Skip to content

Commit e3c5ed4

Browse files
committed
add
1 parent cd947f3 commit e3c5ed4

File tree

17 files changed

+1741
-1699
lines changed

17 files changed

+1741
-1699
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ require (
3939
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn v1.0.1010
4040
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwch v1.1.7
4141
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.627
42-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw v1.0.1018
42+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw v1.3.3
4343
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/chdfs v1.0.600
4444
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ciam v1.0.695
4545
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.1073
4646
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1107
4747
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033
4848
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1148
49-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.50
49+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.3
5050
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1206
5151
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762
5252
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.1161

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.627 h1:nChNdoC
867867
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.627/go.mod h1:lr3IyWgJk4rLWr0vVd8J1Tfs5O+wNcwSZ9ciMhGUrlI=
868868
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw v1.0.1018 h1:t9pWssFNmbTerWeZAASeJyMxj7V+Xfb6VnPPMHDpkDU=
869869
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw v1.0.1018/go.mod h1:/o55E2/cnFVNlRWkpqgn+UHN3sK6AAIYDZOsxPEvdRM=
870+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw v1.3.3 h1:FlCo8dk2pV0K/7CsSqSGgXThMhTcT1w4v5kaI6oKCoY=
871+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw v1.3.3/go.mod h1:ZiYxDOM/SBJzgN2MLpSIeO7VqJxjhQz4hvcwT1/EBBo=
870872
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/chdfs v1.0.600 h1:qSpp4rEgAzfXhi1rPxes+AJp2mwnsyRGPY/Km1FuYGs=
871873
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/chdfs v1.0.600/go.mod h1:xud1dQ7Rc23yC5kS00TYRrvZ/A+94EOkwquaI6xGVac=
872874
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ciam v1.0.695 h1:FGwsF1/PgY+M92bEC+0NH4tJkI8i0qjrLbZWVjLXOAY=
@@ -981,6 +983,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.49 h1:BQwUw
981983
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.49/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
982984
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.50 h1:wZGiUXmzr4L0S1coFhnjddkyNrO5ZTtfxBDrbeR+1d8=
983985
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.50/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
986+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.3 h1:r05ohLc0LVEpiEQeOJ5QwCiKk6XM9kjTca6+UAbNR/8=
987+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.3/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
984988
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993 h1:WlPgXldQCxt7qi5Xrc6j6zTrsXWzN5BcOGs7Irq7fwQ=
985989
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993/go.mod h1:Z9U8zNtyuyKhjS0698wqsrG/kLx1TQ5CEixXBwVe7xY=
986990
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860 h1:F3esKBIT3HW9+7Gt8cVgf8X06VdGIczpgLBUECzSEzU=

tencentcloud/services/cfw/data_source_tc_cfw_nat_fw_switches.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@ func DataSourceTencentCloudCfwNatFwSwitches() *schema.Resource {
2424
"status": {
2525
Optional: true,
2626
Type: schema.TypeInt,
27+
Deprecated: "It has been deprecated from version 1.82.37. Please use `enable` instead.",
2728
Description: "Switch status, 1 open; 0 close.",
2829
},
30+
"enable": {
31+
Optional: true,
32+
Type: schema.TypeInt,
33+
Description: "Switch enable status, 1 open; 0 close.",
34+
},
2935
"data": {
3036
Computed: true,
3137
Type: schema.TypeList,
@@ -134,21 +140,23 @@ func dataSourceTencentCloudCfwNatFwSwitchesRead(d *schema.ResourceData, meta int
134140
defer tccommon.InconsistentCheck(d, meta)()
135141

136142
var (
137-
logId = tccommon.GetLogId(tccommon.ContextNil)
138-
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
139-
service = CfwService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
140-
data []*cfw.NatSwitchListData
141-
natInsId string
143+
logId = tccommon.GetLogId(tccommon.ContextNil)
144+
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
145+
service = CfwService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
146+
data []*cfw.NatSwitchListData
142147
)
143148

144149
paramMap := make(map[string]interface{})
145150
if v, ok := d.GetOk("nat_ins_id"); ok {
146-
paramMap["NatInsId"] = helper.String(v.(string))
147-
natInsId = v.(string)
151+
paramMap["NatInsId"] = v.(string)
148152
}
149153

150-
if v, _ := d.GetOkExists("status"); v != nil {
151-
paramMap["Status"] = helper.IntInt64(v.(int))
154+
if v, ok := d.GetOkExists("status"); ok {
155+
paramMap["Status"] = v.(int)
156+
}
157+
158+
if v, ok := d.GetOkExists("enable"); ok {
159+
paramMap["Enable"] = v.(int)
152160
}
153161

154162
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
@@ -166,11 +174,9 @@ func dataSourceTencentCloudCfwNatFwSwitchesRead(d *schema.ResourceData, meta int
166174
}
167175

168176
tmpList := make([]map[string]interface{}, 0, len(data))
169-
170177
if data != nil {
171178
for _, natSwitchListData := range data {
172179
natSwitchListDataMap := map[string]interface{}{}
173-
174180
if natSwitchListData.Id != nil {
175181
natSwitchListDataMap["id"] = natSwitchListData.Id
176182
}
@@ -245,7 +251,7 @@ func dataSourceTencentCloudCfwNatFwSwitchesRead(d *schema.ResourceData, meta int
245251
_ = d.Set("data", tmpList)
246252
}
247253

248-
d.SetId(natInsId)
254+
d.SetId(helper.BuildToken())
249255
output, ok := d.GetOk("result_output_file")
250256
if ok && output.(string) != "" {
251257
if e := tccommon.WriteToFile(output.(string), tmpList); e != nil {
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
Use this data source to query detailed information of cfw nat_fw_switches
1+
Use this data source to query detailed information of CFW nat fw switches
22

33
Example Usage
44

5-
Query Nat instance'switch by instance id
5+
Query Nat instance'switch by instance ID
66

77
```hcl
88
data "tencentcloud_cfw_nat_fw_switches" "example" {
99
nat_ins_id = "cfwnat-18d2ba18"
1010
}
1111
```
1212

13-
Or filter by switch status
13+
Or filter by switch enable status
1414

1515
```hcl
1616
data "tencentcloud_cfw_nat_fw_switches" "example" {
1717
nat_ins_id = "cfwnat-18d2ba18"
18-
status = 1
18+
enable = 1
1919
}
20-
```
20+
```

tencentcloud/services/cfw/resource_tc_cfw_nat_firewall_switch.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,20 @@ func resourceTencentCloudCfwNatFirewallSwitchCreate(d *schema.ResourceData, meta
5151
defer tccommon.LogElapsed("resource.tencentcloud_cfw_nat_firewall_switch.create")()
5252
defer tccommon.InconsistentCheck(d, meta)()
5353

54-
natInsId := d.Get("nat_ins_id").(string)
55-
subnetId := d.Get("subnet_id").(string)
54+
var (
55+
natInsId string
56+
subnetId string
57+
)
5658

57-
d.SetId(strings.Join([]string{natInsId, subnetId}, tccommon.FILED_SP))
59+
if v, ok := d.GetOk("nat_ins_id"); ok {
60+
natInsId = v.(string)
61+
}
5862

63+
if v, ok := d.GetOk("subnet_id"); ok {
64+
subnetId = v.(string)
65+
}
66+
67+
d.SetId(strings.Join([]string{natInsId, subnetId}, tccommon.FILED_SP))
5968
return resourceTencentCloudCfwNatFirewallSwitchUpdate(d, meta)
6069
}
6170

@@ -76,7 +85,7 @@ func resourceTencentCloudCfwNatFirewallSwitchRead(d *schema.ResourceData, meta i
7685
natInsId := idSplit[0]
7786
subnetId := idSplit[1]
7887

79-
natFirewallSwitch, err := service.DescribeCfwNatFirewallSwitchById(ctx, natInsId, subnetId)
88+
natFirewallSwitch, err := service.DescribeCfwNatFirewallFwSwitchById(ctx, natInsId, subnetId)
8089
if err != nil {
8190
return err
8291
}
@@ -87,6 +96,14 @@ func resourceTencentCloudCfwNatFirewallSwitchRead(d *schema.ResourceData, meta i
8796
return nil
8897
}
8998

99+
if natFirewallSwitch.NatInsId != nil {
100+
_ = d.Set("nat_ins_id", natFirewallSwitch.NatInsId)
101+
}
102+
103+
if natFirewallSwitch.SubnetId != nil {
104+
_ = d.Set("subnet_id", natFirewallSwitch.SubnetId)
105+
}
106+
90107
if natFirewallSwitch.Enable != nil {
91108
_ = d.Set("enable", natFirewallSwitch.Enable)
92109
}
@@ -109,6 +126,7 @@ func resourceTencentCloudCfwNatFirewallSwitchUpdate(d *schema.ResourceData, meta
109126
if len(idSplit) != 2 {
110127
return fmt.Errorf("id is broken,%s", idSplit)
111128
}
129+
112130
natInsId := idSplit[0]
113131
subnetId := idSplit[1]
114132

@@ -117,7 +135,6 @@ func resourceTencentCloudCfwNatFirewallSwitchUpdate(d *schema.ResourceData, meta
117135
}
118136

119137
request.SubnetIdList = common.StringPtrs([]string{subnetId})
120-
121138
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
122139
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseCfwClient().ModifyNatFwSwitch(request)
123140
if e != nil {
@@ -136,7 +153,7 @@ func resourceTencentCloudCfwNatFirewallSwitchUpdate(d *schema.ResourceData, meta
136153

137154
// wait
138155
err = resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
139-
switchDetail, e := service.DescribeCfwNatFirewallSwitchById(ctx, natInsId, subnetId)
156+
switchDetail, e := service.DescribeCfwNatFirewallFwSwitchById(ctx, natInsId, subnetId)
140157
if e != nil {
141158
return tccommon.RetryError(e)
142159
}

tencentcloud/services/cfw/resource_tc_cfw_nat_firewall_switch.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Provides a resource to create a cfw nat_firewall_switch
1+
Provides a resource to create a CFW nat firewall switch
22

33
Example Usage
44

@@ -32,8 +32,8 @@ resource "tencentcloud_cfw_nat_firewall_switch" "example" {
3232

3333
Import
3434

35-
cfw nat_firewall_switch can be imported using the id, e.g.
35+
CFW nat firewall switch can be imported using the natInsId#subnetId, e.g.
3636

3737
```
3838
terraform import tencentcloud_cfw_nat_firewall_switch.example cfwnat-18d2ba18#subnet-ef7wyymr
39-
```
39+
```

tencentcloud/services/cfw/service_tencentcloud_cfw.go

Lines changed: 76 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -598,32 +598,54 @@ func (me *CfwService) DeleteCfwVpcPolicyById(ctx context.Context, uuid string) (
598598
return
599599
}
600600

601-
func (me *CfwService) DescribeCfwNatFirewallSwitchById(ctx context.Context, natInsId, subnetId string) (natFirewallSwitch *cfw.NatSwitchListData, errRet error) {
601+
func (me *CfwService) DescribeCfwNatFirewallFwSwitchById(ctx context.Context, natInsId, subnetId string) (natFirewallSwitch *cfw.NatSwitchListData, errRet error) {
602602
logId := tccommon.GetLogId(ctx)
603603

604-
request := cfw.NewDescribeNatSwitchListRequest()
604+
request := cfw.NewDescribeNatFwSwitchRequest()
605+
response := cfw.NewDescribeNatFwSwitchResponse()
605606
request.Offset = common.Int64Ptr(0)
606607
request.Limit = common.Int64Ptr(20)
607-
request.NatInsId = &natInsId
608-
searchParam := fmt.Sprintf(`{"SubnetId":"%s"}`, subnetId)
609-
request.SearchValue = &searchParam
608+
request.Filters = []*cfw.CommonFilter{
609+
{
610+
Name: common.StringPtr("NatInsId"),
611+
OperatorType: common.Int64Ptr(1),
612+
Values: common.StringPtrs([]string{natInsId}),
613+
},
614+
{
615+
Name: common.StringPtr("SubnetId"),
616+
OperatorType: common.Int64Ptr(1),
617+
Values: common.StringPtrs([]string{subnetId}),
618+
},
619+
}
610620

611621
defer func() {
612622
if errRet != nil {
613623
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
614624
}
615625
}()
616626

617-
ratelimit.Check(request.GetAction())
627+
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
628+
ratelimit.Check(request.GetAction())
629+
result, e := me.client.UseCfwClient().DescribeNatFwSwitch(request)
630+
if e != nil {
631+
return tccommon.RetryError(e)
632+
} else {
633+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
634+
}
635+
636+
if result == nil || result.Response == nil || result.Response.Data == nil {
637+
return resource.NonRetryableError(fmt.Errorf("Describe nat firewall switch failed, Response is nil."))
638+
}
639+
640+
response = result
641+
return nil
642+
})
618643

619-
response, err := me.client.UseCfwClient().DescribeNatSwitchList(request)
620644
if err != nil {
621645
errRet = err
622646
return
623647
}
624648

625-
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
626-
627649
if len(response.Response.Data) < 1 {
628650
return
629651
}
@@ -634,8 +656,10 @@ func (me *CfwService) DescribeCfwNatFirewallSwitchById(ctx context.Context, natI
634656

635657
func (me *CfwService) DescribeCfwNatFwSwitchesByFilter(ctx context.Context, param map[string]interface{}) (natFwSwitches []*cfw.NatSwitchListData, errRet error) {
636658
var (
637-
logId = tccommon.GetLogId(ctx)
638-
request = cfw.NewDescribeNatSwitchListRequest()
659+
logId = tccommon.GetLogId(ctx)
660+
request = cfw.NewDescribeNatFwSwitchRequest()
661+
response = cfw.NewDescribeNatFwSwitchResponse()
662+
filters []*cfw.CommonFilter
639663
)
640664

641665
defer func() {
@@ -645,33 +669,66 @@ func (me *CfwService) DescribeCfwNatFwSwitchesByFilter(ctx context.Context, para
645669
}()
646670

647671
for k, v := range param {
672+
if k == "NatInsId" {
673+
filters = append(filters, &cfw.CommonFilter{
674+
Name: common.StringPtr("NatInsId"),
675+
OperatorType: common.Int64Ptr(1),
676+
Values: common.StringPtrs([]string{v.(string)}),
677+
})
678+
}
679+
648680
if k == "Status" {
649-
request.Status = v.(*int64)
681+
filters = append(filters, &cfw.CommonFilter{
682+
Name: common.StringPtr("Status"),
683+
OperatorType: common.Int64Ptr(1),
684+
Values: common.StringPtrs([]string{helper.IntToStr(v.(int))}),
685+
})
650686
}
651687

652-
if k == "NatInsId" {
653-
request.NatInsId = v.(*string)
688+
if k == "Enable" {
689+
filters = append(filters, &cfw.CommonFilter{
690+
Name: common.StringPtr("Enable"),
691+
OperatorType: common.Int64Ptr(1),
692+
Values: common.StringPtrs([]string{helper.IntToStr(v.(int))}),
693+
})
654694
}
655695
}
656696

657-
ratelimit.Check(request.GetAction())
697+
if len(filters) > 0 {
698+
request.Filters = filters
699+
}
658700

659701
var (
660702
offset int64 = 0
661703
limit int64 = 20
662704
)
705+
663706
for {
664707
request.Offset = &offset
665708
request.Limit = &limit
666-
response, err := me.client.UseCfwClient().DescribeNatSwitchList(request)
709+
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
710+
ratelimit.Check(request.GetAction())
711+
result, e := me.client.UseCfwClient().DescribeNatFwSwitch(request)
712+
if e != nil {
713+
return tccommon.RetryError(e)
714+
} else {
715+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
716+
}
717+
718+
if result == nil || result.Response == nil || result.Response.Data == nil {
719+
return resource.NonRetryableError(fmt.Errorf("Describe nat firewall switch failed, Response is nil."))
720+
}
721+
722+
response = result
723+
return nil
724+
})
725+
667726
if err != nil {
668727
errRet = err
669728
return
670729
}
671730

672-
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
673-
674-
if response == nil || len(response.Response.Data) < 1 {
731+
if len(response.Response.Data) < 1 {
675732
break
676733
}
677734

0 commit comments

Comments
 (0)