diff --git a/.changelog/37686.txt b/.changelog/37686.txt new file mode 100644 index 00000000000..8dd8fd06953 --- /dev/null +++ b/.changelog/37686.txt @@ -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 +``` diff --git a/internal/service/route53/zone_data_source.go b/internal/service/route53/zone_data_source.go index e956c8fe09a..5f34347e73f 100644 --- a/internal/service/route53/zone_data_source.go +++ b/internal/service/route53/zone_data_source.go @@ -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, @@ -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, }, }, } diff --git a/internal/service/route53/zone_data_source_test.go b/internal/service/route53/zone_data_source_test.go index 11e383cd836..42b09f045ae 100644 --- a/internal/service/route53/zone_data_source_test.go +++ b/internal/service/route53/zone_data_source_test.go @@ -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() @@ -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" {