Skip to content

Commit 6ce83e8

Browse files
authored
add ccn datasource (#1675)
* add ccn datasource * add changelog * add vendors
1 parent 63887e3 commit 6ce83e8

22 files changed

+4411
-595
lines changed

.changelog/1675.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
```release-note:new-data-source
2+
tencentcloud_ccn_cross_border_compliance
3+
```
4+
5+
```release-note:new-data-source
6+
tencentcloud_ccn_tenant_instances
7+
```
8+
9+
```release-note:new-data-source
10+
tencentcloud_ccn_cross_border_flow_monitor
11+
```
12+
13+
```release-note:new-data-source
14+
tencentcloud_vpn_customer_gateway_vendors
15+
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ require (
8484
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.630
8585
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tsf v1.0.625
8686
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.199
87-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.569
87+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.638
8888
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss v1.0.199
8989
github.com/tencentyun/cos-go-sdk-v5 v0.7.40
9090
github.com/yangwenmai/ratelimit v0.0.0-20180104140304-44221c2292e1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.199 h1:6Yt74l4
645645
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.199/go.mod h1:Yw6OQ33z3s4k0HVYTNSffB12qOzEJ2Zf1Vj4+5S3sRs=
646646
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.569 h1:rrtTVqu44XEXf88RDE0G7dgT+MwR1XA/YfM11a/+F5g=
647647
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.569/go.mod h1:Xt85jPTJISGWwEq1NSpPvoMZ8h/lxhUXdoH7pFQ9PPU=
648+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.638 h1:0/btEL8LdbikGa1nVW/3TnHjArPsDGwSKuLi9GZQzPw=
649+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.638/go.mod h1:5XIJPKHA/448Rb9HTuKUn48YTN/mZFKFTmqQTk1/JQA=
648650
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss v1.0.199 h1:hMBLtiJPnZ9GvA677cTB6ELBR6B68wCR2QY1sNoGQc4=
649651
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss v1.0.199/go.mod h1:nnY91/H3j/Gu7V/oCA6Zeg8T5D3q36EUdBh4EjmHwqY=
650652
github.com/tencentyun/cos-go-sdk-v5 v0.7.40 h1:W6vDGKCHe4wBACI1d2UgE6+50sJFhRWU4O8IB2ozzxM=
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
/*
2+
Use this data source to query detailed information of ccn cross_border_compliance
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_ccn_cross_border_compliance" "cross_border_compliance" {
8+
service_provider = "UNICOM"
9+
compliance_id = 10002
10+
email = "test@tencent.com"
11+
service_start_date = "2020-07-29"
12+
service_end_date = "2021-07-29"
13+
state = "APPROVED"
14+
}
15+
```
16+
*/
17+
package tencentcloud
18+
19+
import (
20+
"context"
21+
22+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
23+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
24+
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
25+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
26+
)
27+
28+
func dataSourceTencentCloudCcnCrossBorderCompliance() *schema.Resource {
29+
return &schema.Resource{
30+
Read: dataSourceTencentCloudCcnCrossBorderComplianceRead,
31+
Schema: map[string]*schema.Schema{
32+
"service_provider": {
33+
Optional: true,
34+
Type: schema.TypeString,
35+
Description: "(Exact match) service provider, optional value: 'UNICOM'.",
36+
},
37+
38+
"compliance_id": {
39+
Optional: true,
40+
Type: schema.TypeInt,
41+
Description: "(Exact match) compliance approval form: 'ID'.",
42+
},
43+
44+
"company": {
45+
Optional: true,
46+
Type: schema.TypeString,
47+
Description: "(Fuzzy query) Company name.",
48+
},
49+
50+
"uniform_social_credit_code": {
51+
Optional: true,
52+
Type: schema.TypeString,
53+
Description: "(Exact match) Uniform Social Credit Code.",
54+
},
55+
56+
"legal_person": {
57+
Optional: true,
58+
Type: schema.TypeString,
59+
Description: "(Fuzzy query) legal representative.",
60+
},
61+
62+
"issuing_authority": {
63+
Optional: true,
64+
Type: schema.TypeString,
65+
Description: "(Fuzzy query) Issuing authority.",
66+
},
67+
68+
"business_address": {
69+
Optional: true,
70+
Type: schema.TypeString,
71+
Description: "(Fuzzy query) business license address.",
72+
},
73+
74+
"post_code": {
75+
Optional: true,
76+
Type: schema.TypeInt,
77+
Description: "(Exact match) post code.",
78+
},
79+
80+
"manager": {
81+
Optional: true,
82+
Type: schema.TypeString,
83+
Description: "(Fuzzy query) Person in charge.",
84+
},
85+
86+
"manager_id": {
87+
Optional: true,
88+
Type: schema.TypeString,
89+
Description: "(Exact query) ID number of the person in charge.",
90+
},
91+
92+
"manager_address": {
93+
Optional: true,
94+
Type: schema.TypeString,
95+
Description: "(Fuzzy query) ID card address of the person in charge.",
96+
},
97+
98+
"manager_telephone": {
99+
Optional: true,
100+
Type: schema.TypeString,
101+
Description: "(Exact match) contact number of the person in charge.",
102+
},
103+
104+
"email": {
105+
Optional: true,
106+
Type: schema.TypeString,
107+
Description: "(Exact match) email.",
108+
},
109+
110+
"service_start_date": {
111+
Optional: true,
112+
Type: schema.TypeString,
113+
Description: "(Exact match) service start date, such as: '2020-07-28'.",
114+
},
115+
116+
"service_end_date": {
117+
Optional: true,
118+
Type: schema.TypeString,
119+
Description: "(Exact match) service end date, such as: '2020-07-28'.",
120+
},
121+
122+
"state": {
123+
Optional: true,
124+
Type: schema.TypeString,
125+
Description: "(Exact match) status. Pending: PENDING, Passed: APPROVED, Denied: DENY.",
126+
},
127+
128+
"result_output_file": {
129+
Type: schema.TypeString,
130+
Optional: true,
131+
Description: "Used to save results.",
132+
},
133+
},
134+
}
135+
}
136+
137+
func dataSourceTencentCloudCcnCrossBorderComplianceRead(d *schema.ResourceData, meta interface{}) error {
138+
defer logElapsed("data_source.tencentcloud_ccn_cross_border_compliance.read")()
139+
defer inconsistentCheck(d, meta)()
140+
141+
logId := getLogId(contextNil)
142+
143+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
144+
145+
paramMap := make(map[string]interface{})
146+
if v, ok := d.GetOk("service_provider"); ok {
147+
paramMap["service_provider"] = helper.String(v.(string))
148+
}
149+
150+
if v, _ := d.GetOk("compliance_id"); v != nil {
151+
paramMap["compliance_id"] = helper.IntUint64(v.(int))
152+
}
153+
154+
if v, ok := d.GetOk("company"); ok {
155+
paramMap["company"] = helper.String(v.(string))
156+
}
157+
158+
if v, ok := d.GetOk("uniform_social_credit_code"); ok {
159+
paramMap["uniform_social_credit_code"] = helper.String(v.(string))
160+
}
161+
162+
if v, ok := d.GetOk("legal_person"); ok {
163+
paramMap["legal_person"] = helper.String(v.(string))
164+
}
165+
166+
if v, ok := d.GetOk("issuing_authority"); ok {
167+
paramMap["issuing_authority"] = helper.String(v.(string))
168+
}
169+
170+
if v, ok := d.GetOk("business_address"); ok {
171+
paramMap["business_address"] = helper.String(v.(string))
172+
}
173+
174+
if v, _ := d.GetOk("post_code"); v != nil {
175+
paramMap["post_code"] = helper.IntUint64(v.(int))
176+
}
177+
178+
if v, ok := d.GetOk("manager"); ok {
179+
paramMap["manager"] = helper.String(v.(string))
180+
}
181+
182+
if v, ok := d.GetOk("manager_id"); ok {
183+
paramMap["manager_id"] = helper.String(v.(string))
184+
}
185+
186+
if v, ok := d.GetOk("manager_address"); ok {
187+
paramMap["manager_address"] = helper.String(v.(string))
188+
}
189+
190+
if v, ok := d.GetOk("manager_telephone"); ok {
191+
paramMap["manager_telephone"] = helper.String(v.(string))
192+
}
193+
194+
if v, ok := d.GetOk("email"); ok {
195+
paramMap["email"] = helper.String(v.(string))
196+
}
197+
198+
if v, ok := d.GetOk("service_start_date"); ok {
199+
paramMap["service_start_date"] = helper.String(v.(string))
200+
}
201+
202+
if v, ok := d.GetOk("service_end_date"); ok {
203+
paramMap["service_end_date"] = helper.String(v.(string))
204+
}
205+
206+
if v, ok := d.GetOk("state"); ok {
207+
paramMap["state"] = helper.String(v.(string))
208+
}
209+
210+
service := VpcService{client: meta.(*TencentCloudClient).apiV3Conn}
211+
212+
var crossBorderComplianceSet []*vpc.CrossBorderCompliance
213+
214+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
215+
result, e := service.DescribeCcnCrossBorderComplianceByFilter(ctx, paramMap)
216+
if e != nil {
217+
return retryError(e)
218+
}
219+
crossBorderComplianceSet = result
220+
return nil
221+
})
222+
if err != nil {
223+
return err
224+
}
225+
226+
ids := make([]string, 0, len(crossBorderComplianceSet))
227+
tmpList := make([]map[string]interface{}, 0, len(crossBorderComplianceSet))
228+
229+
d.SetId(helper.DataResourceIdsHash(ids))
230+
output, ok := d.GetOk("result_output_file")
231+
if ok && output.(string) != "" {
232+
if e := writeToFile(output.(string), tmpList); e != nil {
233+
return e
234+
}
235+
}
236+
return nil
237+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudCcnCrossBorderComplianceDataSource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() {
13+
testAccPreCheck(t)
14+
},
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccCcnCrossBorderComplianceDataSource,
19+
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_ccn_cross_border_compliance.cross_border_compliance")),
20+
},
21+
},
22+
})
23+
}
24+
25+
const testAccCcnCrossBorderComplianceDataSource = `
26+
27+
data "tencentcloud_ccn_cross_border_compliance" "cross_border_compliance" {
28+
service_provider = "UNICOM"
29+
compliance_id = 10002
30+
email = "test@tencent.com"
31+
service_start_date = "2020-07-29"
32+
service_end_date = "2021-07-29"
33+
state = "APPROVED"
34+
}
35+
36+
`

0 commit comments

Comments
 (0)