Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/cfw #2149

Merged
merged 10 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
59 changes: 59 additions & 0 deletions .changelog/2149.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
```release-note:new-resource
tencentcloud_cfw_address_template
```

```release-note:new-resource
tencentcloud_cfw_block_ignore
```

```release-note:new-resource
tencentcloud_cfw_edge_policy
```

```release-note:new-resource
tencentcloud_cfw_nat_instance
```

```release-note:new-resource
tencentcloud_cfw_nat_policy
```

```release-note:new-resource
tencentcloud_cfw_vpc_instance
```

```release-note:new-resource
tencentcloud_cfw_vpc_policy
```

```release-note:new-resource
tencentcloud_cfw_sync_asset
```

```release-note:new-resource
tencentcloud_cfw_sync_route
```

```release-note:new-resource
tencentcloud_cfw_nat_firewall_switch
```

```release-note:new-resource
tencentcloud_cfw_vpc_firewall_switch
```

```release-note:new-resource
tencentcloud_cfw_edge_firewall_switch
```

```release-note:new-data-source
tencentcloud_cfw_nat_fw_switches
```

```release-note:new-data-source
tencentcloud_cfw_vpc_fw_switches
```

```release-note:new-data-source
tencentcloud_cfw_edge_fw_switches
```
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,14 @@ require (
gopkg.in/yaml.v2 v2.4.0
)

<<<<<<< HEAD
require (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为啥要单独一个 require 呢

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是go mod自动生成的 非人为

github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw v1.0.759
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.754
)
=======
require github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf v1.0.759
>>>>>>> 980b4317f5abdb75718178af297400be12062e6e
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里有冲突了


require (
4d63.com/gocheckcompilerdirectives v1.2.1 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,12 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwch v1.0.745 h1:y3CtD
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwch v1.0.745/go.mod h1:DxjJ8NLE8FGPaQP5k08z1gUqQCSwBuXgPs0u869VoyE=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.627 h1:nChNdoCUWQZciiJj3gRCWoHBO/8LituLQOdCRREIrS4=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.627/go.mod h1:lr3IyWgJk4rLWr0vVd8J1Tfs5O+wNcwSZ9ciMhGUrlI=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw v1.0.755 h1:0cZCYLga+EErHHP+MxBdci4Oi+6pDwgfDKdP7pHkREs=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw v1.0.755/go.mod h1:9QMEYZwC8iBeLMBkuj3hNVpplnHPm06VZigzvJmO0QQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw v1.0.757 h1:eITie8TdmPNSNiz/bD3aT21F2HZmOrp2kElv82GjR6Q=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw v1.0.757/go.mod h1:gdTEysOdEYGEcYatRQqqkEQH5Ei2rt4yYvAucY0hpkA=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw v1.0.759 h1:xQ7s3VZPLFHRu6m2Vra2qGgsEfC7vu8wkRAf74VMYNI=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw v1.0.759/go.mod h1:V0PvdfiaRTBUvtlwHihxTT8dSCl/ZOOZIymMlhknISA=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/chdfs v1.0.600 h1:qSpp4rEgAzfXhi1rPxes+AJp2mwnsyRGPY/Km1FuYGs=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/chdfs v1.0.600/go.mod h1:xud1dQ7Rc23yC5kS00TYRrvZ/A+94EOkwquaI6xGVac=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ciam v1.0.695 h1:FGwsF1/PgY+M92bEC+0NH4tJkI8i0qjrLbZWVjLXOAY=
Expand Down
16 changes: 16 additions & 0 deletions tencentcloud/connectivity/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"strconv"
"time"

cfw "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw/v20190904"

waf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf/v20180125"

dlc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dlc/v20210125"
Expand Down Expand Up @@ -182,6 +184,7 @@ type TencentCloudClient struct {
dlcConn *dlc.Client
wedataConn *wedata.Client
wafConn *waf.Client
cfwConn *cfw.Client
trocketConn *trocket.Client
}

Expand Down Expand Up @@ -1277,6 +1280,19 @@ func (me *TencentCloudClient) UseWafClient() *waf.Client {
return me.wafConn
}

func (me *TencentCloudClient) UseCfwClient() *cfw.Client {
if me.cfwConn != nil {
return me.cfwConn
}

cpf := me.NewClientProfile(300)
cpf.Language = "zh-CN"
me.cfwConn, _ = cfw.NewClient(me.Credential, me.Region, cpf)
me.cfwConn.WithHttpTransport(&LogRoundTripper{})

return me.cfwConn
}

// UseTrocketClient returns trocket client for service
func (me *TencentCloudClient) UseTrocketClient() *trocket.Client {
if me.trocketConn != nil {
Expand Down
180 changes: 180 additions & 0 deletions tencentcloud/data_source_tc_cfw_edge_fw_switches.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/*
Use this data source to query detailed information of cfw edge_fw_switches

Example Usage

```hcl
data "tencentcloud_cfw_edge_fw_switches" "example" {}
```
*/
package tencentcloud

import (
"context"
"strconv"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
cfw "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw/v20190904"
)

func dataSourceTencentCloudCfwEdgeFwSwitches() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCloudCfwEdgeFwSwitchesRead,
Schema: map[string]*schema.Schema{
"data": {
Computed: true,
Type: schema.TypeList,
Description: "Ip switch list.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"public_ip": {
Type: schema.TypeString,
Computed: true,
Description: "public ip.",
},
"public_ip_type": {
Type: schema.TypeInt,
Computed: true,
Description: "Public IP type.",
},
"instance_id": {
Type: schema.TypeString,
Computed: true,
Description: "Instance Id.",
},
"instance_name": {
Type: schema.TypeString,
Computed: true,
Description: "Instance Name.",
},
"intranet_ip": {
Type: schema.TypeString,
Computed: true,
Description: "Intranet Ip.",
},
"asset_type": {
Type: schema.TypeString,
Computed: true,
Description: "Asset Type.",
},
"region": {
Type: schema.TypeString,
Computed: true,
Description: "region.",
},
"status": {
Type: schema.TypeInt,
Computed: true,
Description: "status.",
},
"switch_mode": {
Type: schema.TypeInt,
Computed: true,
Description: "switch mode.",
},
"vpc_id": {
Type: schema.TypeString,
Computed: true,
Description: "vpc id.",
},
},
},
},
"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},
},
}
}

func dataSourceTencentCloudCfwEdgeFwSwitchesRead(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("data_source.tencentcloud_cfw_edge_fw_switches.read")()
defer inconsistentCheck(d, meta)()

var (
logId = getLogId(contextNil)
ctx = context.WithValue(context.TODO(), logIdKey, logId)
service = CfwService{client: meta.(*TencentCloudClient).apiV3Conn}
data []*cfw.EdgeIpInfo
)

err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeCfwEdgeFwSwitchesByFilter(ctx)
if e != nil {
return retryError(e)
}

data = result
return nil
})

if err != nil {
return err
}

tmpList := make([]map[string]interface{}, 0, len(data))

if data != nil {
for _, edgeFwSwitchData := range data {
edgeFwSwitchDataMap := map[string]interface{}{}

if edgeFwSwitchData.PublicIp != nil {
edgeFwSwitchDataMap["public_ip"] = edgeFwSwitchData.PublicIp
}

if edgeFwSwitchData.PublicIpType != nil {
edgeFwSwitchDataMap["public_ip_type"] = edgeFwSwitchData.PublicIpType
}

if edgeFwSwitchData.InstanceId != nil {
edgeFwSwitchDataMap["instance_id"] = edgeFwSwitchData.InstanceId
}

if edgeFwSwitchData.InstanceName != nil {
edgeFwSwitchDataMap["instance_name"] = edgeFwSwitchData.InstanceName
}

if edgeFwSwitchData.IntranetIp != nil {
edgeFwSwitchDataMap["intranet_ip"] = edgeFwSwitchData.IntranetIp
}

if edgeFwSwitchData.AssetType != nil {
edgeFwSwitchDataMap["asset_type"] = edgeFwSwitchData.AssetType
}

if edgeFwSwitchData.Region != nil {
edgeFwSwitchDataMap["region"] = edgeFwSwitchData.Region
}

if edgeFwSwitchData.Status != nil {
edgeFwSwitchDataMap["status"] = edgeFwSwitchData.Status
}

if edgeFwSwitchData.SwitchMode != nil {
edgeFwSwitchDataMap["switch_mode"] = edgeFwSwitchData.SwitchMode
}

if edgeFwSwitchData.VpcId != nil {
edgeFwSwitchDataMap["vpc_id"] = edgeFwSwitchData.VpcId
}

tmpList = append(tmpList, edgeFwSwitchDataMap)
}

_ = d.Set("data", tmpList)
}

d.SetId(strconv.FormatInt(time.Now().Unix(), 10))
output, ok := d.GetOk("result_output_file")
if ok && output.(string) != "" {
if e := writeToFile(output.(string), tmpList); e != nil {
return e
}
}

return nil
}
30 changes: 30 additions & 0 deletions tencentcloud/data_source_tc_cfw_edge_fw_switches_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package tencentcloud

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

// go test -i; go test -test.run TestAccTencentCloudNeedFixCfwEdgeFwSwitchesDataSource_basic -v
func TestAccTencentCloudNeedFixCfwEdgeFwSwitchesDataSource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCfwEdgeFwSwitchesDataSource,
Check: resource.ComposeTestCheckFunc(
testAccCheckTencentCloudDataSourceID("data.tencentcloud_cfw_edge_fw_switches.example"),
),
},
},
})
}

const testAccCfwEdgeFwSwitchesDataSource = `
data "tencentcloud_cfw_edge_fw_switches" "example" {}
`
Loading