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

resource/aws_acm_certificate: Provide additional plan-time validation for subject_alternative_names values #14782

Merged
merged 1 commit into from
Aug 28, 2020
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
7 changes: 5 additions & 2 deletions aws/resource_aws_acm_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ func resourceAwsAcmCertificate() *schema.Resource {
// AWS Provider 3.0.0 aws_route53_zone references no longer contain a
// trailing period, no longer requiring a custom StateFunc
// to prevent ACM API error
Type: schema.TypeString,
ValidateFunc: validation.StringDoesNotMatch(regexp.MustCompile(`\.$`), "cannot end with a period"),
Type: schema.TypeString,
ValidateFunc: validation.All(
validation.StringLenBetween(1, 253),
validation.StringDoesNotMatch(regexp.MustCompile(`\.$`), "cannot end with a period"),
),
},
Set: schema.HashString,
ConflictsWith: []string{"private_key", "certificate_body", "certificate_chain"},
Expand Down
17 changes: 17 additions & 0 deletions aws/resource_aws_acm_certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,23 @@ func TestAccAWSAcmCertificate_rootAndWildcardSan(t *testing.T) {
})
}

func TestAccAWSAcmCertificate_SubjectAlternativeNames_EmptyString(t *testing.T) {
rootDomain := testAccAwsAcmCertificateDomainFromEnv(t)
domain := testAccAwsAcmCertificateRandomSubDomain(rootDomain)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAcmCertificateDestroy,
Steps: []resource.TestStep{
{
Config: testAccAcmCertificateConfig_subjectAlternativeNames(domain, strconv.Quote(""), acm.ValidationMethodDns),
ExpectError: regexp.MustCompile(`expected length`),
},
},
})
}

func TestAccAWSAcmCertificate_san_single(t *testing.T) {
resourceName := "aws_acm_certificate.cert"
rootDomain := testAccAwsAcmCertificateDomainFromEnv(t)
Expand Down