From 439597d91e44523bf8d88e8705b7fcde67f7e186 Mon Sep 17 00:00:00 2001 From: "Adam H. Leventhal" Date: Wed, 30 May 2018 09:43:17 -0700 Subject: [PATCH] 4701 aws_service_discovery_private_dns_namespace name length limit --- ..._service_discovery_private_dns_namespace.go | 11 ++++++++++- ...ice_discovery_private_dns_namespace_test.go | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/aws/resource_aws_service_discovery_private_dns_namespace.go b/aws/resource_aws_service_discovery_private_dns_namespace.go index 8fa80bb5f54..a48330534d0 100644 --- a/aws/resource_aws_service_discovery_private_dns_namespace.go +++ b/aws/resource_aws_service_discovery_private_dns_namespace.go @@ -1,6 +1,8 @@ package aws import ( + "crypto/sha1" + "encoding/hex" "fmt" "time" @@ -47,7 +49,14 @@ func resourceAwsServiceDiscoveryPrivateDnsNamespace() *schema.Resource { func resourceAwsServiceDiscoveryPrivateDnsNamespaceCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).sdconn - requestId := resource.PrefixedUniqueId(fmt.Sprintf("tf-%s", d.Get("name").(string))) + // The CreatorRequestId has a limit of 64 bytes; roughly 30 bytes are used for timestamp and prefix. + name := d.Get("name").(string) + if len(name) > 32 { + hash := sha1.Sum([]byte(name)) + name = hex.EncodeToString(hash[:])[0:32] + } + + requestId := resource.PrefixedUniqueId(fmt.Sprintf("tf-%s", name)) input := &servicediscovery.CreatePrivateDnsNamespaceInput{ Name: aws.String(d.Get("name").(string)), Vpc: aws.String(d.Get("vpc").(string)), diff --git a/aws/resource_aws_service_discovery_private_dns_namespace_test.go b/aws/resource_aws_service_discovery_private_dns_namespace_test.go index f7d13f50f74..78fcd8c68c7 100644 --- a/aws/resource_aws_service_discovery_private_dns_namespace_test.go +++ b/aws/resource_aws_service_discovery_private_dns_namespace_test.go @@ -29,6 +29,24 @@ func TestAccAWSServiceDiscoveryPrivateDnsNamespace_basic(t *testing.T) { }) } +func TestAccAWSServiceDiscoveryPrivateDnsNamespace_longname(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAwsServiceDiscoveryPrivateDnsNamespaceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccServiceDiscoveryPrivateDnsNamespaceConfig(acctest.RandString(8) + "." + acctest.RandString(8) + "." + acctest.RandString(8) + "." + acctest.RandString(8)), + Check: resource.ComposeTestCheckFunc( + testAccCheckAwsServiceDiscoveryPrivateDnsNamespaceExists("aws_service_discovery_private_dns_namespace.test"), + resource.TestCheckResourceAttrSet("aws_service_discovery_private_dns_namespace.test", "arn"), + resource.TestCheckResourceAttrSet("aws_service_discovery_private_dns_namespace.test", "hosted_zone"), + ), + }, + }, + }) +} + func testAccCheckAwsServiceDiscoveryPrivateDnsNamespaceDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).sdconn