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) {
|
func TestAccRoute53Zone(t *testing.T) {
|
||||||
|
var zone route53.HostedZone
|
||||||
|
var td route53.ResourceTagSet
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
|
@ -71,7 +74,9 @@ func TestAccRoute53Zone(t *testing.T) {
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccRoute53ZoneConfig,
|
Config: testAccRoute53ZoneConfig,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckRoute53ZoneExists(n string) resource.TestCheckFunc {
|
func testAccCheckRoute53ZoneExists(n string, zone *route53.HostedZone) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -105,10 +110,37 @@ func testAccCheckRoute53ZoneExists(n string) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
conn := testAccProvider.Meta().(*AWSClient).r53conn
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("Hosted zone err: %v", err)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,5 +148,10 @@ func testAccCheckRoute53ZoneExists(n string) resource.TestCheckFunc {
|
||||||
const testAccRoute53ZoneConfig = `
|
const testAccRoute53ZoneConfig = `
|
||||||
resource "aws_route53_zone" "main" {
|
resource "aws_route53_zone" "main" {
|
||||||
name = "hashicorp.com"
|
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 {
|
for i, t := range remove {
|
||||||
r[i] = *t.Key
|
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{
|
req := &route53.ChangeTagsForResourceRequest{
|
||||||
AddTags: create,
|
AddTags: create,
|
||||||
RemoveTagKeys: r,
|
RemoveTagKeys: r,
|
||||||
|
@ -30,9 +30,7 @@ func setTagsR53(conn *route53.Route53, d *schema.ResourceData) error {
|
||||||
ResourceType: aws.String("hostedzone"),
|
ResourceType: aws.String("hostedzone"),
|
||||||
}
|
}
|
||||||
resp, err := conn.ChangeTagsForResource(req)
|
resp, err := conn.ChangeTagsForResource(req)
|
||||||
log.Printf("\n\t****\nresp:\n%#v", resp)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("\n\t****\nerror:\n%#v", err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"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/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -49,9 +49,9 @@ func TestDiffTagsR53(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range cases {
|
for i, tc := range cases {
|
||||||
c, r := diffTags(tagsFromMap(tc.Old), tagsFromMap(tc.New))
|
c, r := diffTagsR53(tagsFromMapR53(tc.Old), tagsFromMapR53(tc.New))
|
||||||
cm := tagsToMap(c)
|
cm := tagsToMapR53(c)
|
||||||
rm := tagsToMap(r)
|
rm := tagsToMapR53(r)
|
||||||
if !reflect.DeepEqual(cm, tc.Create) {
|
if !reflect.DeepEqual(cm, tc.Create) {
|
||||||
t.Fatalf("%d: bad create: %#v", i, cm)
|
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.
|
// testAccCheckTags can be used to check the tags on a resource.
|
||||||
func testAccCheckTagsR53(
|
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 {
|
return func(s *terraform.State) error {
|
||||||
m := tagsToMap(*ts)
|
m := tagsToMapR53(*ts)
|
||||||
v, ok := m[key]
|
v, ok := m[key]
|
||||||
if value != "" && !ok {
|
if value != "" && !ok {
|
||||||
return fmt.Errorf("Missing tag: %s", key)
|
return fmt.Errorf("Missing tag: %s", key)
|
||||||
|
|
Loading…
Reference in New Issue