provider/aws: Finish Tag support for Route 53 zone
This commit is contained in:
parent
3ce5b6cd70
commit
12585b1963
|
@ -63,6 +63,9 @@ func TestCleanChangeID(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAccRoute53Zone(t *testing.T) {
|
||||
var zone route53.HostedZone
|
||||
var td route53.ResourceTagSet
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
|
@ -71,7 +74,9 @@ func TestAccRoute53Zone(t *testing.T) {
|
|||
resource.TestStep{
|
||||
Config: testAccRoute53ZoneConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckRoute53ZoneExists("aws_route53_zone.main"),
|
||||
testAccCheckRoute53ZoneExists("aws_route53_zone.main", &zone),
|
||||
testAccLoadTagsR53(&zone, &td),
|
||||
testAccCheckTagsR53(&td.Tags, "foo", "bar"),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -93,7 +98,7 @@ func testAccCheckRoute53ZoneDestroy(s *terraform.State) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func testAccCheckRoute53ZoneExists(n string) resource.TestCheckFunc {
|
||||
func testAccCheckRoute53ZoneExists(n string, zone *route53.HostedZone) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
rs, ok := s.RootModule().Resources[n]
|
||||
if !ok {
|
||||
|
@ -105,10 +110,37 @@ func testAccCheckRoute53ZoneExists(n string) resource.TestCheckFunc {
|
|||
}
|
||||
|
||||
conn := testAccProvider.Meta().(*AWSClient).r53conn
|
||||
_, err := conn.GetHostedZone(&route53.GetHostedZoneRequest{ID: aws.String(rs.Primary.ID)})
|
||||
resp, err := conn.GetHostedZone(&route53.GetHostedZoneRequest{ID: aws.String(rs.Primary.ID)})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Hosted zone err: %v", err)
|
||||
}
|
||||
*zone = *resp.HostedZone
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func testAccLoadTagsR53(zone *route53.HostedZone, td *route53.ResourceTagSet) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*AWSClient).r53conn
|
||||
|
||||
zone := cleanZoneID(*zone.ID)
|
||||
req := &route53.ListTagsForResourceRequest{
|
||||
ResourceID: aws.String(zone),
|
||||
ResourceType: aws.String("hostedzone"),
|
||||
}
|
||||
|
||||
resp, err := conn.ListTagsForResource(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var tags []route53.Tag
|
||||
if resp.ResourceTagSet != nil {
|
||||
tags = resp.ResourceTagSet.Tags
|
||||
}
|
||||
|
||||
*td = *resp.ResourceTagSet
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -116,5 +148,10 @@ func testAccCheckRoute53ZoneExists(n string) resource.TestCheckFunc {
|
|||
const testAccRoute53ZoneConfig = `
|
||||
resource "aws_route53_zone" "main" {
|
||||
name = "hashicorp.com"
|
||||
|
||||
tags {
|
||||
foo = "bar"
|
||||
Name = "tf-route53-tag-test"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
|
|
@ -22,7 +22,7 @@ func setTagsR53(conn *route53.Route53, d *schema.ResourceData) error {
|
|||
for i, t := range remove {
|
||||
r[i] = *t.Key
|
||||
}
|
||||
log.Printf("[DEBUG] Changing tags: \n\tadding: %#v\n\tremoving:", create, remove)
|
||||
log.Printf("[DEBUG] Changing tags: \n\tadding: %#v\n\tremoving:%#v", create, remove)
|
||||
req := &route53.ChangeTagsForResourceRequest{
|
||||
AddTags: create,
|
||||
RemoveTagKeys: r,
|
||||
|
@ -30,9 +30,7 @@ func setTagsR53(conn *route53.Route53, d *schema.ResourceData) error {
|
|||
ResourceType: aws.String("hostedzone"),
|
||||
}
|
||||
resp, err := conn.ChangeTagsForResource(req)
|
||||
log.Printf("\n\t****\nresp:\n%#v", resp)
|
||||
if err != nil {
|
||||
log.Printf("\n\t****\nerror:\n%#v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
||||
"github.com/hashicorp/aws-sdk-go/gen/route53"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
@ -49,9 +49,9 @@ func TestDiffTagsR53(t *testing.T) {
|
|||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
c, r := diffTags(tagsFromMap(tc.Old), tagsFromMap(tc.New))
|
||||
cm := tagsToMap(c)
|
||||
rm := tagsToMap(r)
|
||||
c, r := diffTagsR53(tagsFromMapR53(tc.Old), tagsFromMapR53(tc.New))
|
||||
cm := tagsToMapR53(c)
|
||||
rm := tagsToMapR53(r)
|
||||
if !reflect.DeepEqual(cm, tc.Create) {
|
||||
t.Fatalf("%d: bad create: %#v", i, cm)
|
||||
}
|
||||
|
@ -63,9 +63,9 @@ func TestDiffTagsR53(t *testing.T) {
|
|||
|
||||
// testAccCheckTags can be used to check the tags on a resource.
|
||||
func testAccCheckTagsR53(
|
||||
ts *[]ec2.Tag, key string, value string) resource.TestCheckFunc {
|
||||
ts *[]route53.Tag, key string, value string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
m := tagsToMap(*ts)
|
||||
m := tagsToMapR53(*ts)
|
||||
v, ok := m[key]
|
||||
if value != "" && !ok {
|
||||
return fmt.Errorf("Missing tag: %s", key)
|
||||
|
|
Loading…
Reference in New Issue