Skip to content
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
36 changes: 35 additions & 1 deletion tencentcloud/resource_tc_ssl_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ func resourceTencentCloudSslCertificate() *schema.Resource {
return
},
},

"tags": {
Type: schema.TypeMap,
Optional: true,
Computed: true,
Description: "Tags of the SSL certificate.",
},
// computed
"product_zh_name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -208,6 +213,15 @@ func resourceTencentCloudSslCertificateCreate(d *schema.ResourceData, m interfac
log.Printf("[CRITAL]%s create certificate failed, reason: %v", logId, outErr)
return outErr
}

if tags := helper.GetTags(d, "tags"); len(tags) > 0 {
tagClient := m.(*TencentCloudClient).apiV3Conn
tagService := &TagService{client: tagClient}
resourceName := BuildTagResourceName("ssl", "certificate", tagClient.Region, id)
if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil {
return err
}
}
d.SetId(id)

return resourceTencentCloudSslCertificateRead(d, m)
Expand Down Expand Up @@ -287,6 +301,14 @@ func resourceTencentCloudSslCertificateRead(d *schema.ResourceData, m interface{
}
_ = d.Set("subject_names", subjectAltNames)

tagClient := m.(*TencentCloudClient).apiV3Conn
tagService := TagService{client: tagClient}

tags, err := tagService.DescribeResourceTags(ctx, "ssl", "certificate", tagClient.Region, d.Id())
if err != nil {
return err
}
_ = d.Set("tags", tags)
return nil
}

Expand Down Expand Up @@ -347,6 +369,18 @@ func resourceTencentCloudSslCertificateUpdate(d *schema.ResourceData, m interfac
}
d.SetPartial("project_id")
}

if d.HasChange("tags") {
oldInterface, newInterface := d.GetChange("tags")
replaceTags, deleteTags := diffTags(oldInterface.(map[string]interface{}), newInterface.(map[string]interface{}))
tagClient := m.(*TencentCloudClient).apiV3Conn
tagService := TagService{client: tagClient}
resourceName := BuildTagResourceName("ssl", "certificate", tagClient.Region, id)
err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags)
if err != nil {
return err
}
}
d.Partial(false)
return resourceTencentCloudSslCertificateRead(d, m)
}
Expand Down
42 changes: 42 additions & 0 deletions tencentcloud/resource_tc_ssl_certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,37 @@ func TestAccTencentCloudSslCertificate_basic(t *testing.T) {
})
}

func TestAccTencentCloudSslCertificate_tags(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckSslCertificateDestroy,
Steps: []resource.TestStep{
{
Config: testAccSslCertificateWithTags(`{
tagKey1="tagValue1"
}`),
Check: resource.ComposeTestCheckFunc(
testAccCheckSslCertificateExists("tencentcloud_ssl_certificate.test-ssl-certificate-tag"),
resource.TestCheckResourceAttr("tencentcloud_ssl_certificate.test-ssl-certificate-tag", "tags.tagKey1", "tagValue1"),
),
},
{
Config: testAccSslCertificateWithTags(`{
tagKey1="tagValue1"
tagKey2="tagValue2"
}`),
Check: resource.ComposeTestCheckFunc(
testAccCheckSslCertificateExists("tencentcloud_ssl_certificate.test-ssl-certificate-tag"),
resource.TestCheckResourceAttr("tencentcloud_ssl_certificate.test-ssl-certificate-tag", "tags.tagKey1", "tagValue1"),
resource.TestCheckResourceAttr("tencentcloud_ssl_certificate.test-ssl-certificate-tag", "tags.tagKey2", "tagValue2"),
),
},
},
})
}

func TestAccTencentCloudSslCertificate_svr(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
Expand Down Expand Up @@ -242,6 +273,17 @@ resource "tencentcloud_ssl_certificate" "foo" {
return fmt.Sprintf(str, certificateType, cert, name, key)
}

func testAccSslCertificateWithTags(tags string) string {
const str = `
resource "tencentcloud_ssl_certificate" "test-ssl-certificate-tag" {
type = "CA"
cert = "%s"
name = "test-ssl-certificate-tag"
tags =%s
}`
return fmt.Sprintf(str, testAccSslCertificateCA, tags)
}

const testAccSslCertificateCA = "-----BEGIN CERTIFICATE-----\\nMIIERzCCAq+gAwIBAgIBAjANBgkqhkiG9w0BAQsF" +
"ADAoMQ0wCwYDVQQDEwR0ZXN0\\nMRcwFQYDVQQKEw50ZXJyYWZvcm0gdGVzdDAeFw0xOTA4MTM" +
"wMzE5MzlaFw0yOTA4\\nMTAwMzE5MzlaMC4xEzARBgNVBAMTCnNlcnZlciBzc2wxFzAVBgNVBA" +
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/ssl_certificate.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The following arguments are supported:
* `key` - (Optional, ForceNew) Key of the SSL certificate and required when certificate type is `SVR`. Not allowed newline at the start and end.
* `name` - (Optional) Name of the SSL certificate.
* `project_id` - (Optional) Project ID of the SSL certificate. Default is `0`.
* `tags` - (Optional) Tags of the SSL certificate.

## Attributes Reference

Expand Down