Skip to content

Commit b186bef

Browse files
authored
feat/cfw (#2149)
* feat/cfw * feat/cfw * feat/cfw * feat/cfw * feat/cfw * feat/cfw * feat/cfw
1 parent 980b431 commit b186bef

File tree

58 files changed

+25511
-20
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+25511
-20
lines changed

.changelog/2149.txt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
```release-note:new-resource
2+
tencentcloud_cfw_address_template
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_cfw_block_ignore
7+
```
8+
9+
```release-note:new-resource
10+
tencentcloud_cfw_edge_policy
11+
```
12+
13+
```release-note:new-resource
14+
tencentcloud_cfw_nat_instance
15+
```
16+
17+
```release-note:new-resource
18+
tencentcloud_cfw_nat_policy
19+
```
20+
21+
```release-note:new-resource
22+
tencentcloud_cfw_vpc_instance
23+
```
24+
25+
```release-note:new-resource
26+
tencentcloud_cfw_vpc_policy
27+
```
28+
29+
```release-note:new-resource
30+
tencentcloud_cfw_sync_asset
31+
```
32+
33+
```release-note:new-resource
34+
tencentcloud_cfw_sync_route
35+
```
36+
37+
```release-note:new-resource
38+
tencentcloud_cfw_nat_firewall_switch
39+
```
40+
41+
```release-note:new-resource
42+
tencentcloud_cfw_vpc_firewall_switch
43+
```
44+
45+
```release-note:new-resource
46+
tencentcloud_cfw_edge_firewall_switch
47+
```
48+
49+
```release-note:new-data-source
50+
tencentcloud_cfw_nat_fw_switches
51+
```
52+
53+
```release-note:new-data-source
54+
tencentcloud_cfw_vpc_fw_switches
55+
```
56+
57+
```release-note:new-data-source
58+
tencentcloud_cfw_edge_fw_switches
59+
```

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,13 @@ require (
9595
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.755
9696
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wedata v1.0.725
9797
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss v1.0.199
98+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw v1.0.759
99+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.759
98100
github.com/tencentyun/cos-go-sdk-v5 v0.7.42-0.20230629101357-7edd77448a0f
99101
github.com/yangwenmai/ratelimit v0.0.0-20180104140304-44221c2292e1
100102
gopkg.in/yaml.v2 v2.4.0
101103
)
102104

103-
require github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.759
104105

105106
require (
106107
4d63.com/gocheckcompilerdirectives v1.2.1 // indirect

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,12 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwch v1.0.745 h1:y3CtD
798798
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwch v1.0.745/go.mod h1:DxjJ8NLE8FGPaQP5k08z1gUqQCSwBuXgPs0u869VoyE=
799799
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.627 h1:nChNdoCUWQZciiJj3gRCWoHBO/8LituLQOdCRREIrS4=
800800
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.627/go.mod h1:lr3IyWgJk4rLWr0vVd8J1Tfs5O+wNcwSZ9ciMhGUrlI=
801+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw v1.0.755 h1:0cZCYLga+EErHHP+MxBdci4Oi+6pDwgfDKdP7pHkREs=
802+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw v1.0.755/go.mod h1:9QMEYZwC8iBeLMBkuj3hNVpplnHPm06VZigzvJmO0QQ=
803+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw v1.0.757 h1:eITie8TdmPNSNiz/bD3aT21F2HZmOrp2kElv82GjR6Q=
804+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw v1.0.757/go.mod h1:gdTEysOdEYGEcYatRQqqkEQH5Ei2rt4yYvAucY0hpkA=
805+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw v1.0.759 h1:xQ7s3VZPLFHRu6m2Vra2qGgsEfC7vu8wkRAf74VMYNI=
806+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw v1.0.759/go.mod h1:V0PvdfiaRTBUvtlwHihxTT8dSCl/ZOOZIymMlhknISA=
801807
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/chdfs v1.0.600 h1:qSpp4rEgAzfXhi1rPxes+AJp2mwnsyRGPY/Km1FuYGs=
802808
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/chdfs v1.0.600/go.mod h1:xud1dQ7Rc23yC5kS00TYRrvZ/A+94EOkwquaI6xGVac=
803809
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ciam v1.0.695 h1:FGwsF1/PgY+M92bEC+0NH4tJkI8i0qjrLbZWVjLXOAY=

tencentcloud/connectivity/client.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"strconv"
99
"time"
1010

11+
cfw "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw/v20190904"
12+
1113
waf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf/v20180125"
1214

1315
dlc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dlc/v20210125"
@@ -182,6 +184,7 @@ type TencentCloudClient struct {
182184
dlcConn *dlc.Client
183185
wedataConn *wedata.Client
184186
wafConn *waf.Client
187+
cfwConn *cfw.Client
185188
trocketConn *trocket.Client
186189
}
187190

@@ -1277,6 +1280,19 @@ func (me *TencentCloudClient) UseWafClient() *waf.Client {
12771280
return me.wafConn
12781281
}
12791282

1283+
func (me *TencentCloudClient) UseCfwClient() *cfw.Client {
1284+
if me.cfwConn != nil {
1285+
return me.cfwConn
1286+
}
1287+
1288+
cpf := me.NewClientProfile(300)
1289+
cpf.Language = "zh-CN"
1290+
me.cfwConn, _ = cfw.NewClient(me.Credential, me.Region, cpf)
1291+
me.cfwConn.WithHttpTransport(&LogRoundTripper{})
1292+
1293+
return me.cfwConn
1294+
}
1295+
12801296
// UseTrocketClient returns trocket client for service
12811297
func (me *TencentCloudClient) UseTrocketClient() *trocket.Client {
12821298
if me.trocketConn != nil {
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
/*
2+
Use this data source to query detailed information of cfw edge_fw_switches
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_cfw_edge_fw_switches" "example" {}
8+
```
9+
*/
10+
package tencentcloud
11+
12+
import (
13+
"context"
14+
"strconv"
15+
"time"
16+
17+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
18+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
19+
cfw "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw/v20190904"
20+
)
21+
22+
func dataSourceTencentCloudCfwEdgeFwSwitches() *schema.Resource {
23+
return &schema.Resource{
24+
Read: dataSourceTencentCloudCfwEdgeFwSwitchesRead,
25+
Schema: map[string]*schema.Schema{
26+
"data": {
27+
Computed: true,
28+
Type: schema.TypeList,
29+
Description: "Ip switch list.",
30+
Elem: &schema.Resource{
31+
Schema: map[string]*schema.Schema{
32+
"public_ip": {
33+
Type: schema.TypeString,
34+
Computed: true,
35+
Description: "public ip.",
36+
},
37+
"public_ip_type": {
38+
Type: schema.TypeInt,
39+
Computed: true,
40+
Description: "Public IP type.",
41+
},
42+
"instance_id": {
43+
Type: schema.TypeString,
44+
Computed: true,
45+
Description: "Instance Id.",
46+
},
47+
"instance_name": {
48+
Type: schema.TypeString,
49+
Computed: true,
50+
Description: "Instance Name.",
51+
},
52+
"intranet_ip": {
53+
Type: schema.TypeString,
54+
Computed: true,
55+
Description: "Intranet Ip.",
56+
},
57+
"asset_type": {
58+
Type: schema.TypeString,
59+
Computed: true,
60+
Description: "Asset Type.",
61+
},
62+
"region": {
63+
Type: schema.TypeString,
64+
Computed: true,
65+
Description: "region.",
66+
},
67+
"status": {
68+
Type: schema.TypeInt,
69+
Computed: true,
70+
Description: "status.",
71+
},
72+
"switch_mode": {
73+
Type: schema.TypeInt,
74+
Computed: true,
75+
Description: "switch mode.",
76+
},
77+
"vpc_id": {
78+
Type: schema.TypeString,
79+
Computed: true,
80+
Description: "vpc id.",
81+
},
82+
},
83+
},
84+
},
85+
"result_output_file": {
86+
Type: schema.TypeString,
87+
Optional: true,
88+
Description: "Used to save results.",
89+
},
90+
},
91+
}
92+
}
93+
94+
func dataSourceTencentCloudCfwEdgeFwSwitchesRead(d *schema.ResourceData, meta interface{}) error {
95+
defer logElapsed("data_source.tencentcloud_cfw_edge_fw_switches.read")()
96+
defer inconsistentCheck(d, meta)()
97+
98+
var (
99+
logId = getLogId(contextNil)
100+
ctx = context.WithValue(context.TODO(), logIdKey, logId)
101+
service = CfwService{client: meta.(*TencentCloudClient).apiV3Conn}
102+
data []*cfw.EdgeIpInfo
103+
)
104+
105+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
106+
result, e := service.DescribeCfwEdgeFwSwitchesByFilter(ctx)
107+
if e != nil {
108+
return retryError(e)
109+
}
110+
111+
data = result
112+
return nil
113+
})
114+
115+
if err != nil {
116+
return err
117+
}
118+
119+
tmpList := make([]map[string]interface{}, 0, len(data))
120+
121+
if data != nil {
122+
for _, edgeFwSwitchData := range data {
123+
edgeFwSwitchDataMap := map[string]interface{}{}
124+
125+
if edgeFwSwitchData.PublicIp != nil {
126+
edgeFwSwitchDataMap["public_ip"] = edgeFwSwitchData.PublicIp
127+
}
128+
129+
if edgeFwSwitchData.PublicIpType != nil {
130+
edgeFwSwitchDataMap["public_ip_type"] = edgeFwSwitchData.PublicIpType
131+
}
132+
133+
if edgeFwSwitchData.InstanceId != nil {
134+
edgeFwSwitchDataMap["instance_id"] = edgeFwSwitchData.InstanceId
135+
}
136+
137+
if edgeFwSwitchData.InstanceName != nil {
138+
edgeFwSwitchDataMap["instance_name"] = edgeFwSwitchData.InstanceName
139+
}
140+
141+
if edgeFwSwitchData.IntranetIp != nil {
142+
edgeFwSwitchDataMap["intranet_ip"] = edgeFwSwitchData.IntranetIp
143+
}
144+
145+
if edgeFwSwitchData.AssetType != nil {
146+
edgeFwSwitchDataMap["asset_type"] = edgeFwSwitchData.AssetType
147+
}
148+
149+
if edgeFwSwitchData.Region != nil {
150+
edgeFwSwitchDataMap["region"] = edgeFwSwitchData.Region
151+
}
152+
153+
if edgeFwSwitchData.Status != nil {
154+
edgeFwSwitchDataMap["status"] = edgeFwSwitchData.Status
155+
}
156+
157+
if edgeFwSwitchData.SwitchMode != nil {
158+
edgeFwSwitchDataMap["switch_mode"] = edgeFwSwitchData.SwitchMode
159+
}
160+
161+
if edgeFwSwitchData.VpcId != nil {
162+
edgeFwSwitchDataMap["vpc_id"] = edgeFwSwitchData.VpcId
163+
}
164+
165+
tmpList = append(tmpList, edgeFwSwitchDataMap)
166+
}
167+
168+
_ = d.Set("data", tmpList)
169+
}
170+
171+
d.SetId(strconv.FormatInt(time.Now().Unix(), 10))
172+
output, ok := d.GetOk("result_output_file")
173+
if ok && output.(string) != "" {
174+
if e := writeToFile(output.(string), tmpList); e != nil {
175+
return e
176+
}
177+
}
178+
179+
return nil
180+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
// go test -i; go test -test.run TestAccTencentCloudNeedFixCfwEdgeFwSwitchesDataSource_basic -v
10+
func TestAccTencentCloudNeedFixCfwEdgeFwSwitchesDataSource_basic(t *testing.T) {
11+
t.Parallel()
12+
resource.Test(t, resource.TestCase{
13+
PreCheck: func() {
14+
testAccPreCheck(t)
15+
},
16+
Providers: testAccProviders,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccCfwEdgeFwSwitchesDataSource,
20+
Check: resource.ComposeTestCheckFunc(
21+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_cfw_edge_fw_switches.example"),
22+
),
23+
},
24+
},
25+
})
26+
}
27+
28+
const testAccCfwEdgeFwSwitchesDataSource = `
29+
data "tencentcloud_cfw_edge_fw_switches" "example" {}
30+
`

0 commit comments

Comments
 (0)