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
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
3 changes: 3 additions & 0 deletions .changelog/24453.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_acm_certificate_validation: Restore certificate issuance timestamp as the resource `id` value, fixing error on existing resource Read
```
9 changes: 5 additions & 4 deletions internal/service/acm/certificate_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,25 @@ 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 := FindCertificateValidationByARN(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)
}

d.Set("certificate_arn", certificate.CertificateArn)
Expand Down
2 changes: 1 addition & 1 deletion internal/service/acm/certificate_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func testAccCheckAcmCertificateValidationExists(n string) resource.TestCheckFunc

conn := acctest.Provider.Meta().(*conns.AWSClient).ACMConn

_, err := tfacm.FindCertificateValidationByARN(conn, rs.Primary.ID)
_, err := tfacm.FindCertificateValidationByARN(conn, rs.Primary.Attributes["certificate_arn"])

if err != nil {
return err
Expand Down