Skip to content

Commit

Permalink
Refactor r/aws_acm_certificate to use keyvaluetags (#10733)
Browse files Browse the repository at this point in the history
Output from acceptance testing:

```
--- PASS: TestAccAWSAcmCertificate_imported_IpAddress (17.29s)
--- PASS: TestAccAWSAcmCertificate_root (20.55s)
--- PASS: TestAccAWSAcmCertificate_disableCTLogging (21.25s)
--- PASS: TestAccAWSAcmCertificate_privateCert (21.73s)
--- PASS: TestAccAWSAcmCertificate_root_TrailingPeriod (21.86s)
--- PASS: TestAccAWSAcmCertificate_wildcard (21.99s)
--- PASS: TestAccAWSAcmCertificate_wildcardAndRootSan (24.33s)
--- PASS: TestAccAWSAcmCertificate_san_TrailingPeriod (25.21s)
--- PASS: TestAccAWSAcmCertificate_emailValidation (26.51s)
--- PASS: TestAccAWSAcmCertificate_san_single (26.64s)
--- PASS: TestAccAWSAcmCertificate_rootAndWildcardSan (26.77s)
--- PASS: TestAccAWSAcmCertificate_dnsValidation (26.99s)
--- PASS: TestAccAWSAcmCertificate_san_multiple (28.61s)
--- PASS: TestAccAWSAcmCertificate_imported_DomainName (28.80s)
--- PASS: TestAccAWSAcmCertificate_tags (40.02s)
```
  • Loading branch information
DrFaust92 authored and bflad committed Nov 4, 2019
1 parent f5b1da3 commit a5e7c55
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 305 deletions.
43 changes: 15 additions & 28 deletions aws/resource_aws_acm_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

func resourceAwsAcmCertificate() *schema.Resource {
Expand Down Expand Up @@ -174,15 +175,9 @@ func resourceAwsAcmCertificateCreateImported(d *schema.ResourceData, meta interf
}

d.SetId(*resp.CertificateArn)
if v, ok := d.GetOk("tags"); ok {
params := &acm.AddTagsToCertificateInput{
CertificateArn: resp.CertificateArn,
Tags: tagsFromMapACM(v.(map[string]interface{})),
}
_, err := acmconn.AddTagsToCertificate(params)

if err != nil {
return fmt.Errorf("Error requesting certificate: %s", err)
if v := d.Get("tags").(map[string]interface{}); len(v) > 0 {
if err := keyvaluetags.AcmUpdateTags(acmconn, d.Id(), nil, v); err != nil {
return fmt.Errorf("error adding tags: %s", err)
}
}

Expand Down Expand Up @@ -221,15 +216,9 @@ func resourceAwsAcmCertificateCreateRequested(d *schema.ResourceData, meta inter
}

d.SetId(*resp.CertificateArn)
if v, ok := d.GetOk("tags"); ok {
params := &acm.AddTagsToCertificateInput{
CertificateArn: resp.CertificateArn,
Tags: tagsFromMapACM(v.(map[string]interface{})),
}
_, err := acmconn.AddTagsToCertificate(params)

if err != nil {
return fmt.Errorf("Error requesting certificate: %s", err)
if v := d.Get("tags").(map[string]interface{}); len(v) > 0 {
if err := keyvaluetags.AcmUpdateTags(acmconn, d.Id(), nil, v); err != nil {
return fmt.Errorf("error adding tags: %s", err)
}
}

Expand Down Expand Up @@ -281,16 +270,14 @@ func resourceAwsAcmCertificateRead(d *schema.ResourceData, meta interface{}) err
return resource.NonRetryableError(fmt.Errorf("error setting certificate options: %s", err))
}

params := &acm.ListTagsForCertificateInput{
CertificateArn: aws.String(d.Id()),
}
tags, err := keyvaluetags.AcmListTags(acmconn, d.Id())

tagResp, err := acmconn.ListTagsForCertificate(params)
if err != nil {
return resource.NonRetryableError(fmt.Errorf("error listing tags for certificate (%s): %s", d.Id(), err))
return resource.NonRetryableError(fmt.Errorf("error listing tags for ACM Certificate (%s): %s", d.Id(), err))
}
if err := d.Set("tags", tagsToMapACM(tagResp.Tags)); err != nil {
return resource.NonRetryableError(err)

if err := d.Set("tags", tags.IgnoreAws().Map()); err != nil {
return resource.NonRetryableError(fmt.Errorf("error setting tags: %s", err))
}

return nil
Expand Down Expand Up @@ -319,9 +306,9 @@ func resourceAwsAcmCertificateUpdate(d *schema.ResourceData, meta interface{}) e
}

if d.HasChange("tags") {
err := setTagsACM(acmconn, d)
if err != nil {
return err
o, n := d.GetChange("tags")
if err := keyvaluetags.AcmUpdateTags(acmconn, d.Id(), o, n); err != nil {
return fmt.Errorf("error updating tags: %s", err)
}
}
return resourceAwsAcmCertificateRead(d, meta)
Expand Down
Loading

0 comments on commit a5e7c55

Please sign in to comment.