From 4bfac62f8de9d2888bfb5f28f339aa5e26f27b3c Mon Sep 17 00:00:00 2001 From: Hao Wang Date: Mon, 18 Jan 2021 12:16:29 -0500 Subject: [PATCH 1/7] Add Tags to the resource aws_dms_certificate --- aws/resource_aws_dms_certificate.go | 2 ++ aws/resource_aws_dms_certificate_test.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/aws/resource_aws_dms_certificate.go b/aws/resource_aws_dms_certificate.go index 799f052c512..825769bcca0 100644 --- a/aws/resource_aws_dms_certificate.go +++ b/aws/resource_aws_dms_certificate.go @@ -8,6 +8,7 @@ import ( "github.com/aws/aws-sdk-go/aws/awserr" dms "github.com/aws/aws-sdk-go/service/databasemigrationservice" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" ) func resourceAwsDmsCertificate() *schema.Resource { @@ -52,6 +53,7 @@ func resourceAwsDmsCertificateCreate(d *schema.ResourceData, meta interface{}) e request := &dms.ImportCertificateInput{ CertificateIdentifier: aws.String(d.Get("certificate_id").(string)), + Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().DatabasemigrationserviceTags(), } pem, pemSet := d.GetOk("certificate_pem") diff --git a/aws/resource_aws_dms_certificate_test.go b/aws/resource_aws_dms_certificate_test.go index 9d7d99ccd99..97d24777c4d 100644 --- a/aws/resource_aws_dms_certificate_test.go +++ b/aws/resource_aws_dms_certificate_test.go @@ -99,5 +99,9 @@ resource "aws_dms_certificate" "dms_certificate" { certificate_id = "tf-test-dms-certificate-%[1]s" certificate_pem = "-----BEGIN CERTIFICATE-----\nMIID2jCCAsKgAwIBAgIJAJ58TJVjU7G1MA0GCSqGSIb3DQEBBQUAMFExCzAJBgNV\nBAYTAlVTMREwDwYDVQQIEwhDb2xvcmFkbzEPMA0GA1UEBxMGRGVudmVyMRAwDgYD\nVQQKEwdDaGFydGVyMQwwCgYDVQQLEwNDU0UwHhcNMTcwMTMwMTkyMDA4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6itzewWJ2ALvX3QpmZx7fMHJ3tE+SjjyivE1BbOlzYHx83t\nTeYnm7pS9un7A/UzTDHbs7hPUezLek+H3xTPAnnq\n-----END CERTIFICATE-----\n" } + tags = { + Key = "Name" + Value = "Test" + } `, randId) } From 2692502e9f88537c4c3f5f9ad47cda45e482f77b Mon Sep 17 00:00:00 2001 From: Hao Wang Date: Mon, 18 Jan 2021 20:36:56 -0500 Subject: [PATCH 2/7] Updated test case --- aws/resource_aws_dms_certificate.go | 1 + aws/resource_aws_dms_certificate_test.go | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/aws/resource_aws_dms_certificate.go b/aws/resource_aws_dms_certificate.go index 825769bcca0..f8b21bf7650 100644 --- a/aws/resource_aws_dms_certificate.go +++ b/aws/resource_aws_dms_certificate.go @@ -44,6 +44,7 @@ func resourceAwsDmsCertificate() *schema.Resource { ForceNew: true, Sensitive: true, }, + "tags": tagsSchemaForceNew(), }, } } diff --git a/aws/resource_aws_dms_certificate_test.go b/aws/resource_aws_dms_certificate_test.go index 97d24777c4d..c178be6bf81 100644 --- a/aws/resource_aws_dms_certificate_test.go +++ b/aws/resource_aws_dms_certificate_test.go @@ -29,9 +29,10 @@ func TestAccAWSDmsCertificate_basic(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"tags"}, }, }, }) @@ -98,10 +99,9 @@ func dmsCertificateConfig(randId string) string { resource "aws_dms_certificate" "dms_certificate" { certificate_id = "tf-test-dms-certificate-%[1]s" certificate_pem = "-----BEGIN CERTIFICATE-----\nMIID2jCCAsKgAwIBAgIJAJ58TJVjU7G1MA0GCSqGSIb3DQEBBQUAMFExCzAJBgNV\nBAYTAlVTMREwDwYDVQQIEwhDb2xvcmFkbzEPMA0GA1UEBxMGRGVudmVyMRAwDgYD\nVQQKEwdDaGFydGVyMQwwCgYDVQQLEwNDU0UwH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i\n3X9J3WtCK2+T5brXL6itzewWJ2ALvX3QpmZx7fMHJ3tE+SjjyivE1BbOlzYHx83t\nTeYnm7pS9un7A/UzTDHbs7hPUezLek+H3xTPAnnq\n-----END CERTIFICATE-----\n" -} - tags = { - Key = "Name" - Value = "Test" + tags = { + Name = "Test" } +} `, randId) } From e945b47cb6d6e7003612bf7e2a2c44a4ee02713c Mon Sep 17 00:00:00 2001 From: Hao Wang Date: Mon, 18 Jan 2021 20:59:46 -0500 Subject: [PATCH 3/7] fix indent --- aws/resource_aws_dms_certificate_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_dms_certificate_test.go b/aws/resource_aws_dms_certificate_test.go index c178be6bf81..7fa999eaa92 100644 --- a/aws/resource_aws_dms_certificate_test.go +++ b/aws/resource_aws_dms_certificate_test.go @@ -99,7 +99,7 @@ func dmsCertificateConfig(randId string) string { resource "aws_dms_certificate" "dms_certificate" { certificate_id = "tf-test-dms-certificate-%[1]s" certificate_pem = "-----BEGIN CERTIFICATE-----\nMIID2jCCAsKgAwIBAgIJAJ58TJVjU7G1MA0GCSqGSIb3DQEBBQUAMFExCzAJBgNV\nBAYTAlVTMREwDwYDVQQIEwhDb2xvcmFkbzEPMA0GA1UEBxMGRGVudmVyMRAwDgYD\nVQQKEwdDaGFydGVyMQwwCgYDVQQLEwNDU0UwHhcNMTcwMTMwMTkyMDA4WhcNMjYx\nMjA5MTkyMDA4WjBRMQswCQYDVQQGEwJVUzERMA8GA1UECBMIQ29sb3JhZG8xDzAN\nBgNVBAcTBkRlbnZlcjEQMA4GA1UEChMHQ2hhcnRlcjEMMAoGA1UECxMDQ1NFMIIB\nIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAv6dq6VLIImlAaTrckb5w3X6J\nWP7EGz2ChGAXlkEYto6dPCba0v5+f+8UlMOpeB25XGoai7gdItqNWVFpYsgmndx3\nvTad3ukO1zeElKtw5oHPH2plOaiv/gVJaDa9NTeINj0EtGZs74fCOclAzGFX5vBc\nb08ESWBceRgGjGv3nlij4JzHfqTkCKQz6P6pBivQBfk62rcOkkH5rKoaGltRHROS\nMbkwOhu2hN0KmSYTXRvts0LXnZU4N0l2ms39gmr7UNNNlKYINL2JoTs9dNBc7APD\ndZvlEHd+/FjcLCI8hC3t4g4AbfW0okIBCNG0+oVjqGb2DeONSJKsThahXt89MQID\nAQABo4G0MIGxMB0GA1UdDgQWBBQKq8JxjY1GmeZXJjfOMfW0kBIzPDCBgQYDVR0j\nBHoweIAUCqvCcY2NRpnmVyY3zjH1tJASMzyhVaRTMFExCzAJBgNVBAYTAlVTMREw\nDwYDVQQIEwhDb2xvcmFkbzEPMA0GA1UEBxMGRGVudmVyMRAwDgYDVQQKEwdDaGFy\ndGVyMQwwCgYDVQQLEwNDU0WCCQCefEyVY1OxtTAMBgNVHRMEBTADAQH/MA0GCSqG\nSIb3DQEBBQUAA4IBAQAWifoMk5kbv+yuWXvFwHiB4dWUUmMlUlPU/E300yVTRl58\np6DfOgJs7MMftd1KeWqTO+uW134QlTt7+jwI8Jq0uyKCu/O2kJhVtH/Ryog14tGl\n+wLcuIPLbwJI9CwZX4WMBrq4DnYss+6F47i8NCc+Z3MAiG4vtq9ytBmaod0dj2bI\ng4/Lac0e00dql9RnqENh1+dF0V+QgTJCoPkMqDNAlSB8vOodBW81UAb2z12t+IFi\n3X9J3WtCK2+T5brXL6itzewWJ2ALvX3QpmZx7fMHJ3tE+SjjyivE1BbOlzYHx83t\nTeYnm7pS9un7A/UzTDHbs7hPUezLek+H3xTPAnnq\n-----END CERTIFICATE-----\n" - tags = { + tags = { Name = "Test" } } From 41b9b704a9a744a6e94048ee875334f68efbacf0 Mon Sep 17 00:00:00 2001 From: Hao Wang Date: Sun, 24 Jan 2021 10:35:05 -0500 Subject: [PATCH 4/7] Add a new test case for tags of DMS Certificate --- aws/resource_aws_dms_certificate.go | 36 +++++++++++++++++-- aws/resource_aws_dms_certificate_test.go | 45 +++++++++++++++++++++--- 2 files changed, 74 insertions(+), 7 deletions(-) diff --git a/aws/resource_aws_dms_certificate.go b/aws/resource_aws_dms_certificate.go index f8b21bf7650..62742bf29b3 100644 --- a/aws/resource_aws_dms_certificate.go +++ b/aws/resource_aws_dms_certificate.go @@ -15,6 +15,7 @@ func resourceAwsDmsCertificate() *schema.Resource { return &schema.Resource{ Create: resourceAwsDmsCertificateCreate, Read: resourceAwsDmsCertificateRead, + Update: resourceAwsDmsCertificateUpdate, Delete: resourceAwsDmsCertificateDelete, Importer: &schema.ResourceImporter{ @@ -44,7 +45,7 @@ func resourceAwsDmsCertificate() *schema.Resource { ForceNew: true, Sensitive: true, }, - "tags": tagsSchemaForceNew(), + "tags": tagsSchema(), }, } } @@ -87,6 +88,7 @@ func resourceAwsDmsCertificateCreate(d *schema.ResourceData, meta interface{}) e func resourceAwsDmsCertificateRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).dmsconn + ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig response, err := conn.DescribeCertificates(&dms.DescribeCertificatesInput{ Filters: []*dms.Filter{ @@ -104,7 +106,37 @@ func resourceAwsDmsCertificateRead(d *schema.ResourceData, meta interface{}) err return err } - return resourceAwsDmsCertificateSetState(d, response.Certificates[0]) + err = resourceAwsDmsCertificateSetState(d, response.Certificates[0]) + if err != nil { + return err + } + + tags, err := keyvaluetags.DatabasemigrationserviceListTags(conn, d.Get("certificate_arn").(string)) + + if err != nil { + return fmt.Errorf("error listing tags for DMS Certificate (%s): %s", d.Get("certificate_arn").(string), err) + } + + if err := d.Set("tags", tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { + return fmt.Errorf("error setting tags: %s", err) + } + + return nil +} + +func resourceAwsDmsCertificateUpdate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).dmsconn + + if d.HasChange("tags") { + arn := d.Get("certificate_arn").(string) + o, n := d.GetChange("tags") + + if err := keyvaluetags.DatabasemigrationserviceUpdateTags(conn, arn, o, n); err != nil { + return fmt.Errorf("error updating DMS Certificate (%s) tags: %s", arn, err) + } + } + + return resourceAwsDmsCertificateRead(d, meta) } func resourceAwsDmsCertificateDelete(d *schema.ResourceData, meta interface{}) error { diff --git a/aws/resource_aws_dms_certificate_test.go b/aws/resource_aws_dms_certificate_test.go index 7fa999eaa92..eb18f5150bc 100644 --- a/aws/resource_aws_dms_certificate_test.go +++ b/aws/resource_aws_dms_certificate_test.go @@ -29,10 +29,34 @@ func TestAccAWSDmsCertificate_basic(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"tags"}, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAWSDmsCertificate_tags(t *testing.T) { + resourceName := "aws_dms_certificate.dms_certificate" + randId := acctest.RandString(8) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: dmsCertificateDestroy, + Steps: []resource.TestStep{ + { + Config: dmsCertificateTagsConfigUpdate(randId), + Check: resource.ComposeTestCheckFunc( + checkDmsCertificateExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "certificate_arn"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -96,11 +120,22 @@ func checkDmsCertificateExistsWithProviders(n string, providers *[]*schema.Provi func dmsCertificateConfig(randId string) string { return fmt.Sprintf(` +resource "aws_dms_certificate" "dms_certificate" { + certificate_id = "tf-test-dms-certificate-%[1]s" + certificate_pem = "-----BEGIN CERTIFICATE-----\nMIID2jCCAsKgAwIBAgIJAJ58TJVjU7G1MA0GCSqGSIb3DQEBBQUAMFExCzAJBgNV\nBAYTAlVTMREwDwYDVQQIEwhDb2xvcmFkbzEPMA0GA1UEBxMGRGVudmVyMRAwDgYD\nVQQKEwdDaGFydGVyMQwwCgYDVQQLEwNDU0UwHhcNMTcwMTMwMTkyMD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XL6itzewWJ2ALvX3QpmZx7fMHJ3tE+SjjyivE1BbOlzYHx83t\nTeYnm7pS9un7A/UzTDHbs7hPUezLek+H3xTPAnnq\n-----END CERTIFICATE-----\n" +} +`, randId) +} + +func dmsCertificateTagsConfigUpdate(randId string) string { + return fmt.Sprintf(` resource "aws_dms_certificate" "dms_certificate" { certificate_id = "tf-test-dms-certificate-%[1]s" certificate_pem = "-----BEGIN CERTIFICATE-----\nMIID2jCCAsKgAwIBAgIJAJ58TJVjU7G1MA0GCSqGSIb3DQEBBQUAMFExCzAJBgNV\nBAYTAlVTMREwDwYDVQQIEwhDb2xvcmFkbzEPMA0GA1UEBxMGRGVudmVyMRAwDgYD\nVQQKEwdDaGFydGVyMQwwCgYDVQQLEwNDU0UwHhcNMTcwMTMwMTkyMDA4WhcNMjYx\nMjA5MTkyMDA4WjBRMQswCQYDVQQGEwJVUzERMA8GA1UECBMIQ29sb3JhZG8xDzAN\nBgNVBAcTBkRlbnZlcjEQMA4GA1UEChMHQ2hhcnRlcjEMMAoGA1UECxMDQ1NFMIIB\nIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAv6dq6VLIImlAaTrckb5w3X6J\nWP7EGz2ChGAXlkEYto6dPCba0v5+f+8UlMOpeB25XGoai7gdItqNWVFpYsgmndx3\nvTad3ukO1zeElKtw5oHPH2plOaiv/gVJaDa9NTeINj0EtGZs74fCOclAzGFX5vBc\nb08ESWBceRgGjGv3nlij4JzHfqTkCKQz6P6pBivQBfk62rcOkkH5rKoaGltRHROS\nMbkwOhu2hN0KmSYTXRvts0LXnZU4N0l2ms39gmr7UNNNlKYINL2JoTs9dNBc7APD\ndZvlEHd+/FjcLCI8hC3t4g4AbfW0okIBCNG0+oVjqGb2DeONSJKsThahXt89MQID\nAQABo4G0MIGxMB0GA1UdDgQWBBQKq8JxjY1GmeZXJjfOMfW0kBIzPDCBgQYDVR0j\nBHoweIAUCqvCcY2NRpnmVyY3zjH1tJASMzyhVaRTMFExCzAJBgNVBAYTAlVTMREw\nDwYDVQQIEwhDb2xvcmFkbzEPMA0GA1UEBxMGRGVudmVyMRAwDgYDVQQKEwdDaGFy\ndGVyMQwwCgYDVQQLEwNDU0WCCQCefEyVY1OxtTAMBgNVHRMEBTADAQH/MA0GCSqG\nSIb3DQEBBQUAA4IBAQAWifoMk5kbv+yuWXvFwHiB4dWUUmMlUlPU/E300yVTRl58\np6DfOgJs7MMftd1KeWqTO+uW134QlTt7+jwI8Jq0uyKCu/O2kJhVtH/Ryog14tGl\n+wLcuIPLbwJI9CwZX4WMBrq4DnYss+6F47i8NCc+Z3MAiG4vtq9ytBmaod0dj2bI\ng4/Lac0e00dql9RnqENh1+dF0V+QgTJCoPkMqDNAlSB8vOodBW81UAb2z12t+IFi\n3X9J3WtCK2+T5brXL6itzewWJ2ALvX3QpmZx7fMHJ3tE+SjjyivE1BbOlzYHx83t\nTeYnm7pS9un7A/UzTDHbs7hPUezLek+H3xTPAnnq\n-----END CERTIFICATE-----\n" tags = { - Name = "Test" + Name = "tf-test-dms-certificate-%[1]s" + Update = "to-update" + Remove = "to-remove" } } `, randId) From 7eeb7a7d3a8efafdd94739a123799d9c33318471 Mon Sep 17 00:00:00 2001 From: Hao Wang Date: Sun, 24 Jan 2021 10:37:34 -0500 Subject: [PATCH 5/7] fix format --- aws/resource_aws_dms_certificate_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aws/resource_aws_dms_certificate_test.go b/aws/resource_aws_dms_certificate_test.go index eb18f5150bc..fe959f1f0b5 100644 --- a/aws/resource_aws_dms_certificate_test.go +++ b/aws/resource_aws_dms_certificate_test.go @@ -134,8 +134,8 @@ resource "aws_dms_certificate" "dms_certificate" { certificate_pem = "-----BEGIN CERTIFICATE-----\nMIID2jCCAsKgAwIBAgIJAJ58TJVjU7G1MA0GCSqGSIb3DQEBBQUAMFExCzAJBgNV\nBAYTAlVTMREwDwYDVQQIEwhDb2xvcmFkbzEPMA0GA1UEBxMGRGVud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00dql9RnqENh1+dF0V+QgTJCoPkMqDNAlSB8vOodBW81UAb2z12t+IFi\n3X9J3WtCK2+T5brXL6itzewWJ2ALvX3QpmZx7fMHJ3tE+SjjyivE1BbOlzYHx83t\nTeYnm7pS9un7A/UzTDHbs7hPUezLek+H3xTPAnnq\n-----END CERTIFICATE-----\n" tags = { Name = "tf-test-dms-certificate-%[1]s" - Update = "to-update" - Remove = "to-remove" + Update = "to-update" + Remove = "to-remove" } } `, randId) From d5e2534151ecf224c4189b2c2a79ef64b18596e3 Mon Sep 17 00:00:00 2001 From: Hao Wang Date: Sun, 24 Jan 2021 10:40:18 -0500 Subject: [PATCH 6/7] fix format --- aws/resource_aws_dms_certificate_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_dms_certificate_test.go b/aws/resource_aws_dms_certificate_test.go index fe959f1f0b5..d4a2f1d7b54 100644 --- a/aws/resource_aws_dms_certificate_test.go +++ b/aws/resource_aws_dms_certificate_test.go @@ -133,7 +133,7 @@ resource "aws_dms_certificate" "dms_certificate" { certificate_id = "tf-test-dms-certificate-%[1]s" certificate_pem = "-----BEGIN CERTIFICATE-----\nMIID2jCCAsKgAwIBAgIJAJ58TJVjU7G1MA0GCSqGSIb3DQEBBQUAMFExCzAJBgNV\nBAYTAlVTMREwDwYDVQQIEwhDb2xvcmFkbzEPMA0GA1UEBxMGRGVudmVyMRAwDgYD\nVQQKEwdDaGFydGVyMQwwCgYDVQQLEwNDU0UwHhcNMTcwMTMwMTkyMDA4WhcNMjYx\nMjA5MTkyMDA4WjBRMQswCQYDVQQGEwJVUzERMA8GA1UECBMIQ29sb3JhZG8xDzAN\nBgNVBAcTBkRlbnZlcjEQMA4GA1UEChMHQ2hhcnRlcjEMMAoGA1UECxMDQ1NFMIIB\nIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAv6dq6VLIImlAaTrckb5w3X6J\nWP7EGz2ChGAXlkEYto6dPCba0v5+f+8UlMOpeB25XGoai7gdItqNWVFpYsgmndx3\nvTad3ukO1zeElKtw5oHPH2plOaiv/gVJaDa9NTeINj0EtGZs74fCOclAzGFX5vBc\nb08ESWBceRgGjGv3nlij4JzHfqTkCKQz6P6pBivQBfk62rcOkkH5rKoaGltRHROS\nMbkwOhu2hN0KmSYTXRvts0LXnZU4N0l2ms39gmr7UNNNlKYINL2JoTs9dNBc7APD\ndZvlEHd+/FjcLCI8hC3t4g4AbfW0okIBCNG0+oVjqGb2DeONSJKsThahXt89MQID\nAQABo4G0MIGxMB0GA1UdDgQWBBQKq8JxjY1GmeZXJjfOMfW0kBIzPDCBgQYDVR0j\nBHoweIAUCqvCcY2NRpnmVyY3zjH1tJASMzyhVaRTMFExCzAJBgNVBAYTAlVTMREw\nDwYDVQQIEwhDb2xvcmFkbzEPMA0GA1UEBxMGRGVudmVyMRAwDgYDVQQKEwdDaGFy\ndGVyMQwwCgYDVQQLEwNDU0WCCQCefEyVY1OxtTAMBgNVHRMEBTADAQH/MA0GCSqG\nSIb3DQEBBQUAA4IBAQAWifoMk5kbv+yuWXvFwHiB4dWUUmMlUlPU/E300yVTRl58\np6DfOgJs7MMftd1KeWqTO+uW134QlTt7+jwI8Jq0uyKCu/O2kJhVtH/Ryog14tGl\n+wLcuIPLbwJI9CwZX4WMBrq4DnYss+6F47i8NCc+Z3MAiG4vtq9ytBmaod0dj2bI\ng4/Lac0e00dql9RnqENh1+dF0V+QgTJCoPkMqDNAlSB8vOodBW81UAb2z12t+IFi\n3X9J3WtCK2+T5brXL6itzewWJ2ALvX3QpmZx7fMHJ3tE+SjjyivE1BbOlzYHx83t\nTeYnm7pS9un7A/UzTDHbs7hPUezLek+H3xTPAnnq\n-----END CERTIFICATE-----\n" tags = { - Name = "tf-test-dms-certificate-%[1]s" + Name = "tf-test-dms-certificate-%[1]s" Update = "to-update" Remove = "to-remove" } From 32ff3db79c5fbfbe54126e58c60304e456a53acb Mon Sep 17 00:00:00 2001 From: Angie Pinilla Date: Wed, 24 Feb 2021 00:29:05 -0500 Subject: [PATCH 7/7] CR updates; including test coverage and documentation --- .changelog/17163.txt | 3 ++ aws/resource_aws_dms_certificate.go | 6 +-- aws/resource_aws_dms_certificate_test.go | 47 ++++++++++++++++---- website/docs/r/dms_certificate.html.markdown | 6 +++ 4 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 .changelog/17163.txt diff --git a/.changelog/17163.txt b/.changelog/17163.txt new file mode 100644 index 00000000000..0ec9cae8f43 --- /dev/null +++ b/.changelog/17163.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_dms_certificate: Add `tags` argument +``` diff --git a/aws/resource_aws_dms_certificate.go b/aws/resource_aws_dms_certificate.go index 62742bf29b3..1bae78a6b98 100644 --- a/aws/resource_aws_dms_certificate.go +++ b/aws/resource_aws_dms_certificate.go @@ -114,11 +114,11 @@ func resourceAwsDmsCertificateRead(d *schema.ResourceData, meta interface{}) err tags, err := keyvaluetags.DatabasemigrationserviceListTags(conn, d.Get("certificate_arn").(string)) if err != nil { - return fmt.Errorf("error listing tags for DMS Certificate (%s): %s", d.Get("certificate_arn").(string), err) + return fmt.Errorf("error listing tags for DMS Certificate (%s): %w", d.Get("certificate_arn").(string), err) } if err := d.Set("tags", tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return fmt.Errorf("error setting tags: %s", err) + return fmt.Errorf("error setting tags: %w", err) } return nil @@ -132,7 +132,7 @@ func resourceAwsDmsCertificateUpdate(d *schema.ResourceData, meta interface{}) e o, n := d.GetChange("tags") if err := keyvaluetags.DatabasemigrationserviceUpdateTags(conn, arn, o, n); err != nil { - return fmt.Errorf("error updating DMS Certificate (%s) tags: %s", arn, err) + return fmt.Errorf("error updating DMS Certificate (%s) tags: %w", arn, err) } } diff --git a/aws/resource_aws_dms_certificate_test.go b/aws/resource_aws_dms_certificate_test.go index d4a2f1d7b54..44a268d7eb5 100644 --- a/aws/resource_aws_dms_certificate_test.go +++ b/aws/resource_aws_dms_certificate_test.go @@ -47,10 +47,11 @@ func TestAccAWSDmsCertificate_tags(t *testing.T) { CheckDestroy: dmsCertificateDestroy, Steps: []resource.TestStep{ { - Config: dmsCertificateTagsConfigUpdate(randId), - Check: resource.ComposeTestCheckFunc( + Config: testAccAWSDmsCertificateConfigTags1(randId, "key1", "value1"), + Check: resource.ComposeAggregateTestCheckFunc( checkDmsCertificateExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "certificate_arn"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), ), }, { @@ -58,6 +59,23 @@ func TestAccAWSDmsCertificate_tags(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + Config: testAccAWSDmsCertificateConfigTags2(randId, "key1", "value1updated", "key2", "value2"), + Check: resource.ComposeAggregateTestCheckFunc( + checkDmsCertificateExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1updated"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + { + Config: testAccAWSDmsCertificateConfigTags1(randId, "key2", "value2"), + Check: resource.ComposeAggregateTestCheckFunc( + checkDmsCertificateExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, }, }) } @@ -127,16 +145,29 @@ resource "aws_dms_certificate" "dms_certificate" { `, randId) } -func dmsCertificateTagsConfigUpdate(randId string) string { +func testAccAWSDmsCertificateConfigTags1(randId, tagKey1, tagValue1 string) string { + return fmt.Sprintf(` +resource "aws_dms_certificate" "dms_certificate" { + certificate_id = "tf-test-dms-certificate-%[1]s" + certificate_pem = "-----BEGIN CERTIFICATE-----\nMIID2jCCAsKgAwIBAgIJAJ58TJVjU7G1MA0GCSqGSIb3DQEBBQUAMFExCzAJBgNV\nBAYTAlVTMREwDwYDVQQIEwhDb2xvcmFkbzEPMA0GA1UEB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4/Lac0e00dql9RnqENh1+dF0V+QgTJCoPkMqDNAlSB8vOodBW81UAb2z12t+IFi\n3X9J3WtCK2+T5brXL6itzewWJ2ALvX3QpmZx7fMHJ3tE+SjjyivE1BbOlzYHx83t\nTeYnm7pS9un7A/UzTDHbs7hPUezLek+H3xTPAnnq\n-----END CERTIFICATE-----\n" + + tags = { + %[2]q = %[3]q + } +} +`, randId, tagKey1, tagValue1) +} + +func testAccAWSDmsCertificateConfigTags2(randId, tagKey1, tagValue1, tagKey2, tagValue2 string) string { return fmt.Sprintf(` resource "aws_dms_certificate" "dms_certificate" { certificate_id = "tf-test-dms-certificate-%[1]s" certificate_pem = "-----BEGIN CERTIFICATE-----\nMIID2jCCAsKgAwIBAgIJAJ58TJVjU7G1MA0GCSqGSIb3DQEBBQUAMFExCzAJBgNV\nBAYTAlVTMREwDwYDVQQIEwhDb2xvcmFkbzEPMA0GA1UEBxMGRGVudmVyMRAwDgYD\nVQQKEwdDaGFydGVyMQwwCgYDVQQLEwNDU0UwHhcNMTcwMTMwMTkyMDA4WhcNMjYx\nMjA5MTkyMDA4WjBRMQswCQYDVQQGEwJVUzERMA8GA1UECBMIQ29sb3JhZG8xDzAN\nBgNVBAcTBkRlbnZlcjEQMA4GA1UEChMHQ2hhcnRlcjEMMAoGA1UECxMDQ1NFMIIB\nIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAv6dq6VLIImlAaTrckb5w3X6J\nWP7EGz2ChGAXlkEYto6dPCba0v5+f+8UlMOpeB25XGoai7gdItqNWVFpYsgmndx3\nvTad3ukO1zeElKtw5oHPH2plOaiv/gVJaDa9NTeINj0EtGZs74fCOclAzGFX5vBc\nb08ESWBceRgGjGv3nlij4JzHfqTkCKQz6P6pBivQBfk62rcOkkH5rKoaGltRHROS\nMbkwOhu2hN0KmSYTXRvts0LXnZU4N0l2ms39gmr7UNNNlKYINL2JoTs9dNBc7APD\ndZvlEHd+/FjcLCI8hC3t4g4AbfW0okIBCNG0+oVjqGb2DeONSJKsThahXt89MQID\nAQABo4G0MIGxMB0GA1UdDgQWBBQKq8JxjY1GmeZXJjfOMfW0kBIzPDCBgQYDVR0j\nBHoweIAUCqvCcY2NRpnmVyY3zjH1tJASMzyhVaRTMFExCzAJBgNVBAYTAlVTMREw\nDwYDVQQIEwhDb2xvcmFkbzEPMA0GA1UEBxMGRGVudmVyMRAwDgYDVQQKEwdDaGFy\ndGVyMQwwCgYDVQQLEwNDU0WCCQCefEyVY1OxtTAMBgNVHRMEBTADAQH/MA0GCSqG\nSIb3DQEBBQUAA4IBAQAWifoMk5kbv+yuWXvFwHiB4dWUUmMlUlPU/E300yVTRl58\np6DfOgJs7MMftd1KeWqTO+uW134QlTt7+jwI8Jq0uyKCu/O2kJhVtH/Ryog14tGl\n+wLcuIPLbwJI9CwZX4WMBrq4DnYss+6F47i8NCc+Z3MAiG4vtq9ytBmaod0dj2bI\ng4/Lac0e00dql9RnqENh1+dF0V+QgTJCoPkMqDNAlSB8vOodBW81UAb2z12t+IFi\n3X9J3WtCK2+T5brXL6itzewWJ2ALvX3QpmZx7fMHJ3tE+SjjyivE1BbOlzYHx83t\nTeYnm7pS9un7A/UzTDHbs7hPUezLek+H3xTPAnnq\n-----END CERTIFICATE-----\n" + tags = { - Name = "tf-test-dms-certificate-%[1]s" - Update = "to-update" - Remove = "to-remove" + %[2]q = %[3]q + %[4]q = %[5]q } } -`, randId) +`, randId, tagKey1, tagValue1, tagKey2, tagValue2) } diff --git a/website/docs/r/dms_certificate.html.markdown b/website/docs/r/dms_certificate.html.markdown index 51774c19e3e..8ab27b88edd 100644 --- a/website/docs/r/dms_certificate.html.markdown +++ b/website/docs/r/dms_certificate.html.markdown @@ -20,6 +20,11 @@ Provides a DMS (Data Migration Service) certificate resource. DMS certificates c resource "aws_dms_certificate" "test" { certificate_id = "test-dms-certificate-tf" certificate_pem = "..." + + tags = { + Name = "test" + } + } ``` @@ -33,6 +38,7 @@ The following arguments are supported: * `certificate_pem` - (Optional) The contents of the .pem X.509 certificate file for the certificate. Either `certificate_pem` or `certificate_wallet` must be set. * `certificate_wallet` - (Optional) The contents of the Oracle Wallet certificate for use with SSL. Either `certificate_pem` or `certificate_wallet` must be set. +* `tags` - (Optional) A map of tags to assign to the resource. ## Attributes Reference