Skip to content

Commit

Permalink
d/aws_route53_zone: permit both name and zone_id arguments (#37686)
Browse files Browse the repository at this point in the history
As part of the migration of the `route53` service to AWS SDK V2, an `ExactlyOneOf` constraint was added to the `name` and `zone_id` arguments in the `aws_route53_zone` data source. This is technically a regression as the data source functioned correctly in earlier versions when `name` is set and `zone_id` is an empty string. This change reverts the constraint and adds an acceptance test to cover this potential configuration.

```console
% make testacc PKG=route53 TESTS=TestAccRoute53ZoneDataSource_
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.2 test ./internal/service/route53/... -v -count 1 -parallel 20 -run='TestAccRoute53ZoneDataSource_'  -timeout 360m

--- PASS: TestAccRoute53ZoneDataSource_id (91.23s)
--- PASS: TestAccRoute53ZoneDataSource_name_idEmptyString (95.31s)
--- PASS: TestAccRoute53ZoneDataSource_name (101.49s)
--- PASS: TestAccRoute53ZoneDataSource_serviceDiscovery (102.80s)
--- PASS: TestAccRoute53ZoneDataSource_vpc (126.11s)
--- PASS: TestAccRoute53ZoneDataSource_tags (127.60s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/route53    132.691s
```
  • Loading branch information
jar-b committed May 24, 2024
1 parent 42c5107 commit a6e037b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .changelog/37686.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
data-source/aws_route53_zone: Permit both `name` and `zone_id` arguments when one is an empty string
```
14 changes: 6 additions & 8 deletions internal/service/route53/zone_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ func dataSourceZone() *schema.Resource {
Computed: true,
},
names.AttrName: {
Type: schema.TypeString,
Optional: true,
Computed: true,
ExactlyOneOf: []string{"zone_id", names.AttrName},
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"name_servers": {
Type: schema.TypeList,
Expand All @@ -77,10 +76,9 @@ func dataSourceZone() *schema.Resource {
Computed: true,
},
"zone_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ExactlyOneOf: []string{"zone_id", names.AttrName},
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
}
Expand Down
47 changes: 47 additions & 0 deletions internal/service/route53/zone_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,40 @@ func TestAccRoute53ZoneDataSource_name(t *testing.T) {
})
}

// Verifies the data source works when name is set and zone_id is an empty string.
//
// This may be behavior we want to disable in the future with an ExactlyOneOf
// constraint, but because we've historically allowed it we need to continue
// doing so until a major version bump.
//
// Ref: https://github.com/hashicorp/terraform-provider-aws/issues/37683
func TestAccRoute53ZoneDataSource_name_idEmptyString(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_route53_zone.test"
dataSourceName := "data.aws_route53_zone.test"

fqdn := acctest.RandomFQDomainName()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.Route53ServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckZoneDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccZoneDataSourceConfig_name_idEmptyString(fqdn),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(resourceName, names.AttrID, dataSourceName, names.AttrID),
resource.TestCheckResourceAttrPair(resourceName, names.AttrName, dataSourceName, names.AttrName),
resource.TestCheckResourceAttrPair(resourceName, "name_servers.#", dataSourceName, "name_servers.#"),
resource.TestCheckResourceAttrPair(resourceName, "primary_name_server", dataSourceName, "primary_name_server"),
resource.TestCheckResourceAttrPair(resourceName, names.AttrTags, dataSourceName, names.AttrTags),
),
},
},
})
}

func TestAccRoute53ZoneDataSource_tags(t *testing.T) {
ctx := acctest.Context(t)
rInt := sdkacctest.RandInt()
Expand Down Expand Up @@ -170,6 +204,19 @@ data "aws_route53_zone" "test" {
`, fqdn)
}

func testAccZoneDataSourceConfig_name_idEmptyString(fqdn string) string {
return fmt.Sprintf(`
resource "aws_route53_zone" "test" {
name = %[1]q
}
data "aws_route53_zone" "test" {
zone_id = ""
name = aws_route53_zone.test.name
}
`, fqdn)
}

func testAccZoneDataSourceConfig_tagsPrivate(fqdn string, rInt int) string {
return fmt.Sprintf(`
resource "aws_vpc" "test" {
Expand Down

0 comments on commit a6e037b

Please sign in to comment.