From 5d6185fa56eb58602ff9b9bfd74cccc5fec0c060 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Thu, 24 Oct 2024 15:01:09 +0800 Subject: [PATCH 1/3] add --- tencentcloud/connectivity/client.go | 14 + tencentcloud/provider.go | 1 + tencentcloud/provider.md | 1 + ...ource_tc_ccn_route_table_input_policies.go | 243 ++++++++++++++++++ ...ource_tc_ccn_route_table_input_policies.md | 10 + ...cn_route_table_input_policies_extension.go | 1 + ..._tc_ccn_route_table_input_policies_test.go | 33 +++ .../services/ccn/service_tencentcloud_ccn.go | 41 +++ ...n_route_table_input_policies.html.markdown | 38 +++ website/tencentcloud.erb | 3 + 10 files changed, 385 insertions(+) create mode 100644 tencentcloud/services/ccn/data_source_tc_ccn_route_table_input_policies.go create mode 100644 tencentcloud/services/ccn/data_source_tc_ccn_route_table_input_policies.md create mode 100644 tencentcloud/services/ccn/data_source_tc_ccn_route_table_input_policies_extension.go create mode 100644 tencentcloud/services/ccn/data_source_tc_ccn_route_table_input_policies_test.go create mode 100644 website/docs/d/ccn_route_table_input_policies.html.markdown diff --git a/tencentcloud/connectivity/client.go b/tencentcloud/connectivity/client.go index 4e4ed6d3a0..b04c6c67d0 100644 --- a/tencentcloud/connectivity/client.go +++ b/tencentcloud/connectivity/client.go @@ -217,6 +217,7 @@ type TencentCloudClient struct { sslv20191205Conn *sslCertificate.Client postgresv20170312Conn *postgre.Client cfwv20190904Conn *cfw.Client + ccnv20170312Conn *vpc.Client } // NewClientProfile returns a new ClientProfile @@ -1886,3 +1887,16 @@ func (me *TencentCloudClient) UseCfwV20190904Client() *cfw.Client { return me.cfwv20190904Conn } + +// UseCcnV20170312Client return CCN client for service +func (me *TencentCloudClient) UseCcnV20170312Client() *vpc.Client { + if me.ccnv20170312Conn != nil { + return me.ccnv20170312Conn + } + cpf := me.NewClientProfile(300) + cpf.Language = "zh-CN" + me.ccnv20170312Conn, _ = vpc.NewClient(me.Credential, me.Region, cpf) + me.ccnv20170312Conn.WithHttpTransport(&LogRoundTripper{}) + + return me.ccnv20170312Conn +} diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index 22f2ebb335..7fed5b6261 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -457,6 +457,7 @@ func Provider() *schema.Provider { "tencentcloud_ccn_tenant_instances": ccn.DataSourceTencentCloudCcnTenantInstance(), "tencentcloud_ccn_cross_border_flow_monitor": ccn.DataSourceTencentCloudCcnCrossBorderFlowMonitor(), "tencentcloud_ccn_cross_border_region_bandwidth_limits": ccn.DataSourceTencentCloudCcnCrossBorderRegionBandwidthLimits(), + "tencentcloud_ccn_route_table_input_policies": ccn.DataSourceTencentCloudCcnRouteTableInputPolicies(), "tencentcloud_dc_instances": dc.DataSourceTencentCloudDcInstances(), "tencentcloud_dc_access_points": dc.DataSourceTencentCloudDcAccessPoints(), "tencentcloud_dc_internet_address_quota": dc.DataSourceTencentCloudDcInternetAddressQuota(), diff --git a/tencentcloud/provider.md b/tencentcloud/provider.md index 05db050e98..bdcb0f37aa 100644 --- a/tencentcloud/provider.md +++ b/tencentcloud/provider.md @@ -312,6 +312,7 @@ Cloud Connect Network(CCN) tencentcloud_ccn_cross_border_flow_monitor tencentcloud_ccn_cross_border_region_bandwidth_limits tencentcloud_ccn_routes + tencentcloud_ccn_route_table_input_policies Resource tencentcloud_ccn diff --git a/tencentcloud/services/ccn/data_source_tc_ccn_route_table_input_policies.go b/tencentcloud/services/ccn/data_source_tc_ccn_route_table_input_policies.go new file mode 100644 index 0000000000..e11de484fb --- /dev/null +++ b/tencentcloud/services/ccn/data_source_tc_ccn_route_table_input_policies.go @@ -0,0 +1,243 @@ +// Code generated by iacg; DO NOT EDIT. +package ccn + +import ( + "context" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + vpcv20170312 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312" + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" + "strings" +) + +func DataSourceTencentCloudCcnRouteTableInputPolicies() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudCcnRouteTableInputPoliciesRead, + Schema: map[string]*schema.Schema{ + "ccn_id": { + Type: schema.TypeString, + Required: true, + Description: "CCN Instance ID.", + }, + + "route_table_id": { + Type: schema.TypeString, + Required: true, + Description: "CCN Route table ID.", + }, + + "policy_version": { + Type: schema.TypeInt, + Optional: true, + Description: "Policy version.", + }, + + "policy_set": { + Type: schema.TypeList, + Computed: true, + Description: "Policy set.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "policys": { + Type: schema.TypeList, + Optional: true, + Description: "Policys.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "route_conditions": { + Type: schema.TypeList, + Required: true, + Description: "Routing conditions.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "condition type.", + }, + "values": { + Type: schema.TypeSet, + Required: true, + Description: "List of conditional values.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "match_pattern": { + Type: schema.TypeInt, + Required: true, + Description: "Matching mode, `1` precise matching, `0` fuzzy matching.", + }, + }, + }, + }, + "action": { + Type: schema.TypeString, + Required: true, + Description: "Routing behavior, `accept` allows, `drop` rejects.", + }, + "description": { + Type: schema.TypeString, + Required: true, + Description: "Policy description", + }, + "operate_as_path": { + Type: schema.TypeString, + Optional: true, + Description: "as-path operate", + }, + "as_path_operate_mode": { + Type: schema.TypeString, + Optional: true, + Description: "as-path operate mode", + }, + }, + }, + }, + "policy_version": { + Type: schema.TypeInt, + Optional: true, + Description: "Policy version.", + }, + "create_time": { + Type: schema.TypeString, + Optional: true, + Description: "Create time.", + }, + }, + }, + }, + + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudCcnRouteTableInputPoliciesRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("data_source.tencentcloud_ccn_route_table_input_policies.read")() + defer tccommon.InconsistentCheck(d, meta)() + + logId := tccommon.GetLogId(nil) + ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + + service := VpcService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + + var ( + ccnId string + routeTableId string + ) + if v, ok := d.GetOk("ccn_id"); ok { + ccnId = v.(string) + } + if v, ok := d.GetOk("route_table_id"); ok { + routeTableId = v.(string) + } + paramMap := make(map[string]interface{}) + if v, ok := d.GetOk("ccn_id"); ok { + paramMap["CcnId"] = helper.String(v.(string)) + } + + if v, ok := d.GetOk("route_table_id"); ok { + paramMap["RouteTableId"] = helper.String(v.(string)) + } + + if v, ok := d.GetOkExists("policy_version"); ok { + paramMap["PolicyVersion"] = helper.IntUint64(v.(int)) + } + + var respData []*vpcv20170312.CcnRouteTableInputPolicys + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeCcnRouteTableInputPoliciesByFilter(ctx, paramMap) + if e != nil { + return tccommon.RetryError(e) + } + respData = result + return nil + }) + if err != nil { + return err + } + + policySetList := make([]map[string]interface{}, 0, len(respData)) + if respData != nil { + for _, policySet := range respData { + policySetMap := map[string]interface{}{} + + policysList := make([]map[string]interface{}, 0, len(policySet.Policys)) + if policySet.Policys != nil { + for _, policys := range policySet.Policys { + policysMap := map[string]interface{}{} + + routeConditionsList := make([]map[string]interface{}, 0, len(policys.RouteConditions)) + if policys.RouteConditions != nil { + for _, routeConditions := range policys.RouteConditions { + routeConditionsMap := map[string]interface{}{} + + if routeConditions.Name != nil { + routeConditionsMap["name"] = routeConditions.Name + } + + if routeConditions.Values != nil { + routeConditionsMap["values"] = routeConditions.Values + } + + if routeConditions.MatchPattern != nil { + routeConditionsMap["match_pattern"] = routeConditions.MatchPattern + } + + routeConditionsList = append(routeConditionsList, routeConditionsMap) + } + + policysMap["route_conditions"] = routeConditionsList + } + if policys.Action != nil { + policysMap["action"] = policys.Action + } + + if policys.Description != nil { + policysMap["description"] = policys.Description + } + + if policys.OperateAsPath != nil { + policysMap["operate_as_path"] = policys.OperateAsPath + } + + if policys.AsPathOperateMode != nil { + policysMap["as_path_operate_mode"] = policys.AsPathOperateMode + } + + policysList = append(policysList, policysMap) + } + + policySetMap["policys"] = policysList + } + if policySet.PolicyVersion != nil { + policySetMap["policy_version"] = policySet.PolicyVersion + } + + if policySet.CreateTime != nil { + policySetMap["create_time"] = policySet.CreateTime + } + + policySetList = append(policySetList, policySetMap) + } + + _ = d.Set("policy_set", policySetList) + } + + d.SetId(strings.Join([]string{ccnId, routeTableId}, tccommon.FILED_SP)) + + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := tccommon.WriteToFile(output.(string), policySetList); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/services/ccn/data_source_tc_ccn_route_table_input_policies.md b/tencentcloud/services/ccn/data_source_tc_ccn_route_table_input_policies.md new file mode 100644 index 0000000000..ec277b226b --- /dev/null +++ b/tencentcloud/services/ccn/data_source_tc_ccn_route_table_input_policies.md @@ -0,0 +1,10 @@ +Use this data source to query CCN route table input policies. + +Example Usage + +```hcl +data "tencentcloud_ccn_route_table_input_policies" "example" { + ccn_id = "ccn-06jek8tf" + route_table_id = "ccnrtb-4jv5ltb9" +} +``` \ No newline at end of file diff --git a/tencentcloud/services/ccn/data_source_tc_ccn_route_table_input_policies_extension.go b/tencentcloud/services/ccn/data_source_tc_ccn_route_table_input_policies_extension.go new file mode 100644 index 0000000000..af6bc2cf6f --- /dev/null +++ b/tencentcloud/services/ccn/data_source_tc_ccn_route_table_input_policies_extension.go @@ -0,0 +1 @@ +package ccn diff --git a/tencentcloud/services/ccn/data_source_tc_ccn_route_table_input_policies_test.go b/tencentcloud/services/ccn/data_source_tc_ccn_route_table_input_policies_test.go new file mode 100644 index 0000000000..6fee4e662b --- /dev/null +++ b/tencentcloud/services/ccn/data_source_tc_ccn_route_table_input_policies_test.go @@ -0,0 +1,33 @@ +package ccn_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudCcnRouteTableInputPoliciesDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{{ + Config: testAccCcnRouteTableInputPoliciesDataSource, + Check: resource.ComposeTestCheckFunc( + tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_ccn_route_table_input_policies.example"), + resource.TestCheckResourceAttrSet("data.tencentcloud_ccn_route_table_input_policies.example", "ccn_id"), + resource.TestCheckResourceAttrSet("data.tencentcloud_ccn_route_table_input_policies.example", "route_table_id"), + ), + }}, + }) +} + +const testAccCcnRouteTableInputPoliciesDataSource = ` +data "tencentcloud_ccn_route_table_input_policies" "example" { + ccn_id = "ccn-06jek8tf" + route_table_id = "ccnrtb-4jv5ltb9" +} +` diff --git a/tencentcloud/services/ccn/service_tencentcloud_ccn.go b/tencentcloud/services/ccn/service_tencentcloud_ccn.go index 3d983c8d22..26a1596dd0 100644 --- a/tencentcloud/services/ccn/service_tencentcloud_ccn.go +++ b/tencentcloud/services/ccn/service_tencentcloud_ccn.go @@ -1340,3 +1340,44 @@ func (me *VpcService) DescribeTenantCcnByFilter(ctx context.Context, param map[s return } + +func (me *VpcService) DescribeCcnRouteTableInputPoliciesByFilter(ctx context.Context, param map[string]interface{}) (ret []*vpc.CcnRouteTableInputPolicys, errRet error) { + var ( + logId = tccommon.GetLogId(ctx) + request = vpc.NewDescribeCcnRouteTableInputPolicysRequest() + ) + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error()) + } + }() + + for k, v := range param { + if k == "CcnId" { + request.CcnId = v.(*string) + } + if k == "RouteTableId" { + request.RouteTableId = v.(*string) + } + if k == "PolicyVersion" { + request.PolicyVersion = v.(*uint64) + } + } + + ratelimit.Check(request.GetAction()) + + response, err := me.client.UseCcnV20170312Client().DescribeCcnRouteTableInputPolicys(request) + if err != nil { + errRet = err + return + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + if len(response.Response.PolicySet) < 1 { + return + } + + ret = response.Response.PolicySet + return +} diff --git a/website/docs/d/ccn_route_table_input_policies.html.markdown b/website/docs/d/ccn_route_table_input_policies.html.markdown new file mode 100644 index 0000000000..a0680c0c37 --- /dev/null +++ b/website/docs/d/ccn_route_table_input_policies.html.markdown @@ -0,0 +1,38 @@ +--- +subcategory: "Cloud Connect Network(CCN)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_ccn_route_table_input_policies" +sidebar_current: "docs-tencentcloud-datasource-ccn_route_table_input_policies" +description: |- + Use this data source to query CCN route table input policies. +--- + +# tencentcloud_ccn_route_table_input_policies + +Use this data source to query CCN route table input policies. + +## Example Usage + +```hcl +data "tencentcloud_ccn_route_table_input_policies" "example" { + ccn_id = "ccn-06jek8tf" + route_table_id = "ccnrtb-4jv5ltb9" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `ccn_id` - (Required, String) CCN Instance ID. +* `route_table_id` - (Required, String) CCN Route table ID. +* `policy_version` - (Optional, Int) Policy version. +* `result_output_file` - (Optional, String) Used to save results. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `policy_set` - Policy set. + + diff --git a/website/tencentcloud.erb b/website/tencentcloud.erb index 4b2fdbf57c..76ef61e5d5 100644 --- a/website/tencentcloud.erb +++ b/website/tencentcloud.erb @@ -956,6 +956,9 @@
  • tencentcloud_ccn_instances
  • +
  • + tencentcloud_ccn_route_table_input_policies +
  • tencentcloud_ccn_routes
  • From 6a0e22012f8b88fedcd8594ddb32684c8faffe0e Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Thu, 24 Oct 2024 15:02:53 +0800 Subject: [PATCH 2/3] add --- .changelog/2910.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/2910.txt diff --git a/.changelog/2910.txt b/.changelog/2910.txt new file mode 100644 index 0000000000..3fea28e2e1 --- /dev/null +++ b/.changelog/2910.txt @@ -0,0 +1,3 @@ +```release-note:new-data-source +tencentcloud_ccn_route_table_input_policies +``` \ No newline at end of file From b9bcad2105878ef4438373c35c62870d42c7635d Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Thu, 24 Oct 2024 15:12:53 +0800 Subject: [PATCH 3/3] add --- tencentcloud/services/ccn/resource_tc_ccn_routes.md | 2 +- website/docs/r/ccn_routes.html.markdown | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tencentcloud/services/ccn/resource_tc_ccn_routes.md b/tencentcloud/services/ccn/resource_tc_ccn_routes.md index ca2a92ecd4..8d035107b3 100644 --- a/tencentcloud/services/ccn/resource_tc_ccn_routes.md +++ b/tencentcloud/services/ccn/resource_tc_ccn_routes.md @@ -5,7 +5,7 @@ Example Usage ```hcl resource "tencentcloud_ccn_routes" "example" { ccn_id = "ccn-gr7nynbd" - route_id = "ccnrtb-jpf7bzn3" + route_id = "ccnr-5uhewx1s" switch = "off" } ``` diff --git a/website/docs/r/ccn_routes.html.markdown b/website/docs/r/ccn_routes.html.markdown index 97f31ddf40..e52e1ef6a6 100644 --- a/website/docs/r/ccn_routes.html.markdown +++ b/website/docs/r/ccn_routes.html.markdown @@ -16,7 +16,7 @@ Provides a resource to create a vpc ccn_routes switch ```hcl resource "tencentcloud_ccn_routes" "example" { ccn_id = "ccn-gr7nynbd" - route_id = "ccnrtb-jpf7bzn3" + route_id = "ccnr-5uhewx1s" switch = "off" } ```