Skip to content

Commit

Permalink
Merge pull request #24453 from jufemaiz/fix/24452/acm-certificate-val…
Browse files Browse the repository at this point in the history
…idation

fix: aws_acm_certificate_validation uses create timestamp as id for validation not certificate arn
  • Loading branch information
ewbankkit authored Apr 29, 2022
2 parents 0db889a + 1a99059 commit c38868e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
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

0 comments on commit c38868e

Please sign in to comment.