Skip to content

Commit deeb20f

Browse files
authored
Feat/tse certificates (#2147)
* feat: support tse certificates * feat: add doc and test * feat: add changelog
1 parent aeca2a5 commit deeb20f

17 files changed

+2991
-784
lines changed

.changelog/2147.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:new-data-source
2+
tencentcloud_tse_gateway_certificates
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_tse_cngw_certificate
7+
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ require (
8989
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.730
9090
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.691
9191
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/trocket v1.0.746
92-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse v1.0.732
92+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse v1.0.755
9393
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tsf v1.0.674
9494
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.199
9595
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.755

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/trocket v1.0.746 h1:ZHf
959959
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/trocket v1.0.746/go.mod h1:NS1bkjH/+dhwCFvluZd+uq8h8hbnOHJaFDbkQe0YTm4=
960960
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse v1.0.732 h1:hC6bRxIBwjAEnqDsJh8tpY/SqcSfP84exN+cVvHwtd4=
961961
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse v1.0.732/go.mod h1:jF0O9bIPZ/oQ+m3qeEfWHLbtsJFKNaiqvdSNGP7AQCI=
962+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse v1.0.755 h1:DbYmGORd2zBnry69k6BR9hzEczrOmbNScE92POutYOY=
963+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse v1.0.755/go.mod h1:o+ABiUSkJQowYQjJsLBHBJsxy4BosjGVuRAsXas+VlY=
962964
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tsf v1.0.674 h1:VsMV1/vsgVzespG7jUzraZS/AbAUllVQjmtVAlA9W/M=
963965
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tsf v1.0.674/go.mod h1:6+MWxaNR4y+spZHYNntulOyj628owTLuWmEFebJOWdA=
964966
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.199 h1:6Yt74l4pA5QtzhwMNIEUt0spXdSBKH744DDqTHJOCP0=

tencentcloud/basic_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,12 +1088,16 @@ const (
10881088
defaultTseVpcId = "vpc-4owdpnwr"
10891089
defaultTseSubnetId = "subnet-dwj7ipnc"
10901090
defaultTseGatewayId = "gateway-ddbb709b"
1091+
defaultTseCertId = "vYSQkJ3K"
10911092
)
10921093

10931094
const DefaultTseVar = `
10941095
variable "gateway_id" {
10951096
default = "` + defaultTseGatewayId + `"
10961097
}
1098+
variable "cert_id" {
1099+
default = "` + defaultTseCertId + `"
1100+
}
10971101
`
10981102

10991103
// End of TSE
Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
/*
2+
Use this data source to query detailed information of tse gateway_certificates
3+
4+
Example Usage
5+
6+
```hcl
7+
8+
data "tencentcloud_tse_gateway_certificates" "gateway_certificates" {
9+
gateway_id = "gateway-ddbb709b"
10+
filters {
11+
key = "BindDomain"
12+
value = "example.com"
13+
}
14+
}
15+
```
16+
*/
17+
package tencentcloud
18+
19+
import (
20+
"context"
21+
22+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
23+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
24+
tse "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse/v20201207"
25+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
26+
)
27+
28+
func dataSourceTencentCloudTseGatewayCertificates() *schema.Resource {
29+
return &schema.Resource{
30+
Read: dataSourceTencentCloudTseGatewayCertificatesRead,
31+
Schema: map[string]*schema.Schema{
32+
"gateway_id": {
33+
Required: true,
34+
Type: schema.TypeString,
35+
Description: "Gateway ID.",
36+
},
37+
38+
"filters": {
39+
Optional: true,
40+
Type: schema.TypeList,
41+
Description: "Filter conditions, valid value: `BindDomain`, `Name`.",
42+
Elem: &schema.Resource{
43+
Schema: map[string]*schema.Schema{
44+
"key": {
45+
Type: schema.TypeString,
46+
Optional: true,
47+
Description: "Filter name.",
48+
},
49+
"value": {
50+
Type: schema.TypeString,
51+
Optional: true,
52+
Description: "Filter value.",
53+
},
54+
},
55+
},
56+
},
57+
58+
"result": {
59+
Computed: true,
60+
Type: schema.TypeList,
61+
Description: "Result.",
62+
Elem: &schema.Resource{
63+
Schema: map[string]*schema.Schema{
64+
"total": {
65+
Type: schema.TypeInt,
66+
Computed: true,
67+
Description: "Total count. Note: This field may return null, indicating that a valid value is not available.",
68+
},
69+
"certificates_list": {
70+
Type: schema.TypeList,
71+
Computed: true,
72+
Description: "Certificate list of gateway. Note: This field may return null, indicating that a valid value is not available.",
73+
Elem: &schema.Resource{
74+
Schema: map[string]*schema.Schema{
75+
"name": {
76+
Type: schema.TypeString,
77+
Computed: true,
78+
Description: "Certificate name. Note: This field may return null, indicating that a valid value is not available.",
79+
},
80+
"id": {
81+
Type: schema.TypeString,
82+
Computed: true,
83+
Description: "Certificate ID. Note: This field may return null, indicating that a valid value is not available.",
84+
},
85+
"bind_domains": {
86+
Type: schema.TypeSet,
87+
Elem: &schema.Schema{
88+
Type: schema.TypeString,
89+
},
90+
Computed: true,
91+
Description: "Domains of the binding. Note: This field may return null, indicating that a valid value is not available.",
92+
},
93+
"status": {
94+
Type: schema.TypeString,
95+
Computed: true,
96+
Description: "Status of certificate. Reference value:- expired- active. Note: This field may return null, indicating that a valid value is not available.",
97+
},
98+
"crt": {
99+
Type: schema.TypeString,
100+
Computed: true,
101+
Description: "Pem format of certificate. Note: This field may return null, indicating that a valid value is not available.",
102+
},
103+
"key": {
104+
Type: schema.TypeString,
105+
Computed: true,
106+
Description: "Private key of certificate. Note: This field may return null, indicating that a valid value is not available.",
107+
},
108+
"expire_time": {
109+
Type: schema.TypeString,
110+
Computed: true,
111+
Description: "Expiration time of certificate. Note: This field may return null, indicating that a valid value is not available.",
112+
},
113+
"create_time": {
114+
Type: schema.TypeString,
115+
Computed: true,
116+
Description: "Upload time of certificate. Note: This field may return null, indicating that a valid value is not available.",
117+
},
118+
"issue_time": {
119+
Type: schema.TypeString,
120+
Computed: true,
121+
Description: "Issuance time of certificateNote: This field may return null, indicating that a valid value is not available.",
122+
},
123+
"cert_source": {
124+
Type: schema.TypeString,
125+
Computed: true,
126+
Description: "Source of certificate. Reference value:- native. Source: konga- ssl. Source: ssl platform. Note: This field may return null, indicating that a valid value is not available.",
127+
},
128+
"cert_id": {
129+
Type: schema.TypeString,
130+
Computed: true,
131+
Description: "Certificate ID of ssl platform. Note: This field may return null, indicating that a valid value is not available.",
132+
},
133+
},
134+
},
135+
},
136+
},
137+
},
138+
},
139+
140+
"result_output_file": {
141+
Type: schema.TypeString,
142+
Optional: true,
143+
Description: "Used to save results.",
144+
},
145+
},
146+
}
147+
}
148+
149+
func dataSourceTencentCloudTseGatewayCertificatesRead(d *schema.ResourceData, meta interface{}) error {
150+
defer logElapsed("data_source.tencentcloud_tse_gateway_certificates.read")()
151+
defer inconsistentCheck(d, meta)()
152+
153+
logId := getLogId(contextNil)
154+
155+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
156+
157+
paramMap := make(map[string]interface{})
158+
if v, ok := d.GetOk("gateway_id"); ok {
159+
paramMap["GatewayId"] = helper.String(v.(string))
160+
}
161+
162+
if v, ok := d.GetOk("filters"); ok {
163+
filtersSet := v.([]interface{})
164+
tmpSet := make([]*tse.ListFilter, 0, len(filtersSet))
165+
166+
for _, item := range filtersSet {
167+
listFilter := tse.ListFilter{}
168+
listFilterMap := item.(map[string]interface{})
169+
170+
if v, ok := listFilterMap["key"]; ok {
171+
listFilter.Key = helper.String(v.(string))
172+
}
173+
if v, ok := listFilterMap["value"]; ok {
174+
listFilter.Value = helper.String(v.(string))
175+
}
176+
tmpSet = append(tmpSet, &listFilter)
177+
}
178+
paramMap["filters"] = tmpSet
179+
}
180+
181+
service := TseService{client: meta.(*TencentCloudClient).apiV3Conn}
182+
183+
var result *tse.KongCertificatesList
184+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
185+
response, e := service.DescribeTseGatewayCertificatesByFilter(ctx, paramMap)
186+
if e != nil {
187+
return retryError(e)
188+
}
189+
result = response
190+
return nil
191+
})
192+
if err != nil {
193+
return err
194+
}
195+
196+
var ids []string
197+
kongCertificatesListMap := map[string]interface{}{}
198+
if result != nil {
199+
ids = make([]string, 0, *result.Total)
200+
if result.Total != nil {
201+
kongCertificatesListMap["total"] = result.Total
202+
}
203+
204+
if result.CertificatesList != nil {
205+
certificatesListList := []interface{}{}
206+
for _, certificatesList := range result.CertificatesList {
207+
certificatesListMap := map[string]interface{}{}
208+
209+
if certificatesList.Name != nil {
210+
certificatesListMap["name"] = certificatesList.Name
211+
}
212+
213+
if certificatesList.Id != nil {
214+
certificatesListMap["id"] = certificatesList.Id
215+
}
216+
217+
if certificatesList.BindDomains != nil {
218+
certificatesListMap["bind_domains"] = certificatesList.BindDomains
219+
}
220+
221+
if certificatesList.Status != nil {
222+
certificatesListMap["status"] = certificatesList.Status
223+
}
224+
225+
if certificatesList.Crt != nil {
226+
certificatesListMap["crt"] = certificatesList.Crt
227+
}
228+
229+
if certificatesList.Key != nil {
230+
certificatesListMap["key"] = certificatesList.Key
231+
}
232+
233+
if certificatesList.ExpireTime != nil {
234+
certificatesListMap["expire_time"] = certificatesList.ExpireTime
235+
}
236+
237+
if certificatesList.CreateTime != nil {
238+
certificatesListMap["create_time"] = certificatesList.CreateTime
239+
}
240+
241+
if certificatesList.IssueTime != nil {
242+
certificatesListMap["issue_time"] = certificatesList.IssueTime
243+
}
244+
245+
if certificatesList.CertSource != nil {
246+
certificatesListMap["cert_source"] = certificatesList.CertSource
247+
}
248+
249+
if certificatesList.CertId != nil {
250+
certificatesListMap["cert_id"] = certificatesList.CertId
251+
}
252+
253+
certificatesListList = append(certificatesListList, certificatesListMap)
254+
ids = append(ids, *certificatesList.Id)
255+
}
256+
257+
kongCertificatesListMap["certificates_list"] = certificatesListList
258+
}
259+
260+
_ = d.Set("result", []interface{}{kongCertificatesListMap})
261+
}
262+
263+
d.SetId(helper.DataResourceIdsHash(ids))
264+
output, ok := d.GetOk("result_output_file")
265+
if ok && output.(string) != "" {
266+
if e := writeToFile(output.(string), kongCertificatesListMap); e != nil {
267+
return e
268+
}
269+
}
270+
return nil
271+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
// go test -test.run TestAccTencentCloudTseGatewayCertificatesDataSource_basic -v
10+
func TestAccTencentCloudTseGatewayCertificatesDataSource_basic(t *testing.T) {
11+
12+
resource.Test(t, resource.TestCase{
13+
PreCheck: func() {
14+
testAccPreCheck(t)
15+
},
16+
Providers: testAccProviders,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccTseGatewayCertificatesDataSource,
20+
Check: resource.ComposeTestCheckFunc(
21+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_tse_gateway_certificates.gateway_certificates"),
22+
resource.TestCheckResourceAttrSet("data.tencentcloud_tse_gateway_certificates.gateway_certificates", "result.#"),
23+
resource.TestCheckResourceAttrSet("data.tencentcloud_tse_gateway_certificates.gateway_certificates", "result.0.certificates_list.#"),
24+
resource.TestCheckResourceAttrSet("data.tencentcloud_tse_gateway_certificates.gateway_certificates", "result.0.certificates_list.0.bind_domains.#"),
25+
resource.TestCheckResourceAttrSet("data.tencentcloud_tse_gateway_certificates.gateway_certificates", "result.0.certificates_list.0.cert_id"),
26+
resource.TestCheckResourceAttrSet("data.tencentcloud_tse_gateway_certificates.gateway_certificates", "result.0.certificates_list.0.id"),
27+
resource.TestCheckResourceAttrSet("data.tencentcloud_tse_gateway_certificates.gateway_certificates", "result.0.certificates_list.0.cert_source"),
28+
resource.TestCheckResourceAttrSet("data.tencentcloud_tse_gateway_certificates.gateway_certificates", "result.0.certificates_list.0.create_time"),
29+
resource.TestCheckResourceAttrSet("data.tencentcloud_tse_gateway_certificates.gateway_certificates", "result.0.certificates_list.0.crt"),
30+
resource.TestCheckResourceAttrSet("data.tencentcloud_tse_gateway_certificates.gateway_certificates", "result.0.certificates_list.0.expire_time"),
31+
resource.TestCheckResourceAttrSet("data.tencentcloud_tse_gateway_certificates.gateway_certificates", "result.0.certificates_list.0.issue_time"),
32+
resource.TestCheckResourceAttrSet("data.tencentcloud_tse_gateway_certificates.gateway_certificates", "result.0.certificates_list.0.key"),
33+
resource.TestCheckResourceAttrSet("data.tencentcloud_tse_gateway_certificates.gateway_certificates", "result.0.certificates_list.0.name"),
34+
resource.TestCheckResourceAttrSet("data.tencentcloud_tse_gateway_certificates.gateway_certificates", "result.0.certificates_list.0.status"),
35+
),
36+
},
37+
},
38+
})
39+
}
40+
41+
const testAccTseGatewayCertificatesDataSource = testAccTseCngwCertificate + `
42+
43+
data "tencentcloud_tse_gateway_certificates" "gateway_certificates" {
44+
gateway_id = var.gateway_id
45+
filters {
46+
key = "BindDomain"
47+
value = "example.com"
48+
}
49+
depends_on = [ tencentcloud_tse_cngw_certificate.cngw_certificate ]
50+
}
51+
52+
`

0 commit comments

Comments
 (0)