Skip to content

Commit 3349867

Browse files
committed
remove trailing period in computed attribute to address acm_cert validation test errors and add to documentation
1 parent dc19585 commit 3349867

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

aws/resource_aws_acm_certificate.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ func resourceAwsAcmCertificate() *schema.Resource {
165165
// Attempt to calculate the domain validation options based on domains present in domain_name and subject_alternative_names
166166
if diff.Get("validation_method").(string) == "DNS" && (diff.HasChange("domain_name") || diff.HasChange("subject_alternative_names")) {
167167
domainValidationOptionsList := []interface{}{map[string]interface{}{
168+
// AWS Provider 3.0 -- plan-time validation prevents "domain_name"
169+
// argument to accept a string with trailing period; thus, trim of trailing period
170+
// no longer required here
168171
"domain_name": diff.Get("domain_name").(string),
169172
}}
170173

@@ -177,7 +180,10 @@ func resourceAwsAcmCertificate() *schema.Resource {
177180
}
178181

179182
m := map[string]interface{}{
180-
"domain_name": strings.TrimSuffix(san, "."),
183+
// AWS Provider 3.0 -- plan-time validation prevents "subject_alternative_names"
184+
// argument to accept strings with trailing period; thus, trim of trailing period
185+
// no longer required here
186+
"domain_name": san,
181187
}
182188

183189
domainValidationOptionsList = append(domainValidationOptionsList, m)
@@ -244,7 +250,7 @@ func resourceAwsAcmCertificateCreateRequested(d *schema.ResourceData, meta inter
244250
if sans, ok := d.GetOk("subject_alternative_names"); ok {
245251
subjectAlternativeNames := make([]*string, len(sans.(*schema.Set).List()))
246252
for i, sanRaw := range sans.(*schema.Set).List() {
247-
subjectAlternativeNames[i] = aws.String(strings.TrimSuffix(sanRaw.(string), "."))
253+
subjectAlternativeNames[i] = aws.String(sanRaw.(string))
248254
}
249255
params.SubjectAlternativeNames = subjectAlternativeNames
250256
}
@@ -390,8 +396,11 @@ func convertValidationOptions(certificate *acm.CertificateDetail) ([]map[string]
390396
for _, o := range certificate.DomainValidationOptions {
391397
if o.ResourceRecord != nil {
392398
validationOption := map[string]interface{}{
393-
"domain_name": aws.StringValue(o.DomainName),
394-
"resource_record_name": aws.StringValue(o.ResourceRecord.Name),
399+
"domain_name": aws.StringValue(o.DomainName),
400+
// To be consistent with other AWS resources (e.g. Route53 Record) that do not accept a trailing period,
401+
// as well conform to the "domain_name" argument validation, we remove the suffix from
402+
// the DNS Record's Name returned from the API
403+
"resource_record_name": trimTrailingPeriod(aws.StringValue(o.ResourceRecord.Name)),
395404
"resource_record_type": aws.StringValue(o.ResourceRecord.Type),
396405
"resource_record_value": aws.StringValue(o.ResourceRecord.Value),
397406
}

aws/resource_aws_route53_record_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1935,7 +1935,7 @@ resource "aws_route53_zone" "main" {
19351935
}
19361936
19371937
resource "aws_route53_record" "sample" {
1938-
zone_id = "${aws_route53_zone.main.zone_id}"
1938+
zone_id = "${aws_route53_zone.main.zone_id}"
19391939
name = "sample"
19401940
type = "CNAME"
19411941
ttl = "30"

website/docs/guides/version-3-upgrade.html.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,10 @@ Previously the `subject_alternative_names` argument was stored in the Terraform
568568

569569
Previously when the `certificate_body`, `certificate_chain`, and `private_key` arguments were stored in state, they were stored as a hash of the actual value. This prevented Terraform from properly updating the resource when necessary and the hashing has been removed. The Terraform AWS Provider will show an update to these arguments on the first apply after upgrading to version 3.0.0, which is fixing the Terraform state to remove the hash. Since the `private_key` attribute is marked as sensitive, the values in the update will not be visible in the Terraform output. If the non-hashed values have not changed, then no update is occurring other than the Terraform state update. If these arguments are the only updates and they all match the hash removal, the apply will occur without submitting API calls.
570570

571+
### Removal of trailing period in domain_validation_options.resource_record_name attribute
572+
573+
Previously the resource returned the name of the DNS Record directly from the API, which included a `.` suffix. This proves difficult when many other AWS resources do not accept this trailing period (e.g. Route53 Record's `name` argument). This period is now automatically removed. For example, when the attribute would previously return a DNS Record Name such as `_a79865eb4cd1a6ab990a45779b4e0b96.yourdomain.com.`, the attribute now will be returned as `_a79865eb4cd1a6ab990a45779b4e0b96.yourdomain.com`.
574+
571575
## Resource: aws_api_gateway_method_settings
572576

573577
### throttling_burst_limit and throttling_rate_limit Arguments Now Default to -1

0 commit comments

Comments
 (0)