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

d/acm_certificate: add tags attribute #11659

Merged
merged 3 commits into from
Apr 23, 2020
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
14 changes: 13 additions & 1 deletion aws/data_source_aws_acm_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/aws/aws-sdk-go/service/acm"
"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 dataSourceAwsAcmCertificate() *schema.Resource {
Expand Down Expand Up @@ -53,6 +54,7 @@ func dataSourceAwsAcmCertificate() *schema.Resource {
Optional: true,
Default: false,
},
"tags": tagsSchemaComputed(),
},
}
}
Expand All @@ -74,7 +76,7 @@ func dataSourceAwsAcmCertificateRead(d *schema.ResourceData, meta interface{}) e
statusStrings := statuses.([]interface{})
params.CertificateStatuses = expandStringList(statusStrings)
} else {
params.CertificateStatuses = []*string{aws.String("ISSUED")}
params.CertificateStatuses = []*string{aws.String(acm.CertificateStatusIssued)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I missed that

}

var arns []*string
Expand Down Expand Up @@ -169,6 +171,16 @@ func dataSourceAwsAcmCertificateRead(d *schema.ResourceData, meta interface{}) e
d.SetId(time.Now().UTC().String())
d.Set("arn", matchedCertificate.CertificateArn)

tags, err := keyvaluetags.AcmListTags(conn, aws.StringValue(matchedCertificate.CertificateArn))

if err != nil {
return fmt.Errorf("error listing tags for ACM Certificate (%s): %s", d.Id(), err)
}

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

return nil
}

Expand Down
13 changes: 10 additions & 3 deletions aws/data_source_aws_acm_certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/aws/aws-sdk-go/service/acm"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

Expand Down Expand Up @@ -182,15 +183,17 @@ func TestAccAWSAcmCertificateDataSource_KeyTypes(t *testing.T) {
dataSourceName := "data.aws_acm_certificate.test"
key := tlsRsaPrivateKeyPem(4096)
certificate := tlsRsaX509SelfSignedCertificatePem(key, "example.com")
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccAwsAcmCertificateDataSourceConfigKeyTypes(tlsPemEscapeNewlines(certificate), tlsPemEscapeNewlines(key)),
Config: testAccAwsAcmCertificateDataSourceConfigKeyTypes(tlsPemEscapeNewlines(certificate), tlsPemEscapeNewlines(key), rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(resourceName, "arn", dataSourceName, "arn"),
resource.TestCheckResourceAttrPair(resourceName, "tags", dataSourceName, "tags"),
),
},
},
Expand Down Expand Up @@ -252,16 +255,20 @@ data "aws_acm_certificate" "test" {
`, domain, certType, mostRecent)
}

func testAccAwsAcmCertificateDataSourceConfigKeyTypes(certificate, key string) string {
func testAccAwsAcmCertificateDataSourceConfigKeyTypes(certificate, key, rName string) string {
return fmt.Sprintf(`
resource "aws_acm_certificate" "test" {
certificate_body = "%[1]s"
private_key = "%[2]s"

tags = {
Name = %[3]q
}
}

data "aws_acm_certificate" "test" {
domain = "${aws_acm_certificate.test.domain_name}"
key_types = ["RSA_4096"]
}
`, certificate, key)
`, certificate, key, rName)
}
2 changes: 2 additions & 0 deletions website/docs/d/acm_certificate.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ data "aws_acm_certificate" "example" {
## Attributes Reference

* `arn` - Set to the ARN of the found certificate, suitable for referencing in other resources that support ACM certificates.
* `tags` - A mapping of tags for the resource.