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

fix: aws_acm_certificate_validation uses create timestamp as id for validation not certificate arn #24453

Merged
merged 7 commits into from
Apr 29, 2022
24 changes: 20 additions & 4 deletions internal/service/acm/certificate_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,43 @@ func resourceCertificateValidationCreate(d *schema.ResourceData, meta interface{
return fmt.Errorf("waiting for ACM Certificate (%s) to be issued: %w", arn, err)
}

d.SetId(arn)
d.SetId(aws.TimeValue(certificate.IssuedAt).String())

return resourceCertificateValidationRead(d, meta)
}

func resourceCertificateValidationRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*conns.AWSClient).ACMConn

certificate, err := FindCertificateValidationByARN(conn, d.Id())
arn := d.Get("certificate_arn").(string)
certificate, err := FindCertificateByARN(conn, arn)

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] ACM Certificate %s not found, removing from state", d.Id())
log.Printf("[WARN] ACM Certificate %s not found, removing from state", arn)
d.SetId("")
return nil
}

if err != nil {
return fmt.Errorf("reading ACM Certificate (%s): %w", d.Id(), err)
return fmt.Errorf("reading ACM Certificate (%s): %w", arn, err)
}

if certificate == nil {
return fmt.Errorf("error describing ACM Certificate (%s): empty response", arn)
}

if status := aws.StringValue(certificate.Status); status != acm.CertificateStatusIssued {
if d.IsNewResource() {
return fmt.Errorf("ACM Certificate (%s) status not issued: %s", arn, status)
}

log.Printf("[WARN] ACM Certificate (%s) status not issued (%s), removing from state", arn, status)
d.SetId("")
return nil
}

d.Set("certificate_arn", certificate.CertificateArn)
d.SetId(aws.TimeValue(certificate.IssuedAt).String())

return nil
}
Expand Down