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_zone: permit both name and zone_id arguments #37686

Merged
merged 1 commit into from
May 24, 2024
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
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
Loading