-
Notifications
You must be signed in to change notification settings - Fork 136
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
feat/cfw #2149
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e760d81
feat/cfw
SevenEarth 2acd9a0
feat/cfw
SevenEarth 1e7999b
feat/cfw
SevenEarth f200cbe
feat/cfw
SevenEarth 0cda7bc
feat/cfw
SevenEarth 5feaa6d
feat/cfw
SevenEarth b020c4f
feat/cfw
SevenEarth 628a320
feat/cfw
SevenEarth 659c88b
feat/cfw
SevenEarth 58c9a8e
feat/cfw
SevenEarth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,7 +100,14 @@ require ( | |
gopkg.in/yaml.v2 v2.4.0 | ||
) | ||
|
||
<<<<<<< HEAD | ||
require ( | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里有冲突了 |
||
|
||
require ( | ||
4d63.com/gocheckcompilerdirectives v1.2.1 // indirect | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" {} | ||
` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里为啥要单独一个 require 呢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这是go mod自动生成的 非人为