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

aws_service_discovery_public_dns_namespace name length limit #5610

Merged
merged 3 commits into from
Aug 21, 2018
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
13 changes: 10 additions & 3 deletions aws/resource_aws_service_discovery_public_dns_namespace.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package aws

import (
"fmt"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -46,9 +45,17 @@ func resourceAwsServiceDiscoveryPublicDnsNamespace() *schema.Resource {
func resourceAwsServiceDiscoveryPublicDnsNamespaceCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).sdconn

requestId := resource.PrefixedUniqueId(fmt.Sprintf("tf-%s", d.Get("name").(string)))
name := d.Get("name").(string)
// The CreatorRequestId has a limit of 64 bytes
var requestId string
if len(name) > (64 - resource.UniqueIDSuffixLength) {
requestId = resource.PrefixedUniqueId(name[0:(64 - resource.UniqueIDSuffixLength - 1)])
} else {
requestId = resource.PrefixedUniqueId(name)
}

input := &servicediscovery.CreatePublicDnsNamespaceInput{
Name: aws.String(d.Get("name").(string)),
Name: aws.String(name),
CreatorRequestId: aws.String(requestId),
}

Expand Down
20 changes: 20 additions & 0 deletions aws/resource_aws_service_discovery_public_dns_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ func testAccCheckAwsServiceDiscoveryPublicDnsNamespaceExists(name string) resour
}
}

func testAccAWSServiceDiscoveryPublicDnsNamespace_longname(t *testing.T) {
rName := acctest.RandString(64 - len("terraform.com"))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsServiceDiscoveryPublicDnsNamespaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccServiceDiscoveryPublicDnsNamespaceConfig(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsServiceDiscoveryPublicDnsNamespaceExists("aws_service_discovery_public_dns_namespace.test"),
resource.TestCheckResourceAttrSet("aws_service_discovery_public_dns_namespace.test", "arn"),
resource.TestCheckResourceAttrSet("aws_service_discovery_public_dns_namespace.test", "hosted_zone"),
),
},
},
})
}

func testAccServiceDiscoveryPublicDnsNamespaceConfig(rName string) string {
return fmt.Sprintf(`
resource "aws_service_discovery_public_dns_namespace" "test" {
Expand Down