Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d/aws_route53_resolver_rule: Don't retrieve tags for rules 'SHARED_WITH_ME' #10348

Merged
merged 1 commit into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions aws/data_source_aws_route53_resolver_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,13 @@ func dataSourceAwsRoute53ResolverRuleRead(d *schema.ResourceData, meta interface
d.Set("resolver_endpoint_id", rule.ResolverEndpointId)
d.Set("resolver_rule_id", rule.Id)
d.Set("rule_type", rule.RuleType)
d.Set("share_status", rule.ShareStatus)
if err := getTagsRoute53Resolver(conn, d); err != nil {
return fmt.Errorf("error reading Route 53 Resolver rule (%s) tags: %s", d.Id(), err)
shareStatus := aws.StringValue(rule.ShareStatus)
d.Set("share_status", shareStatus)
// https://github.com/terraform-providers/terraform-provider-aws/issues/10211
if shareStatus != route53resolver.ShareStatusSharedWithMe {
if err := getTagsRoute53Resolver(conn, d); err != nil {
return fmt.Errorf("error reading Route 53 Resolver rule (%s) tags: %s", d.Id(), err)
}
}

return nil
Expand Down
163 changes: 163 additions & 0 deletions aws/data_source_aws_route53_resolver_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func TestAccDataSourceAwsRoute53ResolverRule_basic(t *testing.T) {
Expand Down Expand Up @@ -91,6 +92,78 @@ func TestAccDataSourceAwsRoute53ResolverRule_ResolverEndpointIdWithTags(t *testi
})
}

func TestAccDataSourceAwsRoute53ResolverRule_SharedByMe(t *testing.T) {
var providers []*schema.Provider
rName := fmt.Sprintf("tf-testacc-r53-resolver-%s", acctest.RandStringFromCharSet(8, acctest.CharSetAlphaNum))
resourceName := "aws_route53_resolver_rule.example"
ds1ResourceName := "data.aws_route53_resolver_rule.by_resolver_endpoint_id"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccAlternateAccountPreCheck(t)
testAccPreCheckAWSRoute53Resolver(t)
},
ProviderFactories: testAccProviderFactories(&providers),
Steps: []resource.TestStep{
{
Config: testAccDataSourceAwsRoute53ResolverRule_sharedByMe(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(ds1ResourceName, "id", resourceName, "id"),
resource.TestCheckResourceAttrPair(ds1ResourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(ds1ResourceName, "domain_name", resourceName, "domain_name"),
resource.TestCheckResourceAttrPair(ds1ResourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(ds1ResourceName, "owner_id", resourceName, "owner_id"),
resource.TestCheckResourceAttrPair(ds1ResourceName, "resolver_endpoint_id", resourceName, "resolver_endpoint_id"),
resource.TestCheckResourceAttrPair(ds1ResourceName, "resolver_rule_id", resourceName, "id"),
resource.TestCheckResourceAttrPair(ds1ResourceName, "rule_type", resourceName, "rule_type"),
resource.TestCheckResourceAttr(ds1ResourceName, "share_status", "SHARED_BY_ME"),
resource.TestCheckResourceAttrPair(ds1ResourceName, "tags.%", resourceName, "tags.%"),
resource.TestCheckResourceAttr(ds1ResourceName, "tags.%", "2"),
resource.TestCheckResourceAttrPair(ds1ResourceName, "tags.Key1", resourceName, "tags.Key1"),
resource.TestCheckResourceAttrPair(ds1ResourceName, "tags.Key2", resourceName, "tags.Key2"),
),
ExpectNonEmptyPlan: true,
},
},
})
}

func TestAccDataSourceAwsRoute53ResolverRule_SharedWithMe(t *testing.T) {
var providers []*schema.Provider
rName := fmt.Sprintf("tf-testacc-r53-resolver-%s", acctest.RandStringFromCharSet(8, acctest.CharSetAlphaNum))
resourceName := "aws_route53_resolver_rule.example"
ds1ResourceName := "data.aws_route53_resolver_rule.by_resolver_endpoint_id"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccAlternateAccountPreCheck(t)
testAccPreCheckAWSRoute53Resolver(t)
},
ProviderFactories: testAccProviderFactories(&providers),
Steps: []resource.TestStep{
{
Config: testAccDataSourceAwsRoute53ResolverRule_sharedWithMe(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(ds1ResourceName, "id", resourceName, "id"),
resource.TestCheckResourceAttrPair(ds1ResourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(ds1ResourceName, "domain_name", resourceName, "domain_name"),
resource.TestCheckResourceAttrPair(ds1ResourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(ds1ResourceName, "owner_id", resourceName, "owner_id"),
resource.TestCheckResourceAttrPair(ds1ResourceName, "resolver_endpoint_id", resourceName, "resolver_endpoint_id"),
resource.TestCheckResourceAttrPair(ds1ResourceName, "resolver_rule_id", resourceName, "id"),
resource.TestCheckResourceAttrPair(ds1ResourceName, "rule_type", resourceName, "rule_type"),
resource.TestCheckResourceAttr(ds1ResourceName, "share_status", "SHARED_WITH_ME"),
// Tags cannot be retrieved for rules shared with us.
resource.TestCheckResourceAttr(ds1ResourceName, "tags.%", "0"),
),
ExpectNonEmptyPlan: true,
},
},
})
}

func testAccDataSourceAwsRoute53ResolverRule_basic(rName string) string {
return fmt.Sprintf(`
resource "aws_route53_resolver_rule" "example" {
Expand Down Expand Up @@ -138,3 +211,93 @@ data "aws_route53_resolver_rule" "by_resolver_endpoint_id" {
}
`, rName)
}

func testAccDataSourceAwsRoute53ResolverRule_sharedByMe(rName string) string {
return testAccAlternateAccountProviderConfig() + testAccRoute53ResolverRuleConfig_resolverEndpoint(rName) + fmt.Sprintf(`
resource "aws_route53_resolver_rule" "example" {
domain_name = "%[1]s.example.com"
rule_type = "FORWARD"
name = %[1]q

resolver_endpoint_id = "${aws_route53_resolver_endpoint.bar.id}"

target_ip {
ip = "192.0.2.7"
}

tags = {
"Key1" = "Value1"
"Key2" = "Value2"
}
}

resource "aws_ram_resource_share" "test" {
name = %[1]q
allow_external_principals = true
}

resource "aws_ram_resource_association" "test" {
resource_arn = "${aws_route53_resolver_rule.example.arn}"
resource_share_arn = "${aws_ram_resource_share.test.arn}"
}

data "aws_organizations_organization" "test" {}

resource "aws_ram_principal_association" "test" {
principal = "${data.aws_organizations_organization.test.arn}"
resource_share_arn = "${aws_ram_resource_share.test.arn}"
}

data "aws_route53_resolver_rule" "by_resolver_endpoint_id" {
resolver_endpoint_id = "${aws_route53_resolver_rule.example.resolver_endpoint_id}"

depends_on = ["aws_ram_resource_association.test", "aws_ram_principal_association.test"]
}
`, rName)
}

func testAccDataSourceAwsRoute53ResolverRule_sharedWithMe(rName string) string {
return testAccAlternateAccountProviderConfig() + testAccRoute53ResolverRuleConfig_resolverEndpoint(rName) + fmt.Sprintf(`
resource "aws_route53_resolver_rule" "example" {
domain_name = "%[1]s.example.com"
rule_type = "FORWARD"
name = %[1]q

resolver_endpoint_id = "${aws_route53_resolver_endpoint.bar.id}"

target_ip {
ip = "192.0.2.7"
}

tags = {
"Key1" = "Value1"
"Key2" = "Value2"
}
}

resource "aws_ram_resource_share" "test" {
name = %[1]q
allow_external_principals = true
}

resource "aws_ram_resource_association" "test" {
resource_arn = "${aws_route53_resolver_rule.example.arn}"
resource_share_arn = "${aws_ram_resource_share.test.arn}"
}

data "aws_organizations_organization" "test" {}

resource "aws_ram_principal_association" "test" {
principal = "${data.aws_organizations_organization.test.arn}"
resource_share_arn = "${aws_ram_resource_share.test.arn}"
}

data "aws_route53_resolver_rule" "by_resolver_endpoint_id" {
provider = "aws.alternate"

resolver_endpoint_id = "${aws_route53_resolver_rule.example.resolver_endpoint_id}"

depends_on = ["aws_ram_resource_association.test", "aws_ram_principal_association.test"]
}
`, rName)
}