diff --git a/.changelog/3607.txt b/.changelog/3607.txt index 6e3f194167..d87a23a763 100644 --- a/.changelog/3607.txt +++ b/.changelog/3607.txt @@ -1,4 +1,4 @@ -```release-note:new-datasource +```release-note:new-data-source tencentcloud_igtm_address_pool_list ``` diff --git a/.changelog/3608.txt b/.changelog/3608.txt new file mode 100644 index 0000000000..1b6e489f07 --- /dev/null +++ b/.changelog/3608.txt @@ -0,0 +1,35 @@ +```release-note:new-data-source +tencentcloud_igtm_instance_list +``` + +```release-note:new-data-source +tencentcloud_igtm_monitors +``` + +```release-note:new-data-source +tencentcloud_igtm_detectors +``` + +```release-note:new-data-source +tencentcloud_igtm_strategy_list +``` + +```release-note:new-data-source +tencentcloud_igtm_instance_package_list +``` + +```release-note:new-data-source +tencentcloud_igtm_detect_task_package_list +``` + +```release-note:new-resource +tencentcloud_igtm_instance +``` + +```release-note:new-resource +tencentcloud_igtm_monitor +``` + +```release-note:new-resource +tencentcloud_igtm_strategy +``` diff --git a/go.mod b/go.mod index 17ea5cef4c..b4979dd940 100644 --- a/go.mod +++ b/go.mod @@ -46,7 +46,7 @@ require ( github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1107 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1148 - github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.50 + github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.3 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1206 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.1161 @@ -115,6 +115,7 @@ require ( github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dasb v1.0.970 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gwlb v1.0.1127 + github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm v1.3.3 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mqtt v1.0.1136 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/oceanus v1.0.831 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/region v1.0.920 @@ -313,7 +314,6 @@ require ( github.com/subosito/gotenv v1.4.1 // indirect github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c // indirect github.com/tdakkota/asciicheck v0.2.0 // indirect - github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm v1.1.27 // indirect github.com/tetafro/godot v1.4.11 // indirect github.com/tidwall/gjson v1.17.0 // indirect github.com/tidwall/match v1.1.1 // indirect diff --git a/go.sum b/go.sum index fc92f572da..f0d1928c58 100644 --- a/go.sum +++ b/go.sum @@ -981,6 +981,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.49 h1:BQwUw github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.49/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.50 h1:wZGiUXmzr4L0S1coFhnjddkyNrO5ZTtfxBDrbeR+1d8= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.50/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.3 h1:r05ohLc0LVEpiEQeOJ5QwCiKk6XM9kjTca6+UAbNR/8= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.3/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993 h1:WlPgXldQCxt7qi5Xrc6j6zTrsXWzN5BcOGs7Irq7fwQ= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993/go.mod h1:Z9U8zNtyuyKhjS0698wqsrG/kLx1TQ5CEixXBwVe7xY= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860 h1:F3esKBIT3HW9+7Gt8cVgf8X06VdGIczpgLBUECzSEzU= @@ -1029,6 +1031,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gwlb v1.0.1127 h1:1ZhrN github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gwlb v1.0.1127/go.mod h1:HSfd/mm8VyXn7VTe3tOvPgsumbsfeYcG5QgaCI1vsRk= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm v1.1.27 h1:XuNVpfyHcmyAavX06p8w7FLjY4eT70ndPZbazxRpbCY= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm v1.1.27/go.mod h1:26rOgYylbB4qROMOuYaOzUDF8CSKQi022SbX/FB+NHQ= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm v1.3.3 h1:zIgjKSutqWwnLEK3mCMbvthtI2uf5/NL6xhVz+09GC4= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm v1.3.3/go.mod h1:jog/RwpOLs2SbKz1iSenpjeQoVMPJg0F6D/0wa+qLR4= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.563/go.mod h1:uom4Nvi9W+Qkom0exYiJ9VWJjXwyxtPYTkKkaLMlfE0= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.1145 h1:/wV6YoCqDU1XXci7kxt/k+RTwx2xLzcxH4NYbC1UT6k= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.1145/go.mod h1:tUblC9MYww0ZRScBkLYINJ7F1fxAv/Ymmpbjn05RTPY= diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index baf4ed922a..fd113e940e 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -1300,7 +1300,13 @@ func Provider() *schema.Provider { "tencentcloud_mqtt_instance_detail": mqtt.DataSourceTencentCloudMqttInstanceDetail(), "tencentcloud_mqtt_topics": mqtt.DataSourceTencentCloudMqttTopics(), "tencentcloud_billing_budget_operation_log": billing.DataSourceTencentCloudBillingBudgetOperationLog(), + "tencentcloud_igtm_instance_list": igtm.DataSourceTencentCloudIgtmInstanceList(), "tencentcloud_igtm_address_pool_list": igtm.DataSourceTencentCloudIgtmAddressPoolList(), + "tencentcloud_igtm_monitors": igtm.DataSourceTencentCloudIgtmMonitors(), + "tencentcloud_igtm_detectors": igtm.DataSourceTencentCloudIgtmDetectors(), + "tencentcloud_igtm_strategy_list": igtm.DataSourceTencentCloudIgtmStrategyList(), + "tencentcloud_igtm_instance_package_list": igtm.DataSourceTencentCloudIgtmInstancePackageList(), + "tencentcloud_igtm_detect_task_package_list": igtm.DataSourceTencentCloudIgtmDetectTaskPackageList(), }, ResourcesMap: map[string]*schema.Resource{ @@ -2472,7 +2478,10 @@ func Provider() *schema.Provider { "tencentcloud_mqtt_http_authenticator": mqtt.ResourceTencentCloudMqttHttpAuthenticator(), "tencentcloud_billing_allocation_tag": billing.ResourceTencentCloudBillingAllocationTag(), "tencentcloud_billing_budget": billing.ResourceTencentCloudBillingBudget(), + "tencentcloud_igtm_instance": igtm.ResourceTencentCloudIgtmInstance(), "tencentcloud_igtm_address_pool": igtm.ResourceTencentCloudIgtmAddressPool(), + "tencentcloud_igtm_monitor": igtm.ResourceTencentCloudIgtmMonitor(), + "tencentcloud_igtm_strategy": igtm.ResourceTencentCloudIgtmStrategy(), }, ConfigureFunc: providerConfigure, diff --git a/tencentcloud/provider.md b/tencentcloud/provider.md index 02838bbe5e..d575c1345e 100644 --- a/tencentcloud/provider.md +++ b/tencentcloud/provider.md @@ -2447,6 +2447,15 @@ tencentcloud_tcss_refresh_task_operation Intelligent Global Traffic Manager(IGTM) Data Source +tencentcloud_igtm_instance_list tencentcloud_igtm_address_pool_list +tencentcloud_igtm_monitors +tencentcloud_igtm_detectors +tencentcloud_igtm_strategy_list +tencentcloud_igtm_instance_package_list +tencentcloud_igtm_detect_task_package_list Resource +tencentcloud_igtm_instance tencentcloud_igtm_address_pool +tencentcloud_igtm_monitor +tencentcloud_igtm_strategy diff --git a/tencentcloud/services/igtm/data_source_tc_igtm_address_pool_list.go b/tencentcloud/services/igtm/data_source_tc_igtm_address_pool_list.go index 55af7c0e4c..446893d1cf 100644 --- a/tencentcloud/services/igtm/data_source_tc_igtm_address_pool_list.go +++ b/tencentcloud/services/igtm/data_source_tc_igtm_address_pool_list.go @@ -18,13 +18,13 @@ func DataSourceTencentCloudIgtmAddressPoolList() *schema.Resource { "filters": { Type: schema.TypeList, Optional: true, - Description: "Alert filter conditions: PoolName: Address pool name; MonitorId: Monitor ID.", + Description: "Alert filter conditions.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, Required: true, - Description: "Filter field name, supported list as follows:\n- type: Main resource type, CDN.\n- instanceId: IGTM instance ID. This is a required parameter, failure to provide will cause interface query failure.", + Description: "Filter field name, supported list as follows:\n- PoolName: Address pool name.\n- MonitorId: Monitor ID. This is a required parameter, failure to provide will cause interface query failure.", }, "value": { Type: schema.TypeSet, diff --git a/tencentcloud/services/igtm/data_source_tc_igtm_detect_task_package_list.go b/tencentcloud/services/igtm/data_source_tc_igtm_detect_task_package_list.go new file mode 100644 index 0000000000..080e2dab37 --- /dev/null +++ b/tencentcloud/services/igtm/data_source_tc_igtm_detect_task_package_list.go @@ -0,0 +1,265 @@ +package igtm + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + igtmv20231024 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm/v20231024" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func DataSourceTencentCloudIgtmDetectTaskPackageList() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudIgtmDetectTaskPackageListRead, + Schema: map[string]*schema.Schema{ + "filters": { + Type: schema.TypeList, + Optional: true, + Description: "Detect task filter conditions.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "Filter field name, supported list as follows:\n- ResourceId: detect task resource id.\n- PeriodStart: minimum expiration time.\n- PeriodEnd: maximum expiration time.", + }, + "value": { + Type: schema.TypeSet, + Required: true, + Description: "Filter field value.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "fuzzy": { + Type: schema.TypeBool, + Optional: true, + Description: "Whether to enable fuzzy query, only supports filter field name as domain.\nWhen fuzzy query is enabled, maximum Value length is 1, otherwise maximum Value length is 5. (Reserved field, not currently used).", + }, + }, + }, + }, + + "task_package_set": { + Type: schema.TypeList, + Computed: true, + Description: "Detect task package list.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "resource_id": { + Type: schema.TypeString, + Computed: true, + Description: "Resource ID.", + }, + "resource_type": { + Type: schema.TypeString, + Computed: true, + Description: "Resource type\nTASK Detect task.", + }, + "quota": { + Type: schema.TypeInt, + Computed: true, + Description: "Quota.", + }, + "current_deadline": { + Type: schema.TypeString, + Computed: true, + Description: "Package expiration time.", + }, + "create_time": { + Type: schema.TypeString, + Computed: true, + Description: "Package creation time.", + }, + "is_expire": { + Type: schema.TypeInt, + Computed: true, + Description: "Whether expired 0 no 1 yes.", + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "Status\nENABLED: Normal\nISOLATED: Isolated\nDESTROYED: Destroyed\nREFUNDED: Refunded.", + }, + "auto_renew_flag": { + Type: schema.TypeInt, + Computed: true, + Description: "Whether auto-renew 0 no 1 yes.", + }, + "remark": { + Type: schema.TypeString, + Computed: true, + Description: "Remark.", + }, + "cost_item_list": { + Type: schema.TypeList, + Computed: true, + Description: "Billing item.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cost_name": { + Type: schema.TypeString, + Computed: true, + Description: "Billing item name.", + }, + "cost_value": { + Type: schema.TypeInt, + Computed: true, + Description: "Billing item value.", + }, + }, + }, + }, + "group": { + Type: schema.TypeInt, + Computed: true, + Description: "Detect task type: 100 system setting; 200 billing; 300 management system; 110D monitoring migration free task; 120 disaster recovery switch task.", + }, + }, + }, + }, + + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudIgtmDetectTaskPackageListRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("data_source.tencentcloud_igtm_detect_task_package_list.read")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(nil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + service = IgtmService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + ) + + paramMap := make(map[string]interface{}) + if v, ok := d.GetOk("filters"); ok { + filtersSet := v.([]interface{}) + tmpSet := make([]*igtmv20231024.ResourceFilter, 0, len(filtersSet)) + for _, item := range filtersSet { + filtersMap := item.(map[string]interface{}) + resourceFilter := igtmv20231024.ResourceFilter{} + if v, ok := filtersMap["name"].(string); ok && v != "" { + resourceFilter.Name = helper.String(v) + } + + if v, ok := filtersMap["value"]; ok { + valueSet := v.(*schema.Set).List() + for i := range valueSet { + value := valueSet[i].(string) + resourceFilter.Value = append(resourceFilter.Value, helper.String(value)) + } + } + + if v, ok := filtersMap["fuzzy"].(bool); ok { + resourceFilter.Fuzzy = helper.Bool(v) + } + + tmpSet = append(tmpSet, &resourceFilter) + } + + paramMap["Filters"] = tmpSet + } + + var respData []*igtmv20231024.DetectTaskPackage + reqErr := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeIgtmDetectTaskPackageListByFilter(ctx, paramMap) + if e != nil { + return tccommon.RetryError(e) + } + + respData = result + return nil + }) + + if reqErr != nil { + return reqErr + } + + taskPackageSetList := make([]map[string]interface{}, 0, len(respData)) + if respData != nil { + for _, taskPackageSet := range respData { + taskPackageSetMap := map[string]interface{}{} + if taskPackageSet.ResourceId != nil { + taskPackageSetMap["resource_id"] = taskPackageSet.ResourceId + } + + if taskPackageSet.ResourceType != nil { + taskPackageSetMap["resource_type"] = taskPackageSet.ResourceType + } + + if taskPackageSet.Quota != nil { + taskPackageSetMap["quota"] = taskPackageSet.Quota + } + + if taskPackageSet.CurrentDeadline != nil { + taskPackageSetMap["current_deadline"] = taskPackageSet.CurrentDeadline + } + + if taskPackageSet.CreateTime != nil { + taskPackageSetMap["create_time"] = taskPackageSet.CreateTime + } + + if taskPackageSet.IsExpire != nil { + taskPackageSetMap["is_expire"] = taskPackageSet.IsExpire + } + + if taskPackageSet.Status != nil { + taskPackageSetMap["status"] = taskPackageSet.Status + } + + if taskPackageSet.AutoRenewFlag != nil { + taskPackageSetMap["auto_renew_flag"] = taskPackageSet.AutoRenewFlag + } + + if taskPackageSet.Remark != nil { + taskPackageSetMap["remark"] = taskPackageSet.Remark + } + + costItemListList := make([]map[string]interface{}, 0, len(taskPackageSet.CostItemList)) + if taskPackageSet.CostItemList != nil { + for _, costItemList := range taskPackageSet.CostItemList { + costItemListMap := map[string]interface{}{} + if costItemList.CostName != nil { + costItemListMap["cost_name"] = costItemList.CostName + } + + if costItemList.CostValue != nil { + costItemListMap["cost_value"] = costItemList.CostValue + } + + costItemListList = append(costItemListList, costItemListMap) + } + + taskPackageSetMap["cost_item_list"] = costItemListList + } + + if taskPackageSet.Group != nil { + taskPackageSetMap["group"] = taskPackageSet.Group + } + + taskPackageSetList = append(taskPackageSetList, taskPackageSetMap) + } + + _ = d.Set("task_package_set", taskPackageSetList) + } + + d.SetId(helper.BuildToken()) + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := tccommon.WriteToFile(output.(string), taskPackageSetList); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/services/igtm/data_source_tc_igtm_detect_task_package_list.md b/tencentcloud/services/igtm/data_source_tc_igtm_detect_task_package_list.md new file mode 100644 index 0000000000..3ba4b001ce --- /dev/null +++ b/tencentcloud/services/igtm/data_source_tc_igtm_detect_task_package_list.md @@ -0,0 +1,21 @@ +Use this data source to query detailed information of IGTM detect task package list + +Example Usage + +Query all igtm detect task package list + +```hcl +data "tencentcloud_igtm_detect_task_package_list" "example" {} +``` + +Query igtm detect task package list by filter + +```hcl +data "tencentcloud_igtm_detect_task_package_list" "example" { + filters { + name = "ResourceId" + value = ["task-qqcoptejbwbf"] + fuzzy = true + } +} +``` diff --git a/tencentcloud/services/igtm/data_source_tc_igtm_detect_task_package_list_test.go b/tencentcloud/services/igtm/data_source_tc_igtm_detect_task_package_list_test.go new file mode 100644 index 0000000000..b65c5b78f1 --- /dev/null +++ b/tencentcloud/services/igtm/data_source_tc_igtm_detect_task_package_list_test.go @@ -0,0 +1,29 @@ +package igtm_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudIgtmDetectTaskPackageListDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{{ + Config: testAccIgtmDetectTaskPackageListDataSource, + Check: resource.ComposeTestCheckFunc( + tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_igtm_detect_task_package_list.example"), + ), + }}, + }) +} + +const testAccIgtmDetectTaskPackageListDataSource = ` +data "tencentcloud_igtm_detect_task_package_list" "example" {} +` diff --git a/tencentcloud/services/igtm/data_source_tc_igtm_detectors.go b/tencentcloud/services/igtm/data_source_tc_igtm_detectors.go new file mode 100644 index 0000000000..03bebcbae7 --- /dev/null +++ b/tencentcloud/services/igtm/data_source_tc_igtm_detectors.go @@ -0,0 +1,130 @@ +package igtm + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + igtmv20231024 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm/v20231024" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func DataSourceTencentCloudIgtmDetectors() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudIgtmDetectorsRead, + Schema: map[string]*schema.Schema{ + "detector_group_set": { + Type: schema.TypeList, + Computed: true, + Description: "Detector group list.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "gid": { + Type: schema.TypeInt, + Computed: true, + Description: "Line group ID GroupLineId.", + }, + "group_type": { + Type: schema.TypeString, + Computed: true, + Description: "bgp, international, isp.", + }, + "group_name": { + Type: schema.TypeString, + Computed: true, + Description: "Group name.", + }, + "internet_family": { + Type: schema.TypeString, + Computed: true, + Description: "ipv4, ipv6.", + }, + "package_set": { + Type: schema.TypeSet, + Computed: true, + Description: "Supported package types.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + }, + }, + + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudIgtmDetectorsRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("data_source.tencentcloud_igtm_detectors.read")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(nil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + service = IgtmService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + ) + + paramMap := make(map[string]interface{}) + var respData []*igtmv20231024.DetectorGroup + reqErr := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeIgtmDetectorsByFilter(ctx, paramMap) + if e != nil { + return tccommon.RetryError(e) + } + + respData = result + return nil + }) + + if reqErr != nil { + return reqErr + } + + detectorGroupSetList := make([]map[string]interface{}, 0, len(respData)) + if respData != nil { + for _, detectorGroupSet := range respData { + detectorGroupSetMap := map[string]interface{}{} + if detectorGroupSet.Gid != nil { + detectorGroupSetMap["gid"] = detectorGroupSet.Gid + } + + if detectorGroupSet.GroupType != nil { + detectorGroupSetMap["group_type"] = detectorGroupSet.GroupType + } + + if detectorGroupSet.GroupName != nil { + detectorGroupSetMap["group_name"] = detectorGroupSet.GroupName + } + + if detectorGroupSet.InternetFamily != nil { + detectorGroupSetMap["internet_family"] = detectorGroupSet.InternetFamily + } + + if detectorGroupSet.PackageSet != nil { + detectorGroupSetMap["package_set"] = detectorGroupSet.PackageSet + } + + detectorGroupSetList = append(detectorGroupSetList, detectorGroupSetMap) + } + + _ = d.Set("detector_group_set", detectorGroupSetList) + } + + d.SetId(helper.BuildToken()) + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := tccommon.WriteToFile(output.(string), detectorGroupSetList); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/services/igtm/data_source_tc_igtm_detectors.md b/tencentcloud/services/igtm/data_source_tc_igtm_detectors.md new file mode 100644 index 0000000000..365e4690a8 --- /dev/null +++ b/tencentcloud/services/igtm/data_source_tc_igtm_detectors.md @@ -0,0 +1,7 @@ +Use this data source to query detailed information of IGTM detectors + +Example Usage + +```hcl +data "tencentcloud_igtm_detectors" "example" {} +``` diff --git a/tencentcloud/services/igtm/data_source_tc_igtm_detectors_test.go b/tencentcloud/services/igtm/data_source_tc_igtm_detectors_test.go new file mode 100644 index 0000000000..645330ee0a --- /dev/null +++ b/tencentcloud/services/igtm/data_source_tc_igtm_detectors_test.go @@ -0,0 +1,29 @@ +package igtm_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudIgtmDetectorsDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{{ + Config: testAccIgtmDetectorsDataSource, + Check: resource.ComposeTestCheckFunc( + tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_igtm_detectors.example"), + ), + }}, + }) +} + +const testAccIgtmDetectorsDataSource = ` +data "tencentcloud_igtm_detectors" "example" {} +` diff --git a/tencentcloud/services/igtm/data_source_tc_igtm_instance_list.go b/tencentcloud/services/igtm/data_source_tc_igtm_instance_list.go new file mode 100644 index 0000000000..a5a70b0a0d --- /dev/null +++ b/tencentcloud/services/igtm/data_source_tc_igtm_instance_list.go @@ -0,0 +1,331 @@ +package igtm + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + igtmv20231024 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm/v20231024" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func DataSourceTencentCloudIgtmInstanceList() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudIgtmInstanceListRead, + Schema: map[string]*schema.Schema{ + "filters": { + Type: schema.TypeList, + Optional: true, + Description: "Filter conditions.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "Filter field name, supported list as follows:\n- InstanceId: IGTM instance ID.\n- Domain: IGTM instance domain.\n- MonitorId: Monitor ID.\n- PoolId: Pool ID. This is a required parameter, not passing it will cause interface query failure.", + }, + "value": { + Type: schema.TypeSet, + Required: true, + Description: "Filter field value.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "fuzzy": { + Type: schema.TypeBool, + Optional: true, + Description: "Whether to enable fuzzy query, only supports filter field name as domain.\nWhen fuzzy query is enabled, maximum Value length is 1, otherwise maximum Value length is 5. (Reserved field, not currently used).", + }, + }, + }, + }, + + "instance_set": { + Type: schema.TypeList, + Computed: true, + Description: "Instance list.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "instance_id": { + Type: schema.TypeString, + Computed: true, + Description: "Instance ID.", + }, + "instance_name": { + Type: schema.TypeString, + Computed: true, + Description: "Instance name.", + }, + "resource_id": { + Type: schema.TypeString, + Computed: true, + Description: "Resource ID.", + }, + "domain": { + Type: schema.TypeString, + Computed: true, + Description: "Business domain.", + }, + "access_type": { + Type: schema.TypeString, + Computed: true, + Description: "Cname domain access method\nCUSTOM: Custom access domain\nSYSTEM: System access domain.", + }, + "access_domain": { + Type: schema.TypeString, + Computed: true, + Description: "Access domain.", + }, + "access_sub_domain": { + Type: schema.TypeString, + Computed: true, + Description: "Access subdomain.", + }, + "global_ttl": { + Type: schema.TypeInt, + Computed: true, + Description: "Global record expiration time.", + }, + "package_type": { + Type: schema.TypeString, + Computed: true, + Description: "Package type\nFREE: Free version\nSTANDARD: Standard version\nULTIMATE: Ultimate version.", + }, + "working_status": { + Type: schema.TypeString, + Computed: true, + Description: "Instance running status\nNORMAL: Healthy\nFAULTY: At risk\nDOWN: Down\nUNKNOWN: Unknown.", + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "Instance status, ENABLED: Normal, DISABLED: Disabled.", + }, + "is_cname_configured": { + Type: schema.TypeBool, + Computed: true, + Description: "Whether cname access: true accessed; false not accessed.", + }, + "remark": { + Type: schema.TypeString, + Computed: true, + Description: "Remark.", + }, + "strategy_num": { + Type: schema.TypeInt, + Computed: true, + Description: "Strategy count.", + }, + "address_pool_num": { + Type: schema.TypeInt, + Computed: true, + Description: "Bound address pool count.", + }, + "monitor_num": { + Type: schema.TypeInt, + Computed: true, + Description: "Bound monitor count.", + }, + "pool_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Address pool ID.", + }, + "pool_name": { + Type: schema.TypeString, + Computed: true, + Description: "Address pool name.", + }, + "created_on": { + Type: schema.TypeString, + Computed: true, + Description: "Instance creation time.", + }, + "updated_on": { + Type: schema.TypeString, + Computed: true, + Description: "Instance update time.", + }, + }, + }, + }, + + "system_access_enabled": { + Type: schema.TypeBool, + Computed: true, + Description: "Whether system domain access is supported: true supported; false not supported.", + }, + + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudIgtmInstanceListRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("data_source.tencentcloud_igtm_instance_list.read")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(nil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + service = IgtmService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + ) + + paramMap := make(map[string]interface{}) + if v, ok := d.GetOk("filters"); ok { + filtersSet := v.([]interface{}) + tmpSet := make([]*igtmv20231024.ResourceFilter, 0, len(filtersSet)) + for _, item := range filtersSet { + filtersMap := item.(map[string]interface{}) + resourceFilter := igtmv20231024.ResourceFilter{} + if v, ok := filtersMap["name"].(string); ok && v != "" { + resourceFilter.Name = helper.String(v) + } + + if v, ok := filtersMap["value"]; ok { + valueSet := v.(*schema.Set).List() + for i := range valueSet { + value := valueSet[i].(string) + resourceFilter.Value = append(resourceFilter.Value, helper.String(value)) + } + } + + if v, ok := filtersMap["fuzzy"].(bool); ok { + resourceFilter.Fuzzy = helper.Bool(v) + } + tmpSet = append(tmpSet, &resourceFilter) + } + + paramMap["Filters"] = tmpSet + } + + var ( + respData []*igtmv20231024.Instance + systemAccessEnabled *bool + ) + reqErr := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + result, saEnabled, e := service.DescribeIgtmInstanceListByFilter(ctx, paramMap) + if e != nil { + return tccommon.RetryError(e) + } + + respData = result + systemAccessEnabled = saEnabled + return nil + }) + + if reqErr != nil { + return reqErr + } + + instanceSetList := make([]map[string]interface{}, 0, len(respData)) + if respData != nil { + for _, instanceSet := range respData { + instanceSetMap := map[string]interface{}{} + if instanceSet.InstanceId != nil { + instanceSetMap["instance_id"] = instanceSet.InstanceId + } + + if instanceSet.InstanceName != nil { + instanceSetMap["instance_name"] = instanceSet.InstanceName + } + + if instanceSet.ResourceId != nil { + instanceSetMap["resource_id"] = instanceSet.ResourceId + } + + if instanceSet.Domain != nil { + instanceSetMap["domain"] = instanceSet.Domain + } + + if instanceSet.AccessType != nil { + instanceSetMap["access_type"] = instanceSet.AccessType + } + + if instanceSet.AccessDomain != nil { + instanceSetMap["access_domain"] = instanceSet.AccessDomain + } + + if instanceSet.AccessSubDomain != nil { + instanceSetMap["access_sub_domain"] = instanceSet.AccessSubDomain + } + + if instanceSet.GlobalTtl != nil { + instanceSetMap["global_ttl"] = instanceSet.GlobalTtl + } + + if instanceSet.PackageType != nil { + instanceSetMap["package_type"] = instanceSet.PackageType + } + + if instanceSet.WorkingStatus != nil { + instanceSetMap["working_status"] = instanceSet.WorkingStatus + } + + if instanceSet.Status != nil { + instanceSetMap["status"] = instanceSet.Status + } + + if instanceSet.IsCnameConfigured != nil { + instanceSetMap["is_cname_configured"] = instanceSet.IsCnameConfigured + } + + if instanceSet.Remark != nil { + instanceSetMap["remark"] = instanceSet.Remark + } + + if instanceSet.StrategyNum != nil { + instanceSetMap["strategy_num"] = instanceSet.StrategyNum + } + + if instanceSet.AddressPoolNum != nil { + instanceSetMap["address_pool_num"] = instanceSet.AddressPoolNum + } + + if instanceSet.MonitorNum != nil { + instanceSetMap["monitor_num"] = instanceSet.MonitorNum + } + + if instanceSet.PoolId != nil { + instanceSetMap["pool_id"] = instanceSet.PoolId + } + + if instanceSet.PoolName != nil { + instanceSetMap["pool_name"] = instanceSet.PoolName + } + + if instanceSet.CreatedOn != nil { + instanceSetMap["created_on"] = instanceSet.CreatedOn + } + + if instanceSet.UpdatedOn != nil { + instanceSetMap["updated_on"] = instanceSet.UpdatedOn + } + + instanceSetList = append(instanceSetList, instanceSetMap) + } + + _ = d.Set("instance_set", instanceSetList) + } + + if systemAccessEnabled != nil { + _ = d.Set("system_access_enabled", systemAccessEnabled) + } + + d.SetId(helper.BuildToken()) + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := tccommon.WriteToFile(output.(string), d); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/services/igtm/data_source_tc_igtm_instance_list.md b/tencentcloud/services/igtm/data_source_tc_igtm_instance_list.md new file mode 100644 index 0000000000..c0469b05cf --- /dev/null +++ b/tencentcloud/services/igtm/data_source_tc_igtm_instance_list.md @@ -0,0 +1,21 @@ +Use this data source to query detailed information of IGTM instance list + +Example Usage + +Query all igtm instance list + +```hcl +data "tencentcloud_igtm_instance_list" "example" {} +``` + +Query igtm instance list by filters + +```hcl +data "tencentcloud_igtm_instance_list" "example" { + filters { + name = "InstanceId" + value = ["gtm-uukztqtoaru"] + fuzzy = true + } +} +``` \ No newline at end of file diff --git a/tencentcloud/services/igtm/data_source_tc_igtm_instance_list_test.go b/tencentcloud/services/igtm/data_source_tc_igtm_instance_list_test.go new file mode 100644 index 0000000000..870e89f24b --- /dev/null +++ b/tencentcloud/services/igtm/data_source_tc_igtm_instance_list_test.go @@ -0,0 +1,29 @@ +package igtm_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudIgtmInstanceListDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{{ + Config: testAccIgtmInstanceListDataSource, + Check: resource.ComposeTestCheckFunc( + tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_igtm_instance_list.example"), + ), + }}, + }) +} + +const testAccIgtmInstanceListDataSource = ` +data "tencentcloud_igtm_instance_list" "example" {} +` diff --git a/tencentcloud/services/igtm/data_source_tc_igtm_instance_package_list.go b/tencentcloud/services/igtm/data_source_tc_igtm_instance_package_list.go new file mode 100644 index 0000000000..ff49a3ca12 --- /dev/null +++ b/tencentcloud/services/igtm/data_source_tc_igtm_instance_package_list.go @@ -0,0 +1,317 @@ +package igtm + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + igtmv20231024 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm/v20231024" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func DataSourceTencentCloudIgtmInstancePackageList() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudIgtmInstancePackageListRead, + Schema: map[string]*schema.Schema{ + "filters": { + Type: schema.TypeList, + Optional: true, + Description: "Filter conditions.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "Filter field name, supported list as follows:\n- InstanceId: instance ID.\n- InstanceName: instance name.\n- ResourceId: package ID.\n- PackageType: package type. This is a required parameter, not passing it will cause interface query failure.", + }, + "value": { + Type: schema.TypeSet, + Required: true, + Description: "Filter field value.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "fuzzy": { + Type: schema.TypeBool, + Optional: true, + Description: "Whether to enable fuzzy query, only supports filter field name as domain.\nWhen fuzzy query is enabled, maximum Value length is 1, otherwise maximum Value length is 5. (Reserved field, not currently used).", + }, + }, + }, + }, + + "is_used": { + Type: schema.TypeInt, + Optional: true, + Description: "Whether used: 0 not used 1 used.", + }, + + "instance_set": { + Type: schema.TypeList, + Computed: true, + Description: "Instance package list.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "resource_id": { + Type: schema.TypeString, + Computed: true, + Description: "Instance package resource ID.", + }, + "instance_id": { + Type: schema.TypeString, + Computed: true, + Description: "Instance ID.", + }, + "instance_name": { + Type: schema.TypeString, + Computed: true, + Description: "Instance name.", + }, + "package_type": { + Type: schema.TypeString, + Computed: true, + Description: "Package type\nFREE: Free version\nSTANDARD: Standard version\nULTIMATE: Ultimate version.", + }, + "current_deadline": { + Type: schema.TypeString, + Computed: true, + Description: "Package expiration time.", + }, + "create_time": { + Type: schema.TypeString, + Computed: true, + Description: "Package creation time.", + }, + "is_expire": { + Type: schema.TypeInt, + Computed: true, + Description: "Whether expired 0 no 1 yes.", + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "Instance status\nENABLED: Normal\nDISABLED: Disabled.", + }, + "auto_renew_flag": { + Type: schema.TypeInt, + Computed: true, + Description: "Whether auto-renew 0 no 1 yes.", + }, + "remark": { + Type: schema.TypeString, + Computed: true, + Description: "Remark.", + }, + "cost_item_list": { + Type: schema.TypeList, + Computed: true, + Description: "Billing item.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "cost_name": { + Type: schema.TypeString, + Computed: true, + Description: "Billing item name.", + }, + "cost_value": { + Type: schema.TypeInt, + Computed: true, + Description: "Billing item value.", + }, + }, + }, + }, + "min_check_interval": { + Type: schema.TypeInt, + Computed: true, + Description: "Minimum check interval time s.", + }, + "min_global_ttl": { + Type: schema.TypeInt, + Computed: true, + Description: "Minimum TTL s.", + }, + "traffic_strategy": { + Type: schema.TypeSet, + Computed: true, + Description: "Traffic strategy type: ALL return all, WEIGHT weight.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "schedule_strategy": { + Type: schema.TypeSet, + Computed: true, + Description: "Strategy type: LOCATION schedule by geographic location, DELAY schedule by delay.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + }, + }, + + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudIgtmInstancePackageListRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("data_source.tencentcloud_igtm_instance_package_list.read")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(nil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + service = IgtmService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + ) + + paramMap := make(map[string]interface{}) + if v, ok := d.GetOk("filters"); ok { + filtersSet := v.([]interface{}) + tmpSet := make([]*igtmv20231024.ResourceFilter, 0, len(filtersSet)) + for _, item := range filtersSet { + filtersMap := item.(map[string]interface{}) + resourceFilter := igtmv20231024.ResourceFilter{} + if v, ok := filtersMap["name"].(string); ok && v != "" { + resourceFilter.Name = helper.String(v) + } + + if v, ok := filtersMap["value"]; ok { + valueSet := v.(*schema.Set).List() + for i := range valueSet { + value := valueSet[i].(string) + resourceFilter.Value = append(resourceFilter.Value, helper.String(value)) + } + } + + if v, ok := filtersMap["fuzzy"].(bool); ok { + resourceFilter.Fuzzy = helper.Bool(v) + } + + tmpSet = append(tmpSet, &resourceFilter) + } + + paramMap["Filters"] = tmpSet + } + + if v, ok := d.GetOkExists("is_used"); ok { + paramMap["IsUsed"] = helper.IntUint64(v.(int)) + } + + var respData []*igtmv20231024.InstancePackage + reqErr := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeIgtmInstancePackageListByFilter(ctx, paramMap) + if e != nil { + return tccommon.RetryError(e) + } + + respData = result + return nil + }) + + if reqErr != nil { + return reqErr + } + + instanceSetList := make([]map[string]interface{}, 0, len(respData)) + if respData != nil { + for _, instanceSet := range respData { + instanceSetMap := map[string]interface{}{} + if instanceSet.ResourceId != nil { + instanceSetMap["resource_id"] = instanceSet.ResourceId + } + + if instanceSet.InstanceId != nil { + instanceSetMap["instance_id"] = instanceSet.InstanceId + } + + if instanceSet.InstanceName != nil { + instanceSetMap["instance_name"] = instanceSet.InstanceName + } + + if instanceSet.PackageType != nil { + instanceSetMap["package_type"] = instanceSet.PackageType + } + + if instanceSet.CurrentDeadline != nil { + instanceSetMap["current_deadline"] = instanceSet.CurrentDeadline + } + + if instanceSet.CreateTime != nil { + instanceSetMap["create_time"] = instanceSet.CreateTime + } + + if instanceSet.IsExpire != nil { + instanceSetMap["is_expire"] = instanceSet.IsExpire + } + + if instanceSet.Status != nil { + instanceSetMap["status"] = instanceSet.Status + } + + if instanceSet.AutoRenewFlag != nil { + instanceSetMap["auto_renew_flag"] = instanceSet.AutoRenewFlag + } + + if instanceSet.Remark != nil { + instanceSetMap["remark"] = instanceSet.Remark + } + + costItemListList := make([]map[string]interface{}, 0, len(instanceSet.CostItemList)) + if instanceSet.CostItemList != nil { + for _, costItemList := range instanceSet.CostItemList { + costItemListMap := map[string]interface{}{} + if costItemList.CostName != nil { + costItemListMap["cost_name"] = costItemList.CostName + } + + if costItemList.CostValue != nil { + costItemListMap["cost_value"] = costItemList.CostValue + } + + costItemListList = append(costItemListList, costItemListMap) + } + + instanceSetMap["cost_item_list"] = costItemListList + } + + if instanceSet.MinCheckInterval != nil { + instanceSetMap["min_check_interval"] = instanceSet.MinCheckInterval + } + + if instanceSet.MinGlobalTtl != nil { + instanceSetMap["min_global_ttl"] = instanceSet.MinGlobalTtl + } + + if instanceSet.TrafficStrategy != nil { + instanceSetMap["traffic_strategy"] = instanceSet.TrafficStrategy + } + + if instanceSet.ScheduleStrategy != nil { + instanceSetMap["schedule_strategy"] = instanceSet.ScheduleStrategy + } + + instanceSetList = append(instanceSetList, instanceSetMap) + } + + _ = d.Set("instance_set", instanceSetList) + } + + d.SetId(helper.BuildToken()) + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := tccommon.WriteToFile(output.(string), instanceSetList); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/services/igtm/data_source_tc_igtm_instance_package_list.md b/tencentcloud/services/igtm/data_source_tc_igtm_instance_package_list.md new file mode 100644 index 0000000000..311e50dcbd --- /dev/null +++ b/tencentcloud/services/igtm/data_source_tc_igtm_instance_package_list.md @@ -0,0 +1,21 @@ +Use this data source to query detailed information of IGTM instance package list + +Example Usage + +Query all igtm instance package list + +```hcl +data "tencentcloud_igtm_instance_package_list" "example" {} +``` + +Query igtm instance package list by filter + +```hcl +data "tencentcloud_igtm_instance_package_list" "example" { + filters { + name = "InstanceId" + value = ["gtm-uukztqtoaru"] + fuzzy = true + } +} +``` diff --git a/tencentcloud/services/igtm/data_source_tc_igtm_instance_package_list_test.go b/tencentcloud/services/igtm/data_source_tc_igtm_instance_package_list_test.go new file mode 100644 index 0000000000..b9011d70c1 --- /dev/null +++ b/tencentcloud/services/igtm/data_source_tc_igtm_instance_package_list_test.go @@ -0,0 +1,29 @@ +package igtm_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudIgtmInstancePackageListDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{{ + Config: testAccIgtmInstancePackageListDataSource, + Check: resource.ComposeTestCheckFunc( + tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_igtm_instance_package_list.example"), + ), + }}, + }) +} + +const testAccIgtmInstancePackageListDataSource = ` +data "tencentcloud_igtm_instance_package_list" "example" {} +` diff --git a/tencentcloud/services/igtm/data_source_tc_igtm_monitors.go b/tencentcloud/services/igtm/data_source_tc_igtm_monitors.go new file mode 100644 index 0000000000..b6675c91c2 --- /dev/null +++ b/tencentcloud/services/igtm/data_source_tc_igtm_monitors.go @@ -0,0 +1,349 @@ +package igtm + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + igtmv20231024 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm/v20231024" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func DataSourceTencentCloudIgtmMonitors() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudIgtmMonitorsRead, + Schema: map[string]*schema.Schema{ + "filters": { + Type: schema.TypeList, + Optional: true, + Description: "Query filter conditions.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "Filter field name, supported MonitorName: monitor name; MonitorId: monitor ID.", + }, + "value": { + Type: schema.TypeSet, + Required: true, + Description: "Filter field values.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "fuzzy": { + Type: schema.TypeBool, + Optional: true, + Description: "Whether to enable fuzzy query, only supports filter field name as domain.\nWhen fuzzy query is enabled, Value maximum length is 1, otherwise Value maximum length is 5. (Reserved field, currently unused).", + }, + }, + }, + }, + + "is_detect_num": { + Type: schema.TypeInt, + Optional: true, + Description: "Whether to query detection count, 0 for no, 1 for yes.", + }, + + "monitor_data_set": { + Type: schema.TypeList, + Computed: true, + Description: "Monitor list.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "monitor_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Detection rule ID.", + }, + "monitor_name": { + Type: schema.TypeString, + Computed: true, + Description: "Monitor name.", + }, + "uin": { + Type: schema.TypeString, + Computed: true, + Description: "Owner user.", + }, + "detector_group_ids": { + Type: schema.TypeSet, + Computed: true, + Description: "Monitoring node ID group.", + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + "check_protocol": { + Type: schema.TypeString, + Computed: true, + Description: "Detection protocol PING TCP HTTP HTTPS.", + }, + "check_interval": { + Type: schema.TypeInt, + Computed: true, + Description: "Detection period.", + }, + "ping_num": { + Type: schema.TypeInt, + Computed: true, + Description: "Packet count.", + }, + "tcp_port": { + Type: schema.TypeInt, + Computed: true, + Description: "TCP port.", + }, + "host": { + Type: schema.TypeString, + Computed: true, + Description: "Detection host.", + }, + "path": { + Type: schema.TypeString, + Computed: true, + Description: "Detection path.", + }, + "return_code_threshold": { + Type: schema.TypeInt, + Computed: true, + Description: "Return value threshold.", + }, + "enable_redirect": { + Type: schema.TypeString, + Computed: true, + Description: "Whether to enable 3xx redirect following ENABLED DISABLED.", + }, + "enable_sni": { + Type: schema.TypeString, + Computed: true, + Description: "Whether to enable SNI.\nENABLED DISABLED.", + }, + "packet_loss_rate": { + Type: schema.TypeInt, + Computed: true, + Description: "Packet loss rate upper limit.", + }, + "timeout": { + Type: schema.TypeInt, + Computed: true, + Description: "Detection timeout.", + }, + "fail_times": { + Type: schema.TypeInt, + Computed: true, + Description: "Failure count.", + }, + "fail_rate": { + Type: schema.TypeInt, + Computed: true, + Description: "Failure rate upper limit 100.", + }, + "created_on": { + Type: schema.TypeString, + Computed: true, + Description: "Creation time.", + }, + "updated_on": { + Type: schema.TypeString, + Computed: true, + Description: "Update time.", + }, + "detector_style": { + Type: schema.TypeString, + Computed: true, + Description: "Monitoring node type.\nAUTO INTERNAL OVERSEAS IPV6 ALL.", + }, + "detect_num": { + Type: schema.TypeInt, + Computed: true, + Description: "Detection count.", + }, + "continue_period": { + Type: schema.TypeInt, + Computed: true, + Description: "Continuous period count.", + }, + }, + }, + }, + + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudIgtmMonitorsRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("data_source.tencentcloud_igtm_monitors.read")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(nil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + service = IgtmService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + ) + + paramMap := make(map[string]interface{}) + if v, ok := d.GetOk("filters"); ok { + filtersSet := v.([]interface{}) + tmpSet := make([]*igtmv20231024.ResourceFilter, 0, len(filtersSet)) + for _, item := range filtersSet { + filtersMap := item.(map[string]interface{}) + resourceFilter := igtmv20231024.ResourceFilter{} + if v, ok := filtersMap["name"].(string); ok && v != "" { + resourceFilter.Name = helper.String(v) + } + + if v, ok := filtersMap["value"]; ok { + valueSet := v.(*schema.Set).List() + for i := range valueSet { + value := valueSet[i].(string) + resourceFilter.Value = append(resourceFilter.Value, helper.String(value)) + } + } + + if v, ok := filtersMap["fuzzy"].(bool); ok { + resourceFilter.Fuzzy = helper.Bool(v) + } + + tmpSet = append(tmpSet, &resourceFilter) + } + + paramMap["Filters"] = tmpSet + } + + if v, ok := d.GetOkExists("is_detect_num"); ok { + paramMap["IsDetectNum"] = helper.IntUint64(v.(int)) + } + + var respData []*igtmv20231024.MonitorDetail + reqErr := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeIgtmMonitorsByFilter(ctx, paramMap) + if e != nil { + return tccommon.RetryError(e) + } + + respData = result + return nil + }) + + if reqErr != nil { + return reqErr + } + + monitorDataSetList := make([]map[string]interface{}, 0, len(respData)) + if respData != nil { + for _, monitorDataSet := range respData { + monitorDataSetMap := map[string]interface{}{} + if monitorDataSet.MonitorId != nil { + monitorDataSetMap["monitor_id"] = monitorDataSet.MonitorId + } + + if monitorDataSet.MonitorName != nil { + monitorDataSetMap["monitor_name"] = monitorDataSet.MonitorName + } + + if monitorDataSet.Uin != nil { + monitorDataSetMap["uin"] = monitorDataSet.Uin + } + + if monitorDataSet.DetectorGroupIds != nil { + monitorDataSetMap["detector_group_ids"] = monitorDataSet.DetectorGroupIds + } + + if monitorDataSet.CheckProtocol != nil { + monitorDataSetMap["check_protocol"] = monitorDataSet.CheckProtocol + } + + if monitorDataSet.CheckInterval != nil { + monitorDataSetMap["check_interval"] = monitorDataSet.CheckInterval + } + + if monitorDataSet.PingNum != nil { + monitorDataSetMap["ping_num"] = monitorDataSet.PingNum + } + + if monitorDataSet.TcpPort != nil { + monitorDataSetMap["tcp_port"] = monitorDataSet.TcpPort + } + + if monitorDataSet.Host != nil { + monitorDataSetMap["host"] = monitorDataSet.Host + } + + if monitorDataSet.Path != nil { + monitorDataSetMap["path"] = monitorDataSet.Path + } + + if monitorDataSet.ReturnCodeThreshold != nil { + monitorDataSetMap["return_code_threshold"] = monitorDataSet.ReturnCodeThreshold + } + + if monitorDataSet.EnableRedirect != nil { + monitorDataSetMap["enable_redirect"] = monitorDataSet.EnableRedirect + } + + if monitorDataSet.EnableSni != nil { + monitorDataSetMap["enable_sni"] = monitorDataSet.EnableSni + } + + if monitorDataSet.PacketLossRate != nil { + monitorDataSetMap["packet_loss_rate"] = monitorDataSet.PacketLossRate + } + + if monitorDataSet.Timeout != nil { + monitorDataSetMap["timeout"] = monitorDataSet.Timeout + } + + if monitorDataSet.FailTimes != nil { + monitorDataSetMap["fail_times"] = monitorDataSet.FailTimes + } + + if monitorDataSet.FailRate != nil { + monitorDataSetMap["fail_rate"] = monitorDataSet.FailRate + } + + if monitorDataSet.CreatedOn != nil { + monitorDataSetMap["created_on"] = monitorDataSet.CreatedOn + } + + if monitorDataSet.UpdatedOn != nil { + monitorDataSetMap["updated_on"] = monitorDataSet.UpdatedOn + } + + if monitorDataSet.DetectorStyle != nil { + monitorDataSetMap["detector_style"] = monitorDataSet.DetectorStyle + } + + if monitorDataSet.DetectNum != nil { + monitorDataSetMap["detect_num"] = monitorDataSet.DetectNum + } + + if monitorDataSet.ContinuePeriod != nil { + monitorDataSetMap["continue_period"] = monitorDataSet.ContinuePeriod + } + + monitorDataSetList = append(monitorDataSetList, monitorDataSetMap) + } + + _ = d.Set("monitor_data_set", monitorDataSetList) + } + + d.SetId(helper.BuildToken()) + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := tccommon.WriteToFile(output.(string), monitorDataSetList); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/services/igtm/data_source_tc_igtm_monitors.md b/tencentcloud/services/igtm/data_source_tc_igtm_monitors.md new file mode 100644 index 0000000000..0d7546548e --- /dev/null +++ b/tencentcloud/services/igtm/data_source_tc_igtm_monitors.md @@ -0,0 +1,21 @@ +Use this data source to query detailed information of IGTM monitors + +Example Usage + +Query all igtm monitors + +```hcl +data "tencentcloud_igtm_monitors" "example" {} +``` + +Query igtm monitors by filter + +```hcl +data "tencentcloud_igtm_monitors" "example" { + filters { + name = "MonitorId" + value = ["12383"] + fuzzy = true + } +} +``` diff --git a/tencentcloud/services/igtm/data_source_tc_igtm_monitors_test.go b/tencentcloud/services/igtm/data_source_tc_igtm_monitors_test.go new file mode 100644 index 0000000000..19e2cc97cd --- /dev/null +++ b/tencentcloud/services/igtm/data_source_tc_igtm_monitors_test.go @@ -0,0 +1,29 @@ +package igtm_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudIgtmMonitorsDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{{ + Config: testAccIgtmMonitorsDataSource, + Check: resource.ComposeTestCheckFunc( + tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_igtm_monitors.example"), + ), + }}, + }) +} + +const testAccIgtmMonitorsDataSource = ` +data "tencentcloud_igtm_monitors" "example" {} +` diff --git a/tencentcloud/services/igtm/data_source_tc_igtm_strategy_list.go b/tencentcloud/services/igtm/data_source_tc_igtm_strategy_list.go new file mode 100644 index 0000000000..b31c6b1734 --- /dev/null +++ b/tencentcloud/services/igtm/data_source_tc_igtm_strategy_list.go @@ -0,0 +1,313 @@ +package igtm + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + igtmv20231024 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm/v20231024" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func DataSourceTencentCloudIgtmStrategyList() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudIgtmStrategyListRead, + Schema: map[string]*schema.Schema{ + "instance_id": { + Type: schema.TypeString, + Required: true, + Description: "Instance ID.", + }, + + "filters": { + Type: schema.TypeList, + Optional: true, + Description: "Strategy filter conditions: StrategyName: strategy name.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "Filter field name, supported list as follows:\n- type: main resource type, CDN.\n- instanceId: IGTM instance ID. This is a required parameter, failure to pass will cause interface query failure.", + }, + "value": { + Type: schema.TypeSet, + Required: true, + Description: "Filter field values.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "fuzzy": { + Type: schema.TypeBool, + Optional: true, + Description: "Whether to enable fuzzy query, only supports filter field name as domain.\nWhen fuzzy query is enabled, Value maximum length is 1, otherwise Value maximum length is 5. (Reserved field, currently unused).", + }, + }, + }, + }, + + "strategy_set": { + Type: schema.TypeList, + Computed: true, + Description: "Strategy list.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "instance_id": { + Type: schema.TypeString, + Computed: true, + Description: "Instance ID.", + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "Strategy name.", + }, + "source": { + Type: schema.TypeList, + Computed: true, + Description: "Address source.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dns_line_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Resolution request source line ID.", + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: "Resolution request source line name.", + }, + }, + }, + }, + "strategy_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Strategy ID.", + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "Health status: ok healthy, warn risk, down failure.", + }, + "activate_main_pool_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Activated main pool ID, null means unknown.", + }, + "activate_level": { + Type: schema.TypeInt, + Computed: true, + Description: "Current activated address pool level, 0 means fallback activated, null means unknown.", + }, + "active_pool_type": { + Type: schema.TypeString, + Computed: true, + Description: "Current activated address pool set type: main main pool; fallback fallback pool.", + }, + "active_traffic_strategy": { + Type: schema.TypeString, + Computed: true, + Description: "Current activated address pool traffic strategy: all resolve all; weight load balancing.", + }, + "monitor_num": { + Type: schema.TypeInt, + Computed: true, + Description: "Monitor count.", + }, + "is_enabled": { + Type: schema.TypeString, + Computed: true, + Description: "Whether enabled: ENABLED enabled; DISABLED disabled.", + }, + "keep_domain_records": { + Type: schema.TypeString, + Computed: true, + Description: "Whether to retain lines: enabled retain, disabled not retain, only retain default lines.", + }, + "switch_pool_type": { + Type: schema.TypeString, + Computed: true, + Description: "Scheduling mode: AUTO default; PAUSE only pause without switching.", + }, + "created_on": { + Type: schema.TypeString, + Computed: true, + Description: "Creation time.", + }, + "updated_on": { + Type: schema.TypeString, + Computed: true, + Description: "Update time.", + }, + }, + }, + }, + + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudIgtmStrategyListRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("data_source.tencentcloud_igtm_strategy_list.read")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(nil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + service = IgtmService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + instanceId string + ) + + paramMap := make(map[string]interface{}) + if v, ok := d.GetOk("instance_id"); ok { + paramMap["InstanceId"] = helper.String(v.(string)) + instanceId = v.(string) + } + + if v, ok := d.GetOk("filters"); ok { + filtersSet := v.([]interface{}) + tmpSet := make([]*igtmv20231024.ResourceFilter, 0, len(filtersSet)) + for _, item := range filtersSet { + filtersMap := item.(map[string]interface{}) + resourceFilter := igtmv20231024.ResourceFilter{} + if v, ok := filtersMap["name"].(string); ok && v != "" { + resourceFilter.Name = helper.String(v) + } + + if v, ok := filtersMap["value"]; ok { + valueSet := v.(*schema.Set).List() + for i := range valueSet { + value := valueSet[i].(string) + resourceFilter.Value = append(resourceFilter.Value, helper.String(value)) + } + } + + if v, ok := filtersMap["fuzzy"].(bool); ok { + resourceFilter.Fuzzy = helper.Bool(v) + } + + tmpSet = append(tmpSet, &resourceFilter) + } + + paramMap["Filters"] = tmpSet + } + + var respData []*igtmv20231024.Strategy + reqErr := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeIgtmStrategyListByFilter(ctx, paramMap) + if e != nil { + return tccommon.RetryError(e) + } + + respData = result + return nil + }) + + if reqErr != nil { + return reqErr + } + + strategySetList := make([]map[string]interface{}, 0, len(respData)) + if respData != nil { + for _, strategySet := range respData { + strategySetMap := map[string]interface{}{} + if strategySet.InstanceId != nil { + strategySetMap["instance_id"] = strategySet.InstanceId + } + + if strategySet.Name != nil { + strategySetMap["name"] = strategySet.Name + } + + sourceList := make([]map[string]interface{}, 0, len(strategySet.Source)) + if strategySet.Source != nil { + for _, source := range strategySet.Source { + sourceMap := map[string]interface{}{} + if source.DnsLineId != nil { + sourceMap["dns_line_id"] = source.DnsLineId + } + + if source.Name != nil { + sourceMap["name"] = source.Name + } + + sourceList = append(sourceList, sourceMap) + } + + strategySetMap["source"] = sourceList + } + + if strategySet.StrategyId != nil { + strategySetMap["strategy_id"] = strategySet.StrategyId + } + + if strategySet.Status != nil { + strategySetMap["status"] = strategySet.Status + } + + if strategySet.ActivateMainPoolId != nil { + strategySetMap["activate_main_pool_id"] = strategySet.ActivateMainPoolId + } + + if strategySet.ActivateLevel != nil { + strategySetMap["activate_level"] = strategySet.ActivateLevel + } + + if strategySet.ActivePoolType != nil { + strategySetMap["active_pool_type"] = strategySet.ActivePoolType + } + + if strategySet.ActiveTrafficStrategy != nil { + strategySetMap["active_traffic_strategy"] = strategySet.ActiveTrafficStrategy + } + + if strategySet.MonitorNum != nil { + strategySetMap["monitor_num"] = strategySet.MonitorNum + } + + if strategySet.IsEnabled != nil { + strategySetMap["is_enabled"] = strategySet.IsEnabled + } + + if strategySet.KeepDomainRecords != nil { + strategySetMap["keep_domain_records"] = strategySet.KeepDomainRecords + } + + if strategySet.SwitchPoolType != nil { + strategySetMap["switch_pool_type"] = strategySet.SwitchPoolType + } + + if strategySet.CreatedOn != nil { + strategySetMap["created_on"] = strategySet.CreatedOn + } + + if strategySet.UpdatedOn != nil { + strategySetMap["updated_on"] = strategySet.UpdatedOn + } + + strategySetList = append(strategySetList, strategySetMap) + } + + _ = d.Set("strategy_set", strategySetList) + } + + d.SetId(instanceId) + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := tccommon.WriteToFile(output.(string), strategySetList); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/services/igtm/data_source_tc_igtm_strategy_list.md b/tencentcloud/services/igtm/data_source_tc_igtm_strategy_list.md new file mode 100644 index 0000000000..2099f5868e --- /dev/null +++ b/tencentcloud/services/igtm/data_source_tc_igtm_strategy_list.md @@ -0,0 +1,14 @@ +Use this data source to query detailed information of IGTM strategy list + +Example Usage + +```hcl +data "tencentcloud_igtm_strategy_list" "example" { + instance_id = "gtm-uukztqtoaru" + filters { + name = "StrategyName" + value = ["tf-example"] + fuzzy = true + } +} +``` diff --git a/tencentcloud/services/igtm/data_source_tc_igtm_strategy_list_test.go b/tencentcloud/services/igtm/data_source_tc_igtm_strategy_list_test.go new file mode 100644 index 0000000000..1771a44526 --- /dev/null +++ b/tencentcloud/services/igtm/data_source_tc_igtm_strategy_list_test.go @@ -0,0 +1,31 @@ +package igtm_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudIgtmStrategyListDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{{ + Config: testAccIgtmStrategyListDataSource, + Check: resource.ComposeTestCheckFunc( + tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_igtm_strategy_list.example"), + ), + }}, + }) +} + +const testAccIgtmStrategyListDataSource = ` +data "tencentcloud_igtm_strategy_list" "example" { + instance_id = "gtm-uukztqtoaru" +} +` diff --git a/tencentcloud/services/igtm/resource_tc_igtm_address_pool.go b/tencentcloud/services/igtm/resource_tc_igtm_address_pool.go index 2a4bd253df..286cf3b38a 100644 --- a/tencentcloud/services/igtm/resource_tc_igtm_address_pool.go +++ b/tencentcloud/services/igtm/resource_tc_igtm_address_pool.go @@ -133,18 +133,10 @@ func resourceTencentCloudIgtmAddressPoolCreate(d *schema.ResourceData, meta inte address.IsEnable = helper.String(v) } - if v, ok := addressSetMap["address_id"].(int); ok { - address.AddressId = helper.IntUint64(v) - } - if v, ok := addressSetMap["location"].(string); ok && v != "" { address.Location = helper.String(v) } - if v, ok := addressSetMap["status"].(string); ok && v != "" { - address.Status = helper.String(v) - } - if v, ok := addressSetMap["weight"].(int); ok { address.Weight = helper.IntUint64(v) } @@ -325,10 +317,6 @@ func resourceTencentCloudIgtmAddressPoolUpdate(d *schema.ResourceData, meta inte address.Location = helper.String(v) } - if v, ok := addressSetMap["status"].(string); ok && v != "" { - address.Status = helper.String(v) - } - if v, ok := addressSetMap["weight"].(int); ok { address.Weight = helper.IntUint64(v) } diff --git a/tencentcloud/services/igtm/resource_tc_igtm_address_pool.md b/tencentcloud/services/igtm/resource_tc_igtm_address_pool.md index 24b22419c0..1c7341694d 100644 --- a/tencentcloud/services/igtm/resource_tc_igtm_address_pool.md +++ b/tencentcloud/services/igtm/resource_tc_igtm_address_pool.md @@ -1,5 +1,7 @@ Provides a resource to create a IGTM address pool +~> **NOTE:** Resource `tencentcloud_igtm_instance` needs to be created before using this resource. + Example Usage ```hcl diff --git a/tencentcloud/services/igtm/resource_tc_igtm_instance.go b/tencentcloud/services/igtm/resource_tc_igtm_instance.go new file mode 100644 index 0000000000..4a1b4b6fde --- /dev/null +++ b/tencentcloud/services/igtm/resource_tc_igtm_instance.go @@ -0,0 +1,312 @@ +package igtm + +import ( + "context" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + igtmv20231024 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm/v20231024" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func ResourceTencentCloudIgtmInstance() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudIgtmInstanceCreate, + Read: resourceTencentCloudIgtmInstanceRead, + Update: resourceTencentCloudIgtmInstanceUpdate, + Delete: resourceTencentCloudIgtmInstanceDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "domain": { + Type: schema.TypeString, + Required: true, + Description: "Business domain.", + }, + + "access_type": { + Type: schema.TypeString, + Required: true, + Description: "CUSTOM: Custom access domain\nSYSTEM: System access domain.", + }, + + "global_ttl": { + Type: schema.TypeInt, + Required: true, + Description: "Resolution effective time.", + }, + + "package_type": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Package type\nFREE: Free version\nSTANDARD: Standard version\nULTIMATE: Ultimate version.", + }, + + "instance_name": { + Type: schema.TypeString, + Required: true, + Description: "Instance name.", + }, + + "access_domain": { + Type: schema.TypeString, + Required: true, + Description: "Access main domain.", + }, + + "access_sub_domain": { + Type: schema.TypeString, + Required: true, + Description: "Access subdomain.", + }, + + "remark": { + Type: schema.TypeString, + Optional: true, + Description: "Remark.", + }, + + "resource_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Package resource ID.", + }, + + // computed + "instance_id": { + Type: schema.TypeString, + Computed: true, + Description: "Instance ID.", + }, + }, + } +} + +func resourceTencentCloudIgtmInstanceCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_igtm_instance.create")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + request = igtmv20231024.NewCreateInstanceRequest() + response = igtmv20231024.NewCreateInstanceResponse() + instanceId string + ) + + if v, ok := d.GetOk("domain"); ok { + request.Domain = helper.String(v.(string)) + } + + if v, ok := d.GetOk("access_type"); ok { + request.AccessType = helper.String(v.(string)) + } + + if v, ok := d.GetOkExists("global_ttl"); ok { + request.GlobalTtl = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOk("package_type"); ok { + request.PackageType = helper.String(v.(string)) + } + + if v, ok := d.GetOk("instance_name"); ok { + request.InstanceName = helper.String(v.(string)) + } + + if v, ok := d.GetOk("access_domain"); ok { + request.AccessDomain = helper.String(v.(string)) + } + + if v, ok := d.GetOk("access_sub_domain"); ok { + request.AccessSubDomain = helper.String(v.(string)) + } + + if v, ok := d.GetOk("remark"); ok { + request.Remark = helper.String(v.(string)) + } + + if v, ok := d.GetOk("resource_id"); ok { + request.ResourceId = helper.String(v.(string)) + } + + reqErr := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseIgtmV20231024Client().CreateInstanceWithContext(ctx, request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + if result == nil || result.Response == nil { + return resource.NonRetryableError(fmt.Errorf("Create igtm instance failed, Response is nil.")) + } + + response = result + return nil + }) + + if reqErr != nil { + log.Printf("[CRITAL]%s create igtm instance failed, reason:%+v", logId, reqErr) + return reqErr + } + + if response.Response.InstanceId == nil { + return fmt.Errorf("InstanceId is nil.") + } + + instanceId = *response.Response.InstanceId + d.SetId(instanceId) + return resourceTencentCloudIgtmInstanceRead(d, meta) +} + +func resourceTencentCloudIgtmInstanceRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_igtm_instance.read")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + service = IgtmService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + instanceId = d.Id() + ) + + respData, err := service.DescribeIgtmInstanceById(ctx, instanceId) + if err != nil { + return err + } + + if respData == nil { + log.Printf("[WARN]%s resource `tencentcloud_igtm_instance` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + d.SetId("") + return nil + } + + if respData.Domain != nil { + _ = d.Set("domain", respData.Domain) + } + + if respData.AccessType != nil { + _ = d.Set("access_type", respData.AccessType) + } + + if respData.GlobalTtl != nil { + _ = d.Set("global_ttl", respData.GlobalTtl) + } + + if respData.PackageType != nil { + _ = d.Set("package_type", respData.PackageType) + } + + if respData.InstanceName != nil { + _ = d.Set("instance_name", respData.InstanceName) + } + + if respData.AccessDomain != nil { + _ = d.Set("access_domain", respData.AccessDomain) + } + + if respData.AccessSubDomain != nil { + _ = d.Set("access_sub_domain", respData.AccessSubDomain) + } + + if respData.Remark != nil { + _ = d.Set("remark", respData.Remark) + } + + if respData.ResourceId != nil { + _ = d.Set("resource_id", respData.ResourceId) + } + + if respData.InstanceId != nil { + _ = d.Set("instance_id", respData.InstanceId) + } + + return nil +} + +func resourceTencentCloudIgtmInstanceUpdate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_igtm_instance.update")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + instanceId = d.Id() + ) + + needChange := false + mutableArgs := []string{"domain", "access_type", "global_ttl", "instance_name", "access_domain", "access_sub_domain", "remark"} + for _, v := range mutableArgs { + if d.HasChange(v) { + needChange = true + break + } + } + + if needChange { + request := igtmv20231024.NewModifyInstanceConfigRequest() + instanceConfig := igtmv20231024.InstanceConfig{} + if v, ok := d.GetOk("domain"); ok && v.(string) != "" { + instanceConfig.Domain = helper.String(v.(string)) + } + + if v, ok := d.GetOk("access_type"); ok && v.(string) != "" { + instanceConfig.AccessType = helper.String(v.(string)) + } + + if v, ok := d.GetOkExists("global_ttl"); ok { + instanceConfig.GlobalTtl = helper.IntInt64(v.(int)) + } + + if v, ok := d.GetOk("instance_name"); ok && v.(string) != "" { + instanceConfig.InstanceName = helper.String(v.(string)) + } + + if v, ok := d.GetOk("access_domain"); ok && v.(string) != "" { + instanceConfig.AccessDomain = helper.String(v.(string)) + } + + if v, ok := d.GetOk("access_sub_domain"); ok && v.(string) != "" { + instanceConfig.AccessSubDomain = helper.String(v.(string)) + } + + if v, ok := d.GetOk("remark"); ok && v.(string) != "" { + instanceConfig.Remark = helper.String(v.(string)) + } + + request.InstanceConfig = &instanceConfig + request.InstanceId = &instanceId + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseIgtmV20231024Client().ModifyInstanceConfigWithContext(ctx, request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s modify igtm instance config failed, reason:%+v", logId, err) + return err + } + } + + return resourceTencentCloudIgtmInstanceRead(d, meta) +} + +func resourceTencentCloudIgtmInstanceDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_igtm_instance.delete")() + defer tccommon.InconsistentCheck(d, meta)() + + return fmt.Errorf("tencentcloud igtm instance not supported delete, please contact the work order for processing") +} diff --git a/tencentcloud/services/igtm/resource_tc_igtm_instance.md b/tencentcloud/services/igtm/resource_tc_igtm_instance.md new file mode 100644 index 0000000000..fdf42ac407 --- /dev/null +++ b/tencentcloud/services/igtm/resource_tc_igtm_instance.md @@ -0,0 +1,27 @@ +Provides a resource to create a IGTM instance + +~> **NOTE:** Currently, executing the `terraform destroy` command to delete this resource is not supported. If you need to destroy it, please contact Tencent Cloud IGTM through a ticket. + +Example Usage + +```hcl +resource "tencentcloud_igtm_instance" "example" { + domain = "domain.com" + access_type = "CUSTOM" + global_ttl = 60 + package_type = "STANDARD" + instance_name = "tf-example" + access_domain = "domain.com" + access_sub_domain = "sub_domain.com" + remark = "remark." + resource_id = "ins-lnpnnwvwxgs" +} +``` + +Import + +IGTM instance can be imported using the id, e.g. + +``` +terraform import tencentcloud_igtm_instance.example gtm-uukztqtoaru +``` diff --git a/tencentcloud/services/igtm/resource_tc_igtm_instance_test.go b/tencentcloud/services/igtm/resource_tc_igtm_instance_test.go new file mode 100644 index 0000000000..6b7d883d3f --- /dev/null +++ b/tencentcloud/services/igtm/resource_tc_igtm_instance_test.go @@ -0,0 +1,84 @@ +package igtm_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudIgtmInstanceResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{ + { + Config: testAccIgtmInstance, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_igtm_instance.example", "id"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_instance.example", "domain"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_instance.example", "access_type"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_instance.example", "global_ttl"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_instance.example", "package_type"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_instance.example", "instance_name"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_instance.example", "access_domain"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_instance.example", "access_sub_domain"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_instance.example", "remark"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_instance.example", "resource_id"), + ), + }, + { + Config: testAccIgtmInstanceUpdate, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_igtm_instance.example", "id"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_instance.example", "domain"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_instance.example", "access_type"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_instance.example", "global_ttl"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_instance.example", "package_type"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_instance.example", "instance_name"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_instance.example", "access_domain"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_instance.example", "access_sub_domain"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_instance.example", "remark"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_instance.example", "resource_id"), + ), + }, + { + ResourceName: "tencentcloud_igtm_instance.example", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccIgtmInstance = ` +resource "tencentcloud_igtm_instance" "example" { + domain = "xtermpro.com" + access_type = "CUSTOM" + global_ttl = 60 + package_type = "STANDARD" + instance_name = "tf-example" + access_domain = "xtermpro.com" + access_sub_domain = "demo.com" + remark = "remark." + resource_id = "ins-lnpnnwvwqmr" +} +` + +const testAccIgtmInstanceUpdate = ` +resource "tencentcloud_igtm_instance" "example" { + domain = "xtermpro.com" + access_type = "CUSTOM" + global_ttl = 80 + package_type = "STANDARD" + instance_name = "tf-example-update" + access_domain = "xtermpro.com" + access_sub_domain = "demo.com" + remark = "remark update." + resource_id = "ins-lnpnnwvwqmr" +} +` diff --git a/tencentcloud/services/igtm/resource_tc_igtm_monitor.go b/tencentcloud/services/igtm/resource_tc_igtm_monitor.go new file mode 100644 index 0000000000..95d0b36a99 --- /dev/null +++ b/tencentcloud/services/igtm/resource_tc_igtm_monitor.go @@ -0,0 +1,519 @@ +package igtm + +import ( + "context" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + igtmv20231024 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm/v20231024" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func ResourceTencentCloudIgtmMonitor() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudIgtmMonitorCreate, + Read: resourceTencentCloudIgtmMonitorRead, + Update: resourceTencentCloudIgtmMonitorUpdate, + Delete: resourceTencentCloudIgtmMonitorDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "monitor_name": { + Type: schema.TypeString, + Required: true, + Description: "Monitor name.", + }, + + "check_protocol": { + Type: schema.TypeString, + Required: true, + Description: "Detection protocol, optional values `PING`, `TCP`, `HTTP`, `HTTPS`.", + }, + + "check_interval": { + Type: schema.TypeInt, + Required: true, + Description: "Check interval (seconds), optional values 15 60 120 300.", + }, + + "timeout": { + Type: schema.TypeInt, + Required: true, + Description: "Timeout time, unit seconds, optional values 2 3 5 10.", + }, + + "fail_times": { + Type: schema.TypeInt, + Required: true, + Description: "Retry count, optional values 0, 1, 2.", + }, + + "fail_rate": { + Type: schema.TypeInt, + Required: true, + Description: "Failure rate, values 20 30 40 50 60 70 80 100, default value 50.", + }, + + "detector_style": { + Type: schema.TypeString, + Required: true, + Description: "Monitoring node type, optional values AUTO INTERNAL OVERSEAS IPV6 ALL.", + }, + + "detector_group_ids": { + Type: schema.TypeSet, + Required: true, + Description: "Detector group ID list separated by commas.", + Elem: &schema.Schema{ + Type: schema.TypeInt, + }, + }, + + "ping_num": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "PING packet count, required when CheckProtocol=ping, optional values 20 50 100.", + }, + + "tcp_port": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Check port, optional values between 1-65535.", + }, + + "host": { + Type: schema.TypeString, + Optional: true, + Description: "Host setting, default is business domain name.", + }, + + "path": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "URL path, default is \"/\".", + }, + + "return_code_threshold": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Return error code threshold, optional values 400 and 500, default value 500.", + }, + + "enable_redirect": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Follow 3XX redirect, DISABLED for disabled, ENABLED for enabled, default disabled.", + }, + + "enable_sni": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Enable SNI, DISABLED for disabled, ENABLED for enabled, default disabled.", + }, + + "packet_loss_rate": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Packet loss rate alarm threshold, required when CheckProtocol=ping, values 10 30 50 80 90 100.", + }, + + "continue_period": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Continuous period count, optional values 1-5.", + }, + + // computed + "monitor_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Monitor ID.", + }, + }, + } +} + +func resourceTencentCloudIgtmMonitorCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_igtm_monitor.create")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + request = igtmv20231024.NewCreateMonitorRequest() + response = igtmv20231024.NewCreateMonitorResponse() + monitorId string + ) + + if v, ok := d.GetOk("monitor_name"); ok { + request.MonitorName = helper.String(v.(string)) + } + + if v, ok := d.GetOk("check_protocol"); ok { + request.CheckProtocol = helper.String(v.(string)) + } + + if v, ok := d.GetOkExists("check_interval"); ok { + request.CheckInterval = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOkExists("timeout"); ok { + request.Timeout = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOkExists("fail_times"); ok { + request.FailTimes = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOkExists("fail_rate"); ok { + request.FailRate = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOk("detector_style"); ok { + request.DetectorStyle = helper.String(v.(string)) + } + + if v, ok := d.GetOk("detector_group_ids"); ok { + detectorGroupIdsSet := v.(*schema.Set).List() + for i := range detectorGroupIdsSet { + detectorGroupIds := detectorGroupIdsSet[i].(int) + request.DetectorGroupIds = append(request.DetectorGroupIds, helper.IntUint64(detectorGroupIds)) + } + } + + if v, ok := d.GetOkExists("ping_num"); ok { + request.PingNum = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOkExists("tcp_port"); ok { + request.TcpPort = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOk("host"); ok { + request.Host = helper.String(v.(string)) + } + + if v, ok := d.GetOk("path"); ok { + request.Path = helper.String(v.(string)) + } + + if v, ok := d.GetOkExists("return_code_threshold"); ok { + request.ReturnCodeThreshold = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOk("enable_redirect"); ok { + request.EnableRedirect = helper.String(v.(string)) + } + + if v, ok := d.GetOk("enable_sni"); ok { + request.EnableSni = helper.String(v.(string)) + } + + if v, ok := d.GetOkExists("packet_loss_rate"); ok { + request.PacketLossRate = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOkExists("continue_period"); ok { + request.ContinuePeriod = helper.IntUint64(v.(int)) + } + + reqErr := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseIgtmV20231024Client().CreateMonitorWithContext(ctx, request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + if result == nil || result.Response == nil { + return resource.NonRetryableError(fmt.Errorf("Create igtm monitor failed, Response is nil.")) + } + + response = result + return nil + }) + + if reqErr != nil { + log.Printf("[CRITAL]%s create igtm monitor failed, reason:%+v", logId, reqErr) + return reqErr + } + + if response.Response.MonitorId == nil { + return fmt.Errorf("MonitorId is nil.") + } + + monitorId = helper.UInt64ToStr(*response.Response.MonitorId) + d.SetId(monitorId) + return resourceTencentCloudIgtmMonitorRead(d, meta) +} + +func resourceTencentCloudIgtmMonitorRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_igtm_monitor.read")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + service = IgtmService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + monitorId = d.Id() + ) + + respData, err := service.DescribeIgtmMonitorById(ctx, monitorId) + if err != nil { + return err + } + + if respData == nil { + log.Printf("[WARN]%s resource `tencentcloud_igtm_monitor` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + d.SetId("") + return nil + } + + if respData.MonitorName != nil { + _ = d.Set("monitor_name", respData.MonitorName) + } + + if respData.CheckProtocol != nil { + _ = d.Set("check_protocol", respData.CheckProtocol) + } + + if respData.CheckInterval != nil { + _ = d.Set("check_interval", respData.CheckInterval) + } + + if respData.Timeout != nil { + _ = d.Set("timeout", respData.Timeout) + } + + if respData.FailTimes != nil { + _ = d.Set("fail_times", respData.FailTimes) + } + + if respData.FailRate != nil { + _ = d.Set("fail_rate", respData.FailRate) + } + + if respData.DetectorStyle != nil { + _ = d.Set("detector_style", respData.DetectorStyle) + } + + if respData.DetectorGroupIds != nil { + _ = d.Set("detector_group_ids", respData.DetectorGroupIds) + } + + if respData.PingNum != nil { + _ = d.Set("ping_num", respData.PingNum) + } + + if respData.TcpPort != nil { + _ = d.Set("tcp_port", respData.TcpPort) + } + + if respData.Host != nil { + _ = d.Set("host", respData.Host) + } + + if respData.Path != nil { + _ = d.Set("path", respData.Path) + } + + if respData.ReturnCodeThreshold != nil { + _ = d.Set("return_code_threshold", respData.ReturnCodeThreshold) + } + + if respData.EnableRedirect != nil { + _ = d.Set("enable_redirect", respData.EnableRedirect) + } + + if respData.EnableSni != nil { + _ = d.Set("enable_sni", respData.EnableSni) + } + + if respData.PacketLossRate != nil { + _ = d.Set("packet_loss_rate", respData.PacketLossRate) + } + + if respData.ContinuePeriod != nil { + _ = d.Set("continue_period", respData.ContinuePeriod) + } + + if respData.MonitorId != nil { + _ = d.Set("monitor_id", respData.MonitorId) + } + + return nil +} + +func resourceTencentCloudIgtmMonitorUpdate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_igtm_monitor.update")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + monitorId = d.Id() + ) + + needChange := false + mutableArgs := []string{"monitor_name", "check_protocol", "check_interval", "timeout", "fail_times", "fail_rate", "detector_style", "detector_group_ids", "ping_num", "tcp_port", "host", "path", "return_code_threshold", "enable_redirect", "enable_sni", "packet_loss_rate", "continue_period"} + for _, v := range mutableArgs { + if d.HasChange(v) { + needChange = true + break + } + } + + if needChange { + request := igtmv20231024.NewModifyMonitorRequest() + if v, ok := d.GetOk("monitor_name"); ok { + request.MonitorName = helper.String(v.(string)) + } + + if v, ok := d.GetOk("check_protocol"); ok { + request.CheckProtocol = helper.String(v.(string)) + } + + if v, ok := d.GetOkExists("check_interval"); ok { + request.CheckInterval = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOkExists("timeout"); ok { + request.Timeout = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOkExists("fail_times"); ok { + request.FailTimes = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOkExists("fail_rate"); ok { + request.FailRate = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOk("detector_style"); ok { + request.DetectorStyle = helper.String(v.(string)) + } + + if v, ok := d.GetOk("detector_group_ids"); ok { + detectorGroupIdsSet := v.(*schema.Set).List() + for i := range detectorGroupIdsSet { + detectorGroupIds := detectorGroupIdsSet[i].(int) + request.DetectorGroupIds = append(request.DetectorGroupIds, helper.IntUint64(detectorGroupIds)) + } + } + + if v, ok := d.GetOkExists("ping_num"); ok { + request.PingNum = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOkExists("tcp_port"); ok { + request.TcpPort = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOk("host"); ok { + request.Host = helper.String(v.(string)) + } + + if v, ok := d.GetOk("path"); ok { + request.Path = helper.String(v.(string)) + } + + if v, ok := d.GetOkExists("return_code_threshold"); ok { + request.ReturnCodeThreshold = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOk("enable_redirect"); ok { + request.EnableRedirect = helper.String(v.(string)) + } + + if v, ok := d.GetOk("enable_sni"); ok { + request.EnableSni = helper.String(v.(string)) + } + + if v, ok := d.GetOkExists("packet_loss_rate"); ok { + request.PacketLossRate = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOkExists("continue_period"); ok { + request.ContinuePeriod = helper.IntUint64(v.(int)) + } + + request.MonitorId = helper.StrToUint64Point(monitorId) + reqErr := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseIgtmV20231024Client().ModifyMonitorWithContext(ctx, request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + if result == nil || result.Response == nil || result.Response.Msg == nil { + return resource.NonRetryableError(fmt.Errorf("Modify igtm monitor failed, Response is nil.")) + } + + if *result.Response.Msg == "success" { + return nil + } else { + return resource.NonRetryableError(fmt.Errorf("Modify igtm monitor failed, Msg is %s.", *result.Response.Msg)) + } + }) + + if reqErr != nil { + log.Printf("[CRITAL]%s update igtm monitor failed, reason:%+v", logId, reqErr) + return reqErr + } + } + + return resourceTencentCloudIgtmMonitorRead(d, meta) +} + +func resourceTencentCloudIgtmMonitorDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_igtm_monitor.delete")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + request = igtmv20231024.NewDeleteMonitorRequest() + monitorId = d.Id() + ) + + request.MonitorId = helper.StrToUint64Point(monitorId) + reqErr := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseIgtmV20231024Client().DeleteMonitorWithContext(ctx, request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + if result == nil || result.Response == nil || result.Response.Msg == nil { + return resource.NonRetryableError(fmt.Errorf("Delete igtm monitor failed, Response is nil.")) + } + + if *result.Response.Msg == "success" { + return nil + } else { + return resource.NonRetryableError(fmt.Errorf("Delete igtm monitor failed, Msg is %s.", *result.Response.Msg)) + } + }) + + if reqErr != nil { + log.Printf("[CRITAL]%s delete igtm monitor failed, reason:%+v", logId, reqErr) + return reqErr + } + + return nil +} diff --git a/tencentcloud/services/igtm/resource_tc_igtm_monitor.md b/tencentcloud/services/igtm/resource_tc_igtm_monitor.md new file mode 100644 index 0000000000..8fdb38f7df --- /dev/null +++ b/tencentcloud/services/igtm/resource_tc_igtm_monitor.md @@ -0,0 +1,32 @@ +Provides a resource to create a IGTM monitor + +Example Usage + +```hcl +resource "tencentcloud_igtm_monitor" "example" { + monitor_name = "tf-example" + check_protocol = "PING" + check_interval = 60 + timeout = 5 + fail_times = 1 + fail_rate = 50 + detector_style = "INTERNAL" + detector_group_ids = [30, 31, 32, 34, 37, 38, 39, 1, 2, 3, 7, 8, 9, 10, 11, 12] + ping_num = 20 + tcp_port = 443 + path = "/" + return_code_threshold = 500 + enable_redirect = "DISABLED" + enable_sni = "DISABLED" + packet_loss_rate = 90 + continue_period = 1 +} +``` + +Import + +IGTM monitor can be imported using the id, e.g. + +``` +terraform import tencentcloud_igtm_monitor.example 12355 +``` diff --git a/tencentcloud/services/igtm/resource_tc_igtm_monitor_test.go b/tencentcloud/services/igtm/resource_tc_igtm_monitor_test.go new file mode 100644 index 0000000000..4c7a88d431 --- /dev/null +++ b/tencentcloud/services/igtm/resource_tc_igtm_monitor_test.go @@ -0,0 +1,96 @@ +package igtm_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudIgtmMonitorResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{ + { + Config: testAccIgtmMonitor, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_igtm_monitor.example", "id"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_monitor.example", "monitor_name"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_monitor.example", "check_protocol"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_monitor.example", "check_interval"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_monitor.example", "timeout"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_monitor.example", "fail_times"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_monitor.example", "fail_rate"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_monitor.example", "detector_style"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_monitor.example", "detector_group_ids"), + ), + }, + { + Config: testAccIgtmMonitorUpdate, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_igtm_monitor.example", "id"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_monitor.example", "monitor_name"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_monitor.example", "check_protocol"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_monitor.example", "check_interval"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_monitor.example", "timeout"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_monitor.example", "fail_times"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_monitor.example", "fail_rate"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_monitor.example", "detector_style"), + resource.TestCheckResourceAttrSet("tencentcloud_igtm_monitor.example", "detector_group_ids"), + ), + }, + { + ResourceName: "tencentcloud_igtm_monitor.example", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccIgtmMonitor = ` +resource "tencentcloud_igtm_monitor" "example" { + monitor_name = "tf-example" + check_protocol = "PING" + check_interval = 60 + timeout = 5 + fail_times = 1 + fail_rate = 50 + detector_style = "INTERNAL" + detector_group_ids = [30, 31, 32, 34, 37, 38, 39, 1, 2, 3, 7, 8, 9, 10, 11, 12] + ping_num = 20 + tcp_port = 443 + path = "/" + return_code_threshold = 500 + enable_redirect = "DISABLED" + enable_sni = "DISABLED" + packet_loss_rate = 90 + continue_period = 1 +} +` + +const testAccIgtmMonitorUpdate = ` +resource "tencentcloud_igtm_monitor" "example" { + monitor_name = "tf-example-update" + check_protocol = "PING" + check_interval = 60 + timeout = 10 + fail_times = 1 + fail_rate = 50 + detector_style = "INTERNAL" + detector_group_ids = [30, 31, 32, 34, 37, 38, 39, 1, 2, 3, 7, 8, 9, 10, 11, 12] + ping_num = 20 + tcp_port = 443 + path = "/" + return_code_threshold = 500 + enable_redirect = "DISABLED" + enable_sni = "DISABLED" + packet_loss_rate = 90 + continue_period = 1 +} +` diff --git a/tencentcloud/services/igtm/resource_tc_igtm_strategy.go b/tencentcloud/services/igtm/resource_tc_igtm_strategy.go new file mode 100644 index 0000000000..fa3852c235 --- /dev/null +++ b/tencentcloud/services/igtm/resource_tc_igtm_strategy.go @@ -0,0 +1,680 @@ +package igtm + +import ( + "context" + "fmt" + "log" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + igtmv20231024 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm/v20231024" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func ResourceTencentCloudIgtmStrategy() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudIgtmStrategyCreate, + Read: resourceTencentCloudIgtmStrategyRead, + Update: resourceTencentCloudIgtmStrategyUpdate, + Delete: resourceTencentCloudIgtmStrategyDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "instance_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Instance ID.", + }, + + "strategy_name": { + Type: schema.TypeString, + Required: true, + Description: "Strategy name, cannot be duplicated.", + }, + + "source": { + Type: schema.TypeList, + Required: true, + Description: "Resolution lines.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dns_line_id": { + Type: schema.TypeInt, + Required: true, + Description: "Resolution request source line ID.", + }, + "name": { + Type: schema.TypeString, + Optional: true, + Description: "Resolution request source line name.", + }, + }, + }, + }, + + "main_address_pool_set": { + Type: schema.TypeList, + Required: true, + Description: "Main address pool set, up to four levels allowed.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "address_pools": { + Type: schema.TypeList, + Required: true, + Description: "Address pool IDs and weights in the set, array.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "pool_id": { + Type: schema.TypeInt, + Required: true, + Description: "Address pool ID.", + }, + "weight": { + Type: schema.TypeInt, + Optional: true, + Description: "Weight.", + }, + }, + }, + }, + "main_address_pool_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Address pool set ID.", + }, + "min_survive_num": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Switch threshold, cannot exceed the total number of addresses in the main set.", + }, + "traffic_strategy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Switch strategy: ALL resolves all addresses; WEIGHT: load balancing. When ALL, the weight value of resolved addresses is 1; when WEIGHT, weight is address pool weight * address weight.", + }, + }, + }, + }, + + "fallback_address_pool_set": { + Type: schema.TypeList, + Required: true, + Description: "Fallback address pool set, only one level allowed and address pool count must be 1.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "address_pools": { + Type: schema.TypeList, + Required: true, + Description: "Address pool IDs and weights in the set, array.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "pool_id": { + Type: schema.TypeInt, + Required: true, + Description: "Address pool ID.", + }, + "weight": { + Type: schema.TypeInt, + Optional: true, + Description: "Weight.", + }, + }, + }, + }, + "main_address_pool_id": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Address pool set ID.", + }, + "min_survive_num": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + Description: "Switch threshold, cannot exceed the total number of addresses in the main set.", + }, + "traffic_strategy": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Switch strategy: ALL resolves all addresses; WEIGHT: load balancing. When ALL, the weight value of resolved addresses is 1; when WEIGHT, weight is address pool weight * address weight.", + }, + }, + }, + }, + + "keep_domain_records": { + Type: schema.TypeString, + Optional: true, + Description: "Whether to enable policy forced retention of default lines disabled, enabled, default is disabled and only one policy can be enabled.", + }, + + "switch_pool_type": { + Type: schema.TypeString, + Optional: true, + Description: "Policy scheduling mode: AUTO default switching; STOP only pause without switching.", + }, + + // computed + "strategy_id": { + Type: schema.TypeInt, + Computed: true, + Description: "Strategy ID.", + }, + }, + } +} + +func resourceTencentCloudIgtmStrategyCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_igtm_strategy.create")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + request = igtmv20231024.NewCreateStrategyRequest() + response = igtmv20231024.NewCreateStrategyResponse() + instanceId string + strategyId string + ) + + if v, ok := d.GetOk("instance_id"); ok { + request.InstanceId = helper.String(v.(string)) + instanceId = v.(string) + } + + if v, ok := d.GetOk("strategy_name"); ok { + request.StrategyName = helper.String(v.(string)) + } + + if v, ok := d.GetOk("source"); ok { + for _, item := range v.([]interface{}) { + sourceMap := item.(map[string]interface{}) + source := igtmv20231024.Source{} + if v, ok := sourceMap["dns_line_id"].(int); ok { + source.DnsLineId = helper.IntUint64(v) + } + + if v, ok := sourceMap["name"].(string); ok && v != "" { + source.Name = helper.String(v) + } + + request.Source = append(request.Source, &source) + } + } + + if v, ok := d.GetOk("main_address_pool_set"); ok { + for _, item := range v.([]interface{}) { + mainAddressPoolSetMap := item.(map[string]interface{}) + mainAddressPool := igtmv20231024.MainAddressPool{} + if v, ok := mainAddressPoolSetMap["address_pools"]; ok { + for _, item := range v.([]interface{}) { + addressPoolsMap := item.(map[string]interface{}) + mainPoolWeight := igtmv20231024.MainPoolWeight{} + if v, ok := addressPoolsMap["pool_id"].(int); ok { + mainPoolWeight.PoolId = helper.IntUint64(v) + } + + if v, ok := addressPoolsMap["weight"].(int); ok && v != 0 { + mainPoolWeight.Weight = helper.IntUint64(v) + } + + mainAddressPool.AddressPools = append(mainAddressPool.AddressPools, &mainPoolWeight) + } + } + + if v, ok := mainAddressPoolSetMap["main_address_pool_id"].(int); ok && v != 0 { + mainAddressPool.MainAddressPoolId = helper.IntUint64(v) + } + + if v, ok := mainAddressPoolSetMap["min_survive_num"].(int); ok && v != 0 { + mainAddressPool.MinSurviveNum = helper.IntUint64(v) + } + + if v, ok := mainAddressPoolSetMap["traffic_strategy"].(string); ok && v != "" { + mainAddressPool.TrafficStrategy = helper.String(v) + } + + request.MainAddressPoolSet = append(request.MainAddressPoolSet, &mainAddressPool) + } + } + + if v, ok := d.GetOk("fallback_address_pool_set"); ok { + for _, item := range v.([]interface{}) { + fallbackAddressPoolSetMap := item.(map[string]interface{}) + mainAddressPool := igtmv20231024.MainAddressPool{} + if v, ok := fallbackAddressPoolSetMap["address_pools"]; ok { + for _, item := range v.([]interface{}) { + addressPoolsMap := item.(map[string]interface{}) + mainPoolWeight := igtmv20231024.MainPoolWeight{} + if v, ok := addressPoolsMap["pool_id"].(int); ok { + mainPoolWeight.PoolId = helper.IntUint64(v) + } + + if v, ok := addressPoolsMap["weight"].(int); ok && v != 0 { + mainPoolWeight.Weight = helper.IntUint64(v) + } + + mainAddressPool.AddressPools = append(mainAddressPool.AddressPools, &mainPoolWeight) + } + } + + if v, ok := fallbackAddressPoolSetMap["main_address_pool_id"].(int); ok && v != 0 { + mainAddressPool.MainAddressPoolId = helper.IntUint64(v) + } + + if v, ok := fallbackAddressPoolSetMap["min_survive_num"].(int); ok && v != 0 { + mainAddressPool.MinSurviveNum = helper.IntUint64(v) + } + + if v, ok := fallbackAddressPoolSetMap["traffic_strategy"].(string); ok && v != "" { + mainAddressPool.TrafficStrategy = helper.String(v) + } + + request.FallbackAddressPoolSet = append(request.FallbackAddressPoolSet, &mainAddressPool) + } + } + + if v, ok := d.GetOk("keep_domain_records"); ok { + request.KeepDomainRecords = helper.String(v.(string)) + } + + if v, ok := d.GetOk("switch_pool_type"); ok { + request.SwitchPoolType = helper.String(v.(string)) + } + + reqErr := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseIgtmV20231024Client().CreateStrategyWithContext(ctx, request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + if result == nil || result.Response == nil { + return resource.NonRetryableError(fmt.Errorf("Create igtm strategy failed, Response is nil.")) + } + + response = result + return nil + }) + + if reqErr != nil { + log.Printf("[CRITAL]%s create igtm strategy failed, reason:%+v", logId, reqErr) + return reqErr + } + + if response.Response.StrategyId == nil { + return fmt.Errorf("StrategyId is nil.") + } + + strategyId = helper.Int64ToStr(*response.Response.StrategyId) + d.SetId(strings.Join([]string{instanceId, strategyId}, tccommon.FILED_SP)) + return resourceTencentCloudIgtmStrategyRead(d, meta) +} + +func resourceTencentCloudIgtmStrategyRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_igtm_strategy.read")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + service = IgtmService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + ) + + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + + instanceId := idSplit[0] + strategyId := idSplit[1] + + respData, err := service.DescribeIgtmStrategyById(ctx, instanceId, strategyId) + if err != nil { + return err + } + + if respData == nil { + log.Printf("[WARN]%s resource `tencentcloud_igtm_strategy` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + d.SetId("") + return nil + } + + if respData.InstanceId != nil { + _ = d.Set("instance_id", respData.InstanceId) + } + + if respData.Name != nil { + _ = d.Set("strategy_name", respData.Name) + } + + if respData.Source != nil && len(respData.Source) > 0 { + sourceList := make([]map[string]interface{}, 0, len(respData.Source)) + for _, source := range respData.Source { + sourceMap := map[string]interface{}{} + if source.DnsLineId != nil { + sourceMap["dns_line_id"] = source.DnsLineId + } + + if source.Name != nil { + sourceMap["name"] = source.Name + } + + sourceList = append(sourceList, sourceMap) + } + + _ = d.Set("source", sourceList) + } + + if respData.MainAddressPoolSet != nil && len(respData.MainAddressPoolSet) > 0 { + mainAddressPoolSetList := make([]map[string]interface{}, 0, len(respData.MainAddressPoolSet)) + for _, mainAddressPoolSet := range respData.MainAddressPoolSet { + mainAddressPoolSetMap := map[string]interface{}{} + addressPoolsList := make([]map[string]interface{}, 0, len(mainAddressPoolSet.AddressPools)) + if mainAddressPoolSet.AddressPools != nil { + for _, addressPools := range mainAddressPoolSet.AddressPools { + addressPoolsMap := map[string]interface{}{} + if addressPools.PoolId != nil { + addressPoolsMap["pool_id"] = addressPools.PoolId + } + + if addressPools.Weight != nil { + addressPoolsMap["weight"] = addressPools.Weight + } + + addressPoolsList = append(addressPoolsList, addressPoolsMap) + } + + mainAddressPoolSetMap["address_pools"] = addressPoolsList + } + + if mainAddressPoolSet.MainAddressPoolId != nil { + mainAddressPoolSetMap["main_address_pool_id"] = mainAddressPoolSet.MainAddressPoolId + } + + if mainAddressPoolSet.MinSurviveNum != nil { + mainAddressPoolSetMap["min_survive_num"] = mainAddressPoolSet.MinSurviveNum + } + + if mainAddressPoolSet.TrafficStrategy != nil { + mainAddressPoolSetMap["traffic_strategy"] = mainAddressPoolSet.TrafficStrategy + } + + mainAddressPoolSetList = append(mainAddressPoolSetList, mainAddressPoolSetMap) + } + + _ = d.Set("main_address_pool_set", mainAddressPoolSetList) + } + + if respData.FallbackAddressPoolSet != nil && len(respData.FallbackAddressPoolSet) > 0 { + fallbackAddressPoolSetList := make([]map[string]interface{}, 0, len(respData.FallbackAddressPoolSet)) + for _, fallbackAddressPoolSet := range respData.FallbackAddressPoolSet { + fallbackAddressPoolSetMap := map[string]interface{}{} + addressPoolsList := make([]map[string]interface{}, 0, len(fallbackAddressPoolSet.AddressPools)) + if fallbackAddressPoolSet.AddressPools != nil { + for _, addressPools := range fallbackAddressPoolSet.AddressPools { + addressPoolsMap := map[string]interface{}{} + if addressPools.PoolId != nil { + addressPoolsMap["pool_id"] = addressPools.PoolId + } + + if addressPools.Weight != nil { + addressPoolsMap["weight"] = addressPools.Weight + } + + addressPoolsList = append(addressPoolsList, addressPoolsMap) + } + + fallbackAddressPoolSetMap["address_pools"] = addressPoolsList + } + + if fallbackAddressPoolSet.MainAddressPoolId != nil { + fallbackAddressPoolSetMap["main_address_pool_id"] = fallbackAddressPoolSet.MainAddressPoolId + } + + if fallbackAddressPoolSet.MinSurviveNum != nil { + fallbackAddressPoolSetMap["min_survive_num"] = fallbackAddressPoolSet.MinSurviveNum + } + + if fallbackAddressPoolSet.TrafficStrategy != nil { + fallbackAddressPoolSetMap["traffic_strategy"] = fallbackAddressPoolSet.TrafficStrategy + } + + fallbackAddressPoolSetList = append(fallbackAddressPoolSetList, fallbackAddressPoolSetMap) + } + + _ = d.Set("fallback_address_pool_set", fallbackAddressPoolSetList) + } + + if respData.KeepDomainRecords != nil { + _ = d.Set("keep_domain_records", respData.KeepDomainRecords) + } + + if respData.SwitchPoolType != nil { + _ = d.Set("switch_pool_type", respData.SwitchPoolType) + } + + if respData.StrategyId != nil { + _ = d.Set("strategy_id", respData.StrategyId) + } + + return nil +} + +func resourceTencentCloudIgtmStrategyUpdate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_igtm_strategy.update")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + ) + + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + + instanceId := idSplit[0] + strategyId := idSplit[1] + + needChange := false + mutableArgs := []string{"source", "main_address_pool_set", "fallback_address_pool_set", "strategy_name", "is_enabled", "keep_domain_records", "switch_pool_type"} + for _, v := range mutableArgs { + if d.HasChange(v) { + needChange = true + break + } + } + + if needChange { + request := igtmv20231024.NewModifyStrategyRequest() + if v, ok := d.GetOk("source"); ok { + for _, item := range v.([]interface{}) { + sourceMap := item.(map[string]interface{}) + source := igtmv20231024.Source{} + if v, ok := sourceMap["dns_line_id"].(int); ok { + source.DnsLineId = helper.IntUint64(v) + } + + if v, ok := sourceMap["name"].(string); ok && v != "" { + source.Name = helper.String(v) + } + request.Source = append(request.Source, &source) + } + } + + if v, ok := d.GetOk("main_address_pool_set"); ok { + for _, item := range v.([]interface{}) { + mainAddressPoolSetMap := item.(map[string]interface{}) + mainAddressPool := igtmv20231024.MainAddressPool{} + if v, ok := mainAddressPoolSetMap["address_pools"]; ok { + for _, item := range v.([]interface{}) { + addressPoolsMap := item.(map[string]interface{}) + mainPoolWeight := igtmv20231024.MainPoolWeight{} + if v, ok := addressPoolsMap["pool_id"].(int); ok { + mainPoolWeight.PoolId = helper.IntUint64(v) + } + + if v, ok := addressPoolsMap["weight"].(int); ok && v != 0 { + mainPoolWeight.Weight = helper.IntUint64(v) + } + + mainAddressPool.AddressPools = append(mainAddressPool.AddressPools, &mainPoolWeight) + } + } + + if v, ok := mainAddressPoolSetMap["main_address_pool_id"].(int); ok && v != 0 { + mainAddressPool.MainAddressPoolId = helper.IntUint64(v) + } + + if v, ok := mainAddressPoolSetMap["min_survive_num"].(int); ok && v != 0 { + mainAddressPool.MinSurviveNum = helper.IntUint64(v) + } + + if v, ok := mainAddressPoolSetMap["traffic_strategy"].(string); ok && v != "" { + mainAddressPool.TrafficStrategy = helper.String(v) + } + + request.MainAddressPoolSet = append(request.MainAddressPoolSet, &mainAddressPool) + } + } + + if v, ok := d.GetOk("fallback_address_pool_set"); ok { + for _, item := range v.([]interface{}) { + fallbackAddressPoolSetMap := item.(map[string]interface{}) + mainAddressPool := igtmv20231024.MainAddressPool{} + if v, ok := fallbackAddressPoolSetMap["address_pools"]; ok { + for _, item := range v.([]interface{}) { + addressPoolsMap := item.(map[string]interface{}) + mainPoolWeight := igtmv20231024.MainPoolWeight{} + if v, ok := addressPoolsMap["pool_id"].(int); ok { + mainPoolWeight.PoolId = helper.IntUint64(v) + } + + if v, ok := addressPoolsMap["weight"].(int); ok && v != 0 { + mainPoolWeight.Weight = helper.IntUint64(v) + } + + mainAddressPool.AddressPools = append(mainAddressPool.AddressPools, &mainPoolWeight) + } + } + + if v, ok := fallbackAddressPoolSetMap["main_address_pool_id"].(int); ok && v != 0 { + mainAddressPool.MainAddressPoolId = helper.IntUint64(v) + } + + if v, ok := fallbackAddressPoolSetMap["min_survive_num"].(int); ok && v != 0 { + mainAddressPool.MinSurviveNum = helper.IntUint64(v) + } + + if v, ok := fallbackAddressPoolSetMap["traffic_strategy"].(string); ok && v != "" { + mainAddressPool.TrafficStrategy = helper.String(v) + } + + request.FallbackAddressPoolSet = append(request.FallbackAddressPoolSet, &mainAddressPool) + } + } + + if v, ok := d.GetOk("strategy_name"); ok { + request.StrategyName = helper.String(v.(string)) + } + + if v, ok := d.GetOk("is_enabled"); ok { + request.IsEnabled = helper.String(v.(string)) + } + + if v, ok := d.GetOk("keep_domain_records"); ok { + request.KeepDomainRecords = helper.String(v.(string)) + } + + if v, ok := d.GetOk("switch_pool_type"); ok { + request.SwitchPoolType = helper.String(v.(string)) + } + + request.InstanceId = &instanceId + request.StrategyId = helper.StrToUint64Point(strategyId) + reqErr := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseIgtmV20231024Client().ModifyStrategyWithContext(ctx, request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + if result == nil || result.Response == nil || result.Response.Msg == nil { + return resource.NonRetryableError(fmt.Errorf("Modify igtm strategy failed, Response is nil.")) + } + + if *result.Response.Msg == "success" { + return nil + } else { + return resource.NonRetryableError(fmt.Errorf("Modify igtm strategy failed, Msg is %s.", *result.Response.Msg)) + } + }) + + if reqErr != nil { + log.Printf("[CRITAL]%s update igtm strategy failed, reason:%+v", logId, reqErr) + return reqErr + } + } + + return resourceTencentCloudIgtmStrategyRead(d, meta) +} + +func resourceTencentCloudIgtmStrategyDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_igtm_strategy.delete")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + request = igtmv20231024.NewDeleteStrategyRequest() + ) + + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + + instanceId := idSplit[0] + strategyId := idSplit[1] + + request.InstanceId = &instanceId + request.StrategyId = helper.StrToUint64Point(strategyId) + reqErr := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseIgtmV20231024Client().DeleteStrategyWithContext(ctx, request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + if result == nil || result.Response == nil || result.Response.Msg == nil { + return resource.NonRetryableError(fmt.Errorf("Delete igtm strategy failed, Response is nil.")) + } + + if *result.Response.Msg == "success" { + return nil + } else { + return resource.NonRetryableError(fmt.Errorf("Delete igtm strategy failed, Msg is %s.", *result.Response.Msg)) + } + }) + + if reqErr != nil { + log.Printf("[CRITAL]%s delete igtm strategy failed, reason:%+v", logId, reqErr) + return reqErr + } + + return nil +} diff --git a/tencentcloud/services/igtm/resource_tc_igtm_strategy.md b/tencentcloud/services/igtm/resource_tc_igtm_strategy.md new file mode 100644 index 0000000000..64c762eb56 --- /dev/null +++ b/tencentcloud/services/igtm/resource_tc_igtm_strategy.md @@ -0,0 +1,121 @@ +Provides a resource to create a IGTM strategy + +Example Usage + +```hcl +resource "tencentcloud_igtm_instance" "example" { + domain = "domain.com" + access_type = "CUSTOM" + global_ttl = 60 + package_type = "STANDARD" + instance_name = "tf-example" + access_domain = "domain.com" + access_sub_domain = "subDomain.com" + remark = "remark." + resource_id = "ins-lnpnnwvwqmr" +} + +resource "tencentcloud_igtm_address_pool" "example1" { + pool_name = "tf-example1" + traffic_strategy = "WEIGHT" + address_set { + addr = "1.1.1.1" + is_enable = "ENABLED" + weight = 90 + } + + address_set { + addr = "2.2.2.2" + is_enable = "DISABLED" + weight = 50 + } +} + +resource "tencentcloud_igtm_address_pool" "example2" { + pool_name = "tf-example2" + traffic_strategy = "WEIGHT" + address_set { + addr = "3.3.3.3" + is_enable = "ENABLED" + weight = 90 + } + + address_set { + addr = "4.4.4.4" + is_enable = "DISABLED" + weight = 50 + } +} + +resource "tencentcloud_igtm_address_pool" "example3" { + pool_name = "tf-example3" + traffic_strategy = "WEIGHT" + address_set { + addr = "5.5.5.5" + is_enable = "ENABLED" + weight = 90 + } + + address_set { + addr = "6.6.6.6" + is_enable = "DISABLED" + weight = 50 + } +} + +resource "tencentcloud_igtm_strategy" "example" { + instance_id = tencentcloud_igtm_instance.example.id + strategy_name = "tf-example" + source { + dns_line_id = 1 + name = "默认" + } + + source { + dns_line_id = 858 + name = "电信" + } + + source { + dns_line_id = 859 + name = "联通" + } + + source { + dns_line_id = 860 + name = "移动" + } + + main_address_pool_set { + address_pools { + pool_id = tencentcloud_igtm_address_pool.example1.pool_id + weight = 90 + } + + address_pools { + pool_id = tencentcloud_igtm_address_pool.example2.pool_id + weight = 80 + } + + min_survive_num = 1 + traffic_strategy = "WEIGHT" + } + + fallback_address_pool_set { + address_pools { + pool_id = tencentcloud_igtm_address_pool.example3.pool_id + } + } + + keep_domain_records = "DISABLED" + switch_pool_type = "AUTO" +} +``` + +Import + +IGTM strategy can be imported using the instanceId#strategyId, e.g. + +``` +terraform import tencentcloud_igtm_strategy.igtm_strategy gtm-uukztqtoaru#7556 +``` diff --git a/tencentcloud/services/igtm/resource_tc_igtm_strategy_test.go b/tencentcloud/services/igtm/resource_tc_igtm_strategy_test.go new file mode 100644 index 0000000000..d7cdaf0f61 --- /dev/null +++ b/tencentcloud/services/igtm/resource_tc_igtm_strategy_test.go @@ -0,0 +1,43 @@ +package igtm_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudIgtmStrategyResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{{ + Config: testAccIgtmStrategy, + Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_igtm_strategy.igtm_strategy", "id")), + }, { + ResourceName: "tencentcloud_igtm_strategy.igtm_strategy", + ImportState: true, + ImportStateVerify: true, + }}, + }) +} + +const testAccIgtmStrategy = ` + +resource "tencentcloud_igtm_strategy" "igtm_strategy" { + source = { + } + main_address_pool_set = { + address_pools = { + } + } + fallback_address_pool_set = { + address_pools = { + } + } +} +` diff --git a/tencentcloud/services/igtm/service_tencentcloud_igtm.go b/tencentcloud/services/igtm/service_tencentcloud_igtm.go index aa8abddb9b..f37ecfcda4 100644 --- a/tencentcloud/services/igtm/service_tencentcloud_igtm.go +++ b/tencentcloud/services/igtm/service_tencentcloud_igtm.go @@ -117,3 +117,467 @@ func (me *IgtmService) DescribeIgtmAddressPoolListByFilter(ctx context.Context, return } + +func (me *IgtmService) DescribeIgtmMonitorById(ctx context.Context, monitorId string) (ret *igtmv20231024.MonitorDetail, errRet error) { + logId := tccommon.GetLogId(ctx) + + request := igtmv20231024.NewDescribeMonitorDetailRequest() + response := igtmv20231024.NewDescribeMonitorDetailResponse() + request.MonitorId = helper.StrToUint64Point(monitorId) + + 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()) + } + }() + + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + ratelimit.Check(request.GetAction()) + result, e := me.client.UseIgtmV20231024Client().DescribeMonitorDetail(request) + if e != nil { + return tccommon.RetryError(e) + } + + if result == nil || result.Response == nil { + return resource.NonRetryableError(fmt.Errorf("Describe monitor detail failed, Response is nil.")) + } + + response = result + return nil + }) + + if err != nil { + errRet = err + return + } + + ret = response.Response.MonitorDetail + return +} + +func (me *IgtmService) DescribeIgtmMonitorsByFilter(ctx context.Context, param map[string]interface{}) (ret []*igtmv20231024.MonitorDetail, errRet error) { + var ( + logId = tccommon.GetLogId(ctx) + request = igtmv20231024.NewDescribeMonitorsRequest() + response = igtmv20231024.NewDescribeMonitorsResponse() + ) + + 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 == "Filters" { + request.Filters = v.([]*igtmv20231024.ResourceFilter) + } + + if k == "IsDetectNum" { + request.IsDetectNum = v.(*uint64) + } + } + + var ( + offset uint64 = 0 + limit uint64 = 100 + ) + for { + request.Offset = &offset + request.Limit = &limit + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + ratelimit.Check(request.GetAction()) + result, e := me.client.UseIgtmV20231024Client().DescribeMonitors(request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + if result == nil || result.Response == nil || result.Response.MonitorDataSet == nil { + return resource.NonRetryableError(fmt.Errorf("Describe monitors failed, Response is nil.")) + } + + response = result + return nil + }) + + if err != nil { + errRet = err + return + } + + ret = append(ret, response.Response.MonitorDataSet...) + if len(response.Response.MonitorDataSet) < int(limit) { + break + } + + offset += limit + } + + return +} + +func (me *IgtmService) DescribeIgtmDetectorsByFilter(ctx context.Context, param map[string]interface{}) (ret []*igtmv20231024.DetectorGroup, errRet error) { + var ( + logId = tccommon.GetLogId(ctx) + request = igtmv20231024.NewDescribeDetectorsRequest() + response = igtmv20231024.NewDescribeDetectorsResponse() + ) + + 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()) + } + }() + + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + ratelimit.Check(request.GetAction()) + result, e := me.client.UseIgtmV20231024Client().DescribeDetectors(request) + if e != nil { + return tccommon.RetryError(e) + } + + if result == nil || result.Response == nil { + return resource.NonRetryableError(fmt.Errorf("Describe detectors failed, Response is nil.")) + } + + response = result + return nil + }) + + if err != nil { + errRet = err + return + } + + ret = response.Response.DetectorGroupSet + return +} + +func (me *IgtmService) DescribeIgtmStrategyById(ctx context.Context, instanceId, strategyId string) (ret *igtmv20231024.StrategyDetail, errRet error) { + logId := tccommon.GetLogId(ctx) + + request := igtmv20231024.NewDescribeStrategyDetailRequest() + response := igtmv20231024.NewDescribeStrategyDetailResponse() + request.InstanceId = &instanceId + request.StrategyId = helper.StrToInt64Point(strategyId) + + 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()) + } + }() + + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + ratelimit.Check(request.GetAction()) + result, e := me.client.UseIgtmV20231024Client().DescribeStrategyDetail(request) + if e != nil { + return tccommon.RetryError(e) + } + + if result == nil || result.Response == nil { + return resource.NonRetryableError(fmt.Errorf("Describe strategy failed, Response is nil.")) + } + + response = result + return nil + }) + + if err != nil { + errRet = err + return + } + + ret = response.Response.StrategyDetail + return +} + +func (me *IgtmService) DescribeIgtmStrategyListByFilter(ctx context.Context, param map[string]interface{}) (ret []*igtmv20231024.Strategy, errRet error) { + var ( + logId = tccommon.GetLogId(ctx) + request = igtmv20231024.NewDescribeStrategyListRequest() + response = igtmv20231024.NewDescribeStrategyListResponse() + ) + + 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 == "InstanceId" { + request.InstanceId = v.(*string) + } + + if k == "Filters" { + request.Filters = v.([]*igtmv20231024.ResourceFilter) + } + } + + var ( + offset uint64 = 0 + limit uint64 = 100 + ) + + for { + request.Offset = &offset + request.Limit = &limit + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + ratelimit.Check(request.GetAction()) + result, e := me.client.UseIgtmV20231024Client().DescribeStrategyList(request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + if result == nil || result.Response == nil || result.Response.StrategySet == nil { + return resource.NonRetryableError(fmt.Errorf("Describe strategy list failed, Response is nil.")) + } + + response = result + return nil + }) + + if err != nil { + errRet = err + return + } + + ret = append(ret, response.Response.StrategySet...) + if len(response.Response.StrategySet) < int(limit) { + break + } + + offset += limit + } + + return +} + +func (me *IgtmService) DescribeIgtmInstanceById(ctx context.Context, instanceId string) (ret *igtmv20231024.InstanceDetail, errRet error) { + logId := tccommon.GetLogId(ctx) + + request := igtmv20231024.NewDescribeInstanceDetailRequest() + response := igtmv20231024.NewDescribeInstanceDetailResponse() + request.InstanceId = &instanceId + + 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()) + } + }() + + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + ratelimit.Check(request.GetAction()) + result, e := me.client.UseIgtmV20231024Client().DescribeInstanceDetail(request) + if e != nil { + return tccommon.RetryError(e) + } + + if result == nil || result.Response == nil { + return resource.NonRetryableError(fmt.Errorf("Describe instance failed, Response is nil.")) + } + + response = result + return nil + }) + + if err != nil { + errRet = err + return + } + + ret = response.Response.Instance + return +} + +func (me *IgtmService) DescribeIgtmInstanceListByFilter(ctx context.Context, param map[string]interface{}) (ret []*igtmv20231024.Instance, systemAccessEnabled *bool, errRet error) { + var ( + logId = tccommon.GetLogId(ctx) + request = igtmv20231024.NewDescribeInstanceListRequest() + response = igtmv20231024.NewDescribeInstanceListResponse() + ) + + 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 == "Filters" { + request.Filters = v.([]*igtmv20231024.ResourceFilter) + } + } + + var ( + offset uint64 = 0 + limit uint64 = 100 + ) + + for { + request.Offset = &offset + request.Limit = &limit + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + ratelimit.Check(request.GetAction()) + result, e := me.client.UseIgtmV20231024Client().DescribeInstanceList(request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + if result == nil || result.Response == nil || result.Response.InstanceSet == nil { + return resource.NonRetryableError(fmt.Errorf("Describe instance list failed, Response is nil.")) + } + + if result.Response.SystemAccessEnabled != nil { + systemAccessEnabled = result.Response.SystemAccessEnabled + } + + response = result + return nil + }) + + if err != nil { + errRet = err + return + } + + ret = append(ret, response.Response.InstanceSet...) + if len(response.Response.InstanceSet) < int(limit) { + break + } + + offset += limit + } + + return +} + +func (me *IgtmService) DescribeIgtmInstancePackageListByFilter(ctx context.Context, param map[string]interface{}) (ret []*igtmv20231024.InstancePackage, errRet error) { + var ( + logId = tccommon.GetLogId(ctx) + request = igtmv20231024.NewDescribeInstancePackageListRequest() + response = igtmv20231024.NewDescribeInstancePackageListResponse() + ) + + 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 == "Filters" { + request.Filters = v.([]*igtmv20231024.ResourceFilter) + } + + if k == "IsUsed" { + request.IsUsed = v.(*uint64) + } + } + + var ( + offset uint64 = 0 + limit uint64 = 100 + ) + + for { + request.Offset = &offset + request.Limit = &limit + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + ratelimit.Check(request.GetAction()) + result, e := me.client.UseIgtmV20231024Client().DescribeInstancePackageList(request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + if result == nil || result.Response == nil || result.Response.InstanceSet == nil { + return resource.NonRetryableError(fmt.Errorf("Describe instance package list failed, Response is nil.")) + } + + response = result + return nil + }) + + if err != nil { + errRet = err + return + } + + ret = append(ret, response.Response.InstanceSet...) + if len(response.Response.InstanceSet) < int(limit) { + break + } + + offset += limit + } + + return +} + +func (me *IgtmService) DescribeIgtmDetectTaskPackageListByFilter(ctx context.Context, param map[string]interface{}) (ret []*igtmv20231024.DetectTaskPackage, errRet error) { + var ( + logId = tccommon.GetLogId(ctx) + request = igtmv20231024.NewDescribeDetectTaskPackageListRequest() + response = igtmv20231024.NewDescribeDetectTaskPackageListResponse() + ) + + 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 == "Filters" { + request.Filters = v.([]*igtmv20231024.ResourceFilter) + } + } + + var ( + offset uint64 = 0 + limit uint64 = 100 + ) + + for { + request.Offset = &offset + request.Limit = &limit + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + ratelimit.Check(request.GetAction()) + result, e := me.client.UseIgtmV20231024Client().DescribeDetectTaskPackageList(request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + if result == nil || result.Response == nil || result.Response.TaskPackageSet == nil { + return resource.NonRetryableError(fmt.Errorf("Describe detect task package list failed, Response is nil.")) + } + + response = result + return nil + }) + + if err != nil { + errRet = err + return + } + + ret = append(ret, response.Response.TaskPackageSet...) + if len(response.Response.TaskPackageSet) < int(limit) { + break + } + + offset += limit + } + + return +} diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/client.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/client.go index 2ee969f674..856733eb0d 100644 --- a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/client.go +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/client.go @@ -102,7 +102,14 @@ func (c *Client) completeRequest(request tchttp.Request) { if domain == "" { domain = request.GetServiceDomain(request.GetService()) } - request.SetDomain(domain) + pathIdx := strings.IndexByte(domain, '/') + if pathIdx >= 0 { + request.SetDomain(domain[:pathIdx]) + request.SetPath(domain[pathIdx:]) + } else { + request.SetDomain(domain) + request.SetPath("/") + } } if request.GetHttpMethod() == "" { @@ -197,16 +204,6 @@ func (c *Client) sendWithoutSignature(request tchttp.Request, response tchttp.Re } } - for k, v := range request.GetHeader() { - switch k { - case "X-TC-Action", "X-TC-Version", "X-TC-Timestamp", "X-TC-RequestClient", - "X-TC-Language", "Content-Type", "X-TC-Region", "X-TC-Token": - c.logger.Printf("Skip header \"%s\": can not specify built-in header", k) - default: - headers[k] = v - } - } - if !isOctetStream && request.GetContentType() == octetStream { isOctetStream = true b, _ := json.Marshal(request) @@ -269,7 +266,11 @@ func (c *Client) sendWithoutSignature(request tchttp.Request, response tchttp.Re } httpRequest = httpRequest.WithContext(request.GetContext()) for k, v := range headers { - httpRequest.Header[k] = []string{v} + if strings.EqualFold(k, "Host") { + httpRequest.Host = v + } else { + httpRequest.Header.Set(k, v) + } } httpResponse, err := c.sendWithRateLimitRetry(httpRequest, isRetryable(request)) if err != nil { @@ -300,7 +301,11 @@ func (c *Client) sendWithSignatureV1(request tchttp.Request, response tchttp.Res } for k, v := range request.GetHeader() { - httpRequest.Header.Set(k, v) + if strings.EqualFold(k, "Host") { + httpRequest.Host = v + } else { + httpRequest.Header.Set(k, v) + } } httpResponse, err := c.sendWithRateLimitRetry(httpRequest, isRetryable(request)) @@ -358,18 +363,6 @@ func (c *Client) sendWithSignatureV3(request tchttp.Request, response tchttp.Res } } - // Merge any additional headers from the request, but skip built-in headers - // to prevent them from being overridden. - for k, v := range request.GetHeader() { - switch k { - case "X-TC-Action", "X-TC-Version", "X-TC-Timestamp", "X-TC-RequestClient", - "X-TC-Language", "X-TC-Region", "X-TC-Token": - c.logger.Printf("Skip header \"%s\": can not specify built-in header", k) - default: - headers[k] = v - } - } - // Handle the case where the request content type is explicitly set to octet-stream, // but it's not already handled as an OctetStream CommonRequest. if !isOctetStream && request.GetContentType() == octetStream { @@ -385,6 +378,12 @@ func (c *Client) sendWithSignatureV3(request tchttp.Request, response tchttp.Res headers["Content-Type"] = octetStream octetStreamBody = request.GetBody() } + + // Merge any additional headers from the request + for k, v := range request.GetHeader() { + headers[k] = v + } + // --- Begin Signature Version 3 (TC3-HMAC-SHA256) Signing Process --- // 1. Construct the Canonical Request @@ -528,7 +527,11 @@ func (c *Client) sendWithSignatureV3(request tchttp.Request, response tchttp.Res // Set all the headers on the request. for k, v := range headers { - httpRequest.Header[k] = []string{v} + if strings.EqualFold(k, "Host") { + httpRequest.Host = v + } else { + httpRequest.Header.Set(k, v) + } } // Send the HTTP request with rate limit retry logic. diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go index ef97ef16cc..dad44bec04 100644 --- a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go @@ -265,7 +265,7 @@ func CompleteCommonParams(request Request, region string, requestClient string) params["Action"] = request.GetAction() params["Timestamp"] = strconv.FormatInt(time.Now().Unix(), 10) params["Nonce"] = strconv.Itoa(rand.Int()) - params["RequestClient"] = "SDK_GO_1.1.50" + params["RequestClient"] = "SDK_GO_1.3.3" if requestClient != "" { params["RequestClient"] += ": " + requestClient } diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/role_arn_provider.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/role_arn_provider.go index 421f09dfea..46ac52acba 100644 --- a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/role_arn_provider.go +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/role_arn_provider.go @@ -27,6 +27,7 @@ type RoleArnProvider struct { roleArn string roleSessionName string durationSeconds int64 + Endpoint string } type stsRsp struct { @@ -65,7 +66,11 @@ func (r *RoleArnProvider) GetCredential() (CredentialIface, error) { } credential := NewCredential(r.longSecretId, r.longSecretKey) cpf := profile.NewClientProfile() - cpf.HttpProfile.Endpoint = endpoint + providerEndpoint := r.Endpoint + if providerEndpoint == "" { + providerEndpoint = endpoint + } + cpf.HttpProfile.Endpoint = providerEndpoint cpf.HttpProfile.ReqMethod = "POST" client := NewCommonClient(credential, region, cpf) diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/sign.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/sign.go index 0c91afd245..e26cc65e68 100644 --- a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/sign.go +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/sign.go @@ -62,7 +62,10 @@ func signRequest(request tchttp.Request, credential CredentialIface, method stri func getStringToSign(request tchttp.Request) string { method := request.GetHttpMethod() - domain := request.GetDomain() + domain := request.GetHeader()["Host"] + if domain == "" { + domain = request.GetDomain() + } path := request.GetPath() var buf bytes.Buffer diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm/v20231024/models.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm/v20231024/models.go index ba73b83c36..46994fe55b 100644 --- a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm/v20231024/models.go +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm/v20231024/models.go @@ -308,6 +308,9 @@ func (r *CreateInstanceRequest) FromJsonString(s string) error { // Predefined struct for user type CreateInstanceResponseParams struct { + // 实例id + InstanceId *string `json:"InstanceId,omitnil,omitempty" name:"InstanceId"` + // 唯一请求 ID,由服务端生成,每次请求都会返回(若请求因其他原因未能抵达服务端,则该次请求不会获得 RequestId)。定位问题时需要提供该次请求的 RequestId。 RequestId *string `json:"RequestId,omitnil,omitempty" name:"RequestId"` } @@ -1054,6 +1057,9 @@ func (r *DescribeDetectPackageDetailResponse) FromJsonString(s string) error { // Predefined struct for user type DescribeDetectTaskPackageListRequestParams struct { + // 偏移量 + Offset *uint64 `json:"Offset,omitnil,omitempty" name:"Offset"` + // 每页条数 Limit *uint64 `json:"Limit,omitnil,omitempty" name:"Limit"` @@ -1064,6 +1070,9 @@ type DescribeDetectTaskPackageListRequestParams struct { type DescribeDetectTaskPackageListRequest struct { *tchttp.BaseRequest + // 偏移量 + Offset *uint64 `json:"Offset,omitnil,omitempty" name:"Offset"` + // 每页条数 Limit *uint64 `json:"Limit,omitnil,omitempty" name:"Limit"` @@ -1083,6 +1092,7 @@ func (r *DescribeDetectTaskPackageListRequest) FromJsonString(s string) error { if err := json.Unmarshal([]byte(s), &f); err != nil { return err } + delete(f, "Offset") delete(f, "Limit") delete(f, "Filters") if len(f) > 0 { @@ -1232,12 +1242,15 @@ func (r *DescribeDnsLineListResponse) FromJsonString(s string) error { // Predefined struct for user type DescribeInstanceDetailRequestParams struct { - + // 实例id + InstanceId *string `json:"InstanceId,omitnil,omitempty" name:"InstanceId"` } type DescribeInstanceDetailRequest struct { *tchttp.BaseRequest + // 实例id + InstanceId *string `json:"InstanceId,omitnil,omitempty" name:"InstanceId"` } func (r *DescribeInstanceDetailRequest) ToJsonString() string { @@ -1252,7 +1265,7 @@ func (r *DescribeInstanceDetailRequest) FromJsonString(s string) error { if err := json.Unmarshal([]byte(s), &f); err != nil { return err } - + delete(f, "InstanceId") if len(f) > 0 { return tcerr.NewTencentCloudSDKError("ClientError.BuildRequestError", "DescribeInstanceDetailRequest has unknown keys!", "") } @@ -1363,6 +1376,9 @@ func (r *DescribeInstanceListResponse) FromJsonString(s string) error { // Predefined struct for user type DescribeInstancePackageListRequestParams struct { + // 偏移量 + Offset *uint64 `json:"Offset,omitnil,omitempty" name:"Offset"` + // 每页条数 Limit *uint64 `json:"Limit,omitnil,omitempty" name:"Limit"` @@ -1376,6 +1392,9 @@ type DescribeInstancePackageListRequestParams struct { type DescribeInstancePackageListRequest struct { *tchttp.BaseRequest + // 偏移量 + Offset *uint64 `json:"Offset,omitnil,omitempty" name:"Offset"` + // 每页条数 Limit *uint64 `json:"Limit,omitnil,omitempty" name:"Limit"` @@ -1398,6 +1417,7 @@ func (r *DescribeInstancePackageListRequest) FromJsonString(s string) error { if err := json.Unmarshal([]byte(s), &f); err != nil { return err } + delete(f, "Offset") delete(f, "Limit") delete(f, "Filters") delete(f, "IsUsed") @@ -1500,6 +1520,9 @@ type DescribeMonitorsRequestParams struct { // 分页,当前分页记录数 Limit *uint64 `json:"Limit,omitnil,omitempty" name:"Limit"` + // 查询过滤条件:MonitorName:监控器名称;MonitorId:监控器id + Filters []*ResourceFilter `json:"Filters,omitnil,omitempty" name:"Filters"` + // 是否查探测次数0否1是 IsDetectNum *uint64 `json:"IsDetectNum,omitnil,omitempty" name:"IsDetectNum"` } @@ -1513,6 +1536,9 @@ type DescribeMonitorsRequest struct { // 分页,当前分页记录数 Limit *uint64 `json:"Limit,omitnil,omitempty" name:"Limit"` + // 查询过滤条件:MonitorName:监控器名称;MonitorId:监控器id + Filters []*ResourceFilter `json:"Filters,omitnil,omitempty" name:"Filters"` + // 是否查探测次数0否1是 IsDetectNum *uint64 `json:"IsDetectNum,omitnil,omitempty" name:"IsDetectNum"` } @@ -1531,6 +1557,7 @@ func (r *DescribeMonitorsRequest) FromJsonString(s string) error { } delete(f, "Offset") delete(f, "Limit") + delete(f, "Filters") delete(f, "IsDetectNum") if len(f) > 0 { return tcerr.NewTencentCloudSDKError("ClientError.BuildRequestError", "DescribeMonitorsRequest has unknown keys!", "") @@ -2187,6 +2214,9 @@ func (r *ModifyAddressPoolResponse) FromJsonString(s string) error { // Predefined struct for user type ModifyInstanceConfigRequestParams struct { + // 实例id + InstanceId *string `json:"InstanceId,omitnil,omitempty" name:"InstanceId"` + // 实例配置详情 InstanceConfig *InstanceConfig `json:"InstanceConfig,omitnil,omitempty" name:"InstanceConfig"` } @@ -2194,6 +2224,9 @@ type ModifyInstanceConfigRequestParams struct { type ModifyInstanceConfigRequest struct { *tchttp.BaseRequest + // 实例id + InstanceId *string `json:"InstanceId,omitnil,omitempty" name:"InstanceId"` + // 实例配置详情 InstanceConfig *InstanceConfig `json:"InstanceConfig,omitnil,omitempty" name:"InstanceConfig"` } @@ -2210,6 +2243,7 @@ func (r *ModifyInstanceConfigRequest) FromJsonString(s string) error { if err := json.Unmarshal([]byte(s), &f); err != nil { return err } + delete(f, "InstanceId") delete(f, "InstanceConfig") if len(f) > 0 { return tcerr.NewTencentCloudSDKError("ClientError.BuildRequestError", "ModifyInstanceConfigRequest has unknown keys!", "") diff --git a/vendor/modules.txt b/vendor/modules.txt index 38f6edfd7f..0f58333ae8 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1170,7 +1170,7 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit/v20190319 # github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1148 ## explicit; go 1.14 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls/v20201016 -# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.50 +# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.3.3 ## explicit; go 1.11 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors @@ -1235,7 +1235,7 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap/v20180529 # github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gwlb v1.0.1127 ## explicit; go 1.14 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gwlb/v20240906 -# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm v1.1.27 +# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm v1.3.3 ## explicit; go 1.14 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/igtm/v20231024 # github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.1145 diff --git a/website/docs/d/igtm_address_pool_list.html.markdown b/website/docs/d/igtm_address_pool_list.html.markdown index b422c031b1..5c31f094b0 100644 --- a/website/docs/d/igtm_address_pool_list.html.markdown +++ b/website/docs/d/igtm_address_pool_list.html.markdown @@ -35,14 +35,14 @@ data "tencentcloud_igtm_address_pool_list" "example" { The following arguments are supported: -* `filters` - (Optional, List) Alert filter conditions: PoolName: Address pool name; MonitorId: Monitor ID. +* `filters` - (Optional, List) Alert filter conditions. * `result_output_file` - (Optional, String) Used to save results. The `filters` object supports the following: * `name` - (Required, String) Filter field name, supported list as follows: -- type: Main resource type, CDN. -- instanceId: IGTM instance ID. This is a required parameter, failure to provide will cause interface query failure. +- PoolName: Address pool name. +- MonitorId: Monitor ID. This is a required parameter, failure to provide will cause interface query failure. * `value` - (Required, Set) Filter field value. * `fuzzy` - (Optional, Bool) Whether to enable fuzzy query, only supports filter field name as domain. When fuzzy query is enabled, maximum Value length is 1, otherwise maximum Value length is 5. (Reserved field, currently not used). diff --git a/website/docs/d/igtm_detect_task_package_list.html.markdown b/website/docs/d/igtm_detect_task_package_list.html.markdown new file mode 100644 index 0000000000..d10ad0059a --- /dev/null +++ b/website/docs/d/igtm_detect_task_package_list.html.markdown @@ -0,0 +1,75 @@ +--- +subcategory: "Intelligent Global Traffic Manager(IGTM)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_igtm_detect_task_package_list" +sidebar_current: "docs-tencentcloud-datasource-igtm_detect_task_package_list" +description: |- + Use this data source to query detailed information of IGTM detect task package list +--- + +# tencentcloud_igtm_detect_task_package_list + +Use this data source to query detailed information of IGTM detect task package list + +## Example Usage + +### Query all igtm detect task package list + +```hcl +data "tencentcloud_igtm_detect_task_package_list" "example" {} +``` + +### Query igtm detect task package list by filter + +```hcl +data "tencentcloud_igtm_detect_task_package_list" "example" { + filters { + name = "ResourceId" + value = ["task-qqcoptejbwbf"] + fuzzy = true + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `filters` - (Optional, List) Detect task filter conditions. +* `result_output_file` - (Optional, String) Used to save results. + +The `filters` object supports the following: + +* `name` - (Required, String) Filter field name, supported list as follows: +- ResourceId: detect task resource id. +- PeriodStart: minimum expiration time. +- PeriodEnd: maximum expiration time. +* `value` - (Required, Set) Filter field value. +* `fuzzy` - (Optional, Bool) Whether to enable fuzzy query, only supports filter field name as domain. +When fuzzy query is enabled, maximum Value length is 1, otherwise maximum Value length is 5. (Reserved field, not currently used). + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `task_package_set` - Detect task package list. + * `auto_renew_flag` - Whether auto-renew 0 no 1 yes. + * `cost_item_list` - Billing item. + * `cost_name` - Billing item name. + * `cost_value` - Billing item value. + * `create_time` - Package creation time. + * `current_deadline` - Package expiration time. + * `group` - Detect task type: 100 system setting; 200 billing; 300 management system; 110D monitoring migration free task; 120 disaster recovery switch task. + * `is_expire` - Whether expired 0 no 1 yes. + * `quota` - Quota. + * `remark` - Remark. + * `resource_id` - Resource ID. + * `resource_type` - Resource type +TASK Detect task. + * `status` - Status +ENABLED: Normal +ISOLATED: Isolated +DESTROYED: Destroyed +REFUNDED: Refunded. + + diff --git a/website/docs/d/igtm_detectors.html.markdown b/website/docs/d/igtm_detectors.html.markdown new file mode 100644 index 0000000000..b991641fdb --- /dev/null +++ b/website/docs/d/igtm_detectors.html.markdown @@ -0,0 +1,37 @@ +--- +subcategory: "Intelligent Global Traffic Manager(IGTM)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_igtm_detectors" +sidebar_current: "docs-tencentcloud-datasource-igtm_detectors" +description: |- + Use this data source to query detailed information of IGTM detectors +--- + +# tencentcloud_igtm_detectors + +Use this data source to query detailed information of IGTM detectors + +## Example Usage + +```hcl +data "tencentcloud_igtm_detectors" "example" {} +``` + +## Argument Reference + +The following arguments are supported: + +* `result_output_file` - (Optional, String) Used to save results. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `detector_group_set` - Detector group list. + * `gid` - Line group ID GroupLineId. + * `group_name` - Group name. + * `group_type` - bgp, international, isp. + * `internet_family` - ipv4, ipv6. + * `package_set` - Supported package types. + + diff --git a/website/docs/d/igtm_instance_list.html.markdown b/website/docs/d/igtm_instance_list.html.markdown new file mode 100644 index 0000000000..d2fbbeaf97 --- /dev/null +++ b/website/docs/d/igtm_instance_list.html.markdown @@ -0,0 +1,88 @@ +--- +subcategory: "Intelligent Global Traffic Manager(IGTM)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_igtm_instance_list" +sidebar_current: "docs-tencentcloud-datasource-igtm_instance_list" +description: |- + Use this data source to query detailed information of IGTM instance list +--- + +# tencentcloud_igtm_instance_list + +Use this data source to query detailed information of IGTM instance list + +## Example Usage + +### Query all igtm instance list + +```hcl +data "tencentcloud_igtm_instance_list" "example" {} +``` + +### Query igtm instance list by filters + +```hcl +data "tencentcloud_igtm_instance_list" "example" { + filters { + name = "InstanceId" + value = ["gtm-uukztqtoaru"] + fuzzy = true + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `filters` - (Optional, List) Filter conditions. +* `result_output_file` - (Optional, String) Used to save results. + +The `filters` object supports the following: + +* `name` - (Required, String) Filter field name, supported list as follows: +- InstanceId: IGTM instance ID. +- Domain: IGTM instance domain. +- MonitorId: Monitor ID. +- PoolId: Pool ID. This is a required parameter, not passing it will cause interface query failure. +* `value` - (Required, Set) Filter field value. +* `fuzzy` - (Optional, Bool) Whether to enable fuzzy query, only supports filter field name as domain. +When fuzzy query is enabled, maximum Value length is 1, otherwise maximum Value length is 5. (Reserved field, not currently used). + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `instance_set` - Instance list. + * `access_domain` - Access domain. + * `access_sub_domain` - Access subdomain. + * `access_type` - Cname domain access method +CUSTOM: Custom access domain +SYSTEM: System access domain. + * `address_pool_num` - Bound address pool count. + * `created_on` - Instance creation time. + * `domain` - Business domain. + * `global_ttl` - Global record expiration time. + * `instance_id` - Instance ID. + * `instance_name` - Instance name. + * `is_cname_configured` - Whether cname access: true accessed; false not accessed. + * `monitor_num` - Bound monitor count. + * `package_type` - Package type +FREE: Free version +STANDARD: Standard version +ULTIMATE: Ultimate version. + * `pool_id` - Address pool ID. + * `pool_name` - Address pool name. + * `remark` - Remark. + * `resource_id` - Resource ID. + * `status` - Instance status, ENABLED: Normal, DISABLED: Disabled. + * `strategy_num` - Strategy count. + * `updated_on` - Instance update time. + * `working_status` - Instance running status +NORMAL: Healthy +FAULTY: At risk +DOWN: Down +UNKNOWN: Unknown. +* `system_access_enabled` - Whether system domain access is supported: true supported; false not supported. + + diff --git a/website/docs/d/igtm_instance_package_list.html.markdown b/website/docs/d/igtm_instance_package_list.html.markdown new file mode 100644 index 0000000000..147ed22562 --- /dev/null +++ b/website/docs/d/igtm_instance_package_list.html.markdown @@ -0,0 +1,81 @@ +--- +subcategory: "Intelligent Global Traffic Manager(IGTM)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_igtm_instance_package_list" +sidebar_current: "docs-tencentcloud-datasource-igtm_instance_package_list" +description: |- + Use this data source to query detailed information of IGTM instance package list +--- + +# tencentcloud_igtm_instance_package_list + +Use this data source to query detailed information of IGTM instance package list + +## Example Usage + +### Query all igtm instance package list + +```hcl +data "tencentcloud_igtm_instance_package_list" "example" {} +``` + +### Query igtm instance package list by filter + +```hcl +data "tencentcloud_igtm_instance_package_list" "example" { + filters { + name = "InstanceId" + value = ["gtm-uukztqtoaru"] + fuzzy = true + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `filters` - (Optional, List) Filter conditions. +* `is_used` - (Optional, Int) Whether used: 0 not used 1 used. +* `result_output_file` - (Optional, String) Used to save results. + +The `filters` object supports the following: + +* `name` - (Required, String) Filter field name, supported list as follows: +- InstanceId: instance ID. +- InstanceName: instance name. +- ResourceId: package ID. +- PackageType: package type. This is a required parameter, not passing it will cause interface query failure. +* `value` - (Required, Set) Filter field value. +* `fuzzy` - (Optional, Bool) Whether to enable fuzzy query, only supports filter field name as domain. +When fuzzy query is enabled, maximum Value length is 1, otherwise maximum Value length is 5. (Reserved field, not currently used). + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `instance_set` - Instance package list. + * `auto_renew_flag` - Whether auto-renew 0 no 1 yes. + * `cost_item_list` - Billing item. + * `cost_name` - Billing item name. + * `cost_value` - Billing item value. + * `create_time` - Package creation time. + * `current_deadline` - Package expiration time. + * `instance_id` - Instance ID. + * `instance_name` - Instance name. + * `is_expire` - Whether expired 0 no 1 yes. + * `min_check_interval` - Minimum check interval time s. + * `min_global_ttl` - Minimum TTL s. + * `package_type` - Package type +FREE: Free version +STANDARD: Standard version +ULTIMATE: Ultimate version. + * `remark` - Remark. + * `resource_id` - Instance package resource ID. + * `schedule_strategy` - Strategy type: LOCATION schedule by geographic location, DELAY schedule by delay. + * `status` - Instance status +ENABLED: Normal +DISABLED: Disabled. + * `traffic_strategy` - Traffic strategy type: ALL return all, WEIGHT weight. + + diff --git a/website/docs/d/igtm_monitors.html.markdown b/website/docs/d/igtm_monitors.html.markdown new file mode 100644 index 0000000000..783cf5cf47 --- /dev/null +++ b/website/docs/d/igtm_monitors.html.markdown @@ -0,0 +1,79 @@ +--- +subcategory: "Intelligent Global Traffic Manager(IGTM)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_igtm_monitors" +sidebar_current: "docs-tencentcloud-datasource-igtm_monitors" +description: |- + Use this data source to query detailed information of IGTM monitors +--- + +# tencentcloud_igtm_monitors + +Use this data source to query detailed information of IGTM monitors + +## Example Usage + +### Query all igtm monitors + +```hcl +data "tencentcloud_igtm_monitors" "example" {} +``` + +### Query igtm monitors by filter + +```hcl +data "tencentcloud_igtm_monitors" "example" { + filters { + name = "MonitorId" + value = ["12383"] + fuzzy = true + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `filters` - (Optional, List) Query filter conditions. +* `is_detect_num` - (Optional, Int) Whether to query detection count, 0 for no, 1 for yes. +* `result_output_file` - (Optional, String) Used to save results. + +The `filters` object supports the following: + +* `name` - (Required, String) Filter field name, supported MonitorName: monitor name; MonitorId: monitor ID. +* `value` - (Required, Set) Filter field values. +* `fuzzy` - (Optional, Bool) Whether to enable fuzzy query, only supports filter field name as domain. +When fuzzy query is enabled, Value maximum length is 1, otherwise Value maximum length is 5. (Reserved field, currently unused). + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `monitor_data_set` - Monitor list. + * `check_interval` - Detection period. + * `check_protocol` - Detection protocol PING TCP HTTP HTTPS. + * `continue_period` - Continuous period count. + * `created_on` - Creation time. + * `detect_num` - Detection count. + * `detector_group_ids` - Monitoring node ID group. + * `detector_style` - Monitoring node type. +AUTO INTERNAL OVERSEAS IPV6 ALL. + * `enable_redirect` - Whether to enable 3xx redirect following ENABLED DISABLED. + * `enable_sni` - Whether to enable SNI. +ENABLED DISABLED. + * `fail_rate` - Failure rate upper limit 100. + * `fail_times` - Failure count. + * `host` - Detection host. + * `monitor_id` - Detection rule ID. + * `monitor_name` - Monitor name. + * `packet_loss_rate` - Packet loss rate upper limit. + * `path` - Detection path. + * `ping_num` - Packet count. + * `return_code_threshold` - Return value threshold. + * `tcp_port` - TCP port. + * `timeout` - Detection timeout. + * `uin` - Owner user. + * `updated_on` - Update time. + + diff --git a/website/docs/d/igtm_strategy_list.html.markdown b/website/docs/d/igtm_strategy_list.html.markdown new file mode 100644 index 0000000000..d27c2d6185 --- /dev/null +++ b/website/docs/d/igtm_strategy_list.html.markdown @@ -0,0 +1,67 @@ +--- +subcategory: "Intelligent Global Traffic Manager(IGTM)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_igtm_strategy_list" +sidebar_current: "docs-tencentcloud-datasource-igtm_strategy_list" +description: |- + Use this data source to query detailed information of IGTM strategy list +--- + +# tencentcloud_igtm_strategy_list + +Use this data source to query detailed information of IGTM strategy list + +## Example Usage + +```hcl +data "tencentcloud_igtm_strategy_list" "example" { + instance_id = "gtm-uukztqtoaru" + filters { + name = "StrategyName" + value = ["tf-example"] + fuzzy = true + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `instance_id` - (Required, String) Instance ID. +* `filters` - (Optional, List) Strategy filter conditions: StrategyName: strategy name. +* `result_output_file` - (Optional, String) Used to save results. + +The `filters` object supports the following: + +* `name` - (Required, String) Filter field name, supported list as follows: +- type: main resource type, CDN. +- instanceId: IGTM instance ID. This is a required parameter, failure to pass will cause interface query failure. +* `value` - (Required, Set) Filter field values. +* `fuzzy` - (Optional, Bool) Whether to enable fuzzy query, only supports filter field name as domain. +When fuzzy query is enabled, Value maximum length is 1, otherwise Value maximum length is 5. (Reserved field, currently unused). + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `strategy_set` - Strategy list. + * `activate_level` - Current activated address pool level, 0 means fallback activated, null means unknown. + * `activate_main_pool_id` - Activated main pool ID, null means unknown. + * `active_pool_type` - Current activated address pool set type: main main pool; fallback fallback pool. + * `active_traffic_strategy` - Current activated address pool traffic strategy: all resolve all; weight load balancing. + * `created_on` - Creation time. + * `instance_id` - Instance ID. + * `is_enabled` - Whether enabled: ENABLED enabled; DISABLED disabled. + * `keep_domain_records` - Whether to retain lines: enabled retain, disabled not retain, only retain default lines. + * `monitor_num` - Monitor count. + * `name` - Strategy name. + * `source` - Address source. + * `dns_line_id` - Resolution request source line ID. + * `name` - Resolution request source line name. + * `status` - Health status: ok healthy, warn risk, down failure. + * `strategy_id` - Strategy ID. + * `switch_pool_type` - Scheduling mode: AUTO default; PAUSE only pause without switching. + * `updated_on` - Update time. + + diff --git a/website/docs/r/igtm_address_pool.html.markdown b/website/docs/r/igtm_address_pool.html.markdown index 586ced2de6..58884bac52 100644 --- a/website/docs/r/igtm_address_pool.html.markdown +++ b/website/docs/r/igtm_address_pool.html.markdown @@ -11,6 +11,8 @@ description: |- Provides a resource to create a IGTM address pool +~> **NOTE:** Resource `tencentcloud_igtm_instance` needs to be created before using this resource. + ## Example Usage ```hcl diff --git a/website/docs/r/igtm_instance.html.markdown b/website/docs/r/igtm_instance.html.markdown new file mode 100644 index 0000000000..0458ea209d --- /dev/null +++ b/website/docs/r/igtm_instance.html.markdown @@ -0,0 +1,65 @@ +--- +subcategory: "Intelligent Global Traffic Manager(IGTM)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_igtm_instance" +sidebar_current: "docs-tencentcloud-resource-igtm_instance" +description: |- + Provides a resource to create a IGTM instance +--- + +# tencentcloud_igtm_instance + +Provides a resource to create a IGTM instance + +~> **NOTE:** Currently, executing the `terraform destroy` command to delete this resource is not supported. If you need to destroy it, please contact Tencent Cloud IGTM through a ticket. + +## Example Usage + +```hcl +resource "tencentcloud_igtm_instance" "example" { + domain = "domain.com" + access_type = "CUSTOM" + global_ttl = 60 + package_type = "STANDARD" + instance_name = "tf-example" + access_domain = "domain.com" + access_sub_domain = "sub_domain.com" + remark = "remark." + resource_id = "ins-lnpnnwvwxgs" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `access_domain` - (Required, String) Access main domain. +* `access_sub_domain` - (Required, String) Access subdomain. +* `access_type` - (Required, String) CUSTOM: Custom access domain +SYSTEM: System access domain. +* `domain` - (Required, String) Business domain. +* `global_ttl` - (Required, Int) Resolution effective time. +* `instance_name` - (Required, String) Instance name. +* `package_type` - (Required, String, ForceNew) Package type +FREE: Free version +STANDARD: Standard version +ULTIMATE: Ultimate version. +* `resource_id` - (Required, String, ForceNew) Package resource ID. +* `remark` - (Optional, String) Remark. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. +* `instance_id` - Instance ID. + + +## Import + +IGTM instance can be imported using the id, e.g. + +``` +terraform import tencentcloud_igtm_instance.example gtm-uukztqtoaru +``` + diff --git a/website/docs/r/igtm_monitor.html.markdown b/website/docs/r/igtm_monitor.html.markdown new file mode 100644 index 0000000000..266e8bcca4 --- /dev/null +++ b/website/docs/r/igtm_monitor.html.markdown @@ -0,0 +1,74 @@ +--- +subcategory: "Intelligent Global Traffic Manager(IGTM)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_igtm_monitor" +sidebar_current: "docs-tencentcloud-resource-igtm_monitor" +description: |- + Provides a resource to create a IGTM monitor +--- + +# tencentcloud_igtm_monitor + +Provides a resource to create a IGTM monitor + +## Example Usage + +```hcl +resource "tencentcloud_igtm_monitor" "example" { + monitor_name = "tf-example" + check_protocol = "PING" + check_interval = 60 + timeout = 5 + fail_times = 1 + fail_rate = 50 + detector_style = "INTERNAL" + detector_group_ids = [30, 31, 32, 34, 37, 38, 39, 1, 2, 3, 7, 8, 9, 10, 11, 12] + ping_num = 20 + tcp_port = 443 + path = "/" + return_code_threshold = 500 + enable_redirect = "DISABLED" + enable_sni = "DISABLED" + packet_loss_rate = 90 + continue_period = 1 +} +``` + +## Argument Reference + +The following arguments are supported: + +* `check_interval` - (Required, Int) Check interval (seconds), optional values 15 60 120 300. +* `check_protocol` - (Required, String) Detection protocol, optional values `PING`, `TCP`, `HTTP`, `HTTPS`. +* `detector_group_ids` - (Required, Set: [`Int`]) Detector group ID list separated by commas. +* `detector_style` - (Required, String) Monitoring node type, optional values AUTO INTERNAL OVERSEAS IPV6 ALL. +* `fail_rate` - (Required, Int) Failure rate, values 20 30 40 50 60 70 80 100, default value 50. +* `fail_times` - (Required, Int) Retry count, optional values 0, 1, 2. +* `monitor_name` - (Required, String) Monitor name. +* `timeout` - (Required, Int) Timeout time, unit seconds, optional values 2 3 5 10. +* `continue_period` - (Optional, Int) Continuous period count, optional values 1-5. +* `enable_redirect` - (Optional, String) Follow 3XX redirect, DISABLED for disabled, ENABLED for enabled, default disabled. +* `enable_sni` - (Optional, String) Enable SNI, DISABLED for disabled, ENABLED for enabled, default disabled. +* `host` - (Optional, String) Host setting, default is business domain name. +* `packet_loss_rate` - (Optional, Int) Packet loss rate alarm threshold, required when CheckProtocol=ping, values 10 30 50 80 90 100. +* `path` - (Optional, String) URL path, default is "/". +* `ping_num` - (Optional, Int) PING packet count, required when CheckProtocol=ping, optional values 20 50 100. +* `return_code_threshold` - (Optional, Int) Return error code threshold, optional values 400 and 500, default value 500. +* `tcp_port` - (Optional, Int) Check port, optional values between 1-65535. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. +* `monitor_id` - Monitor ID. + + +## Import + +IGTM monitor can be imported using the id, e.g. + +``` +terraform import tencentcloud_igtm_monitor.example 12355 +``` + diff --git a/website/docs/r/igtm_strategy.html.markdown b/website/docs/r/igtm_strategy.html.markdown new file mode 100644 index 0000000000..f10b5fbf28 --- /dev/null +++ b/website/docs/r/igtm_strategy.html.markdown @@ -0,0 +1,182 @@ +--- +subcategory: "Intelligent Global Traffic Manager(IGTM)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_igtm_strategy" +sidebar_current: "docs-tencentcloud-resource-igtm_strategy" +description: |- + Provides a resource to create a IGTM strategy +--- + +# tencentcloud_igtm_strategy + +Provides a resource to create a IGTM strategy + +## Example Usage + +```hcl +resource "tencentcloud_igtm_instance" "example" { + domain = "domain.com" + access_type = "CUSTOM" + global_ttl = 60 + package_type = "STANDARD" + instance_name = "tf-example" + access_domain = "domain.com" + access_sub_domain = "subDomain.com" + remark = "remark." + resource_id = "ins-lnpnnwvwqmr" +} + +resource "tencentcloud_igtm_address_pool" "example1" { + pool_name = "tf-example1" + traffic_strategy = "WEIGHT" + address_set { + addr = "1.1.1.1" + is_enable = "ENABLED" + weight = 90 + } + + address_set { + addr = "2.2.2.2" + is_enable = "DISABLED" + weight = 50 + } +} + +resource "tencentcloud_igtm_address_pool" "example2" { + pool_name = "tf-example2" + traffic_strategy = "WEIGHT" + address_set { + addr = "3.3.3.3" + is_enable = "ENABLED" + weight = 90 + } + + address_set { + addr = "4.4.4.4" + is_enable = "DISABLED" + weight = 50 + } +} + +resource "tencentcloud_igtm_address_pool" "example3" { + pool_name = "tf-example3" + traffic_strategy = "WEIGHT" + address_set { + addr = "5.5.5.5" + is_enable = "ENABLED" + weight = 90 + } + + address_set { + addr = "6.6.6.6" + is_enable = "DISABLED" + weight = 50 + } +} + +resource "tencentcloud_igtm_strategy" "example" { + instance_id = tencentcloud_igtm_instance.example.id + strategy_name = "tf-example" + source { + dns_line_id = 1 + name = "默认" + } + + source { + dns_line_id = 858 + name = "电信" + } + + source { + dns_line_id = 859 + name = "联通" + } + + source { + dns_line_id = 860 + name = "移动" + } + + main_address_pool_set { + address_pools { + pool_id = tencentcloud_igtm_address_pool.example1.pool_id + weight = 90 + } + + address_pools { + pool_id = tencentcloud_igtm_address_pool.example2.pool_id + weight = 80 + } + + min_survive_num = 1 + traffic_strategy = "WEIGHT" + } + + fallback_address_pool_set { + address_pools { + pool_id = tencentcloud_igtm_address_pool.example3.pool_id + } + } + + keep_domain_records = "DISABLED" + switch_pool_type = "AUTO" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `fallback_address_pool_set` - (Required, List) Fallback address pool set, only one level allowed and address pool count must be 1. +* `instance_id` - (Required, String, ForceNew) Instance ID. +* `main_address_pool_set` - (Required, List) Main address pool set, up to four levels allowed. +* `source` - (Required, List) Resolution lines. +* `strategy_name` - (Required, String) Strategy name, cannot be duplicated. +* `keep_domain_records` - (Optional, String) Whether to enable policy forced retention of default lines disabled, enabled, default is disabled and only one policy can be enabled. +* `switch_pool_type` - (Optional, String) Policy scheduling mode: AUTO default switching; STOP only pause without switching. + +The `address_pools` object of `fallback_address_pool_set` supports the following: + +* `pool_id` - (Required, Int) Address pool ID. +* `weight` - (Optional, Int) Weight. + +The `address_pools` object of `main_address_pool_set` supports the following: + +* `pool_id` - (Required, Int) Address pool ID. +* `weight` - (Optional, Int) Weight. + +The `fallback_address_pool_set` object supports the following: + +* `address_pools` - (Required, List) Address pool IDs and weights in the set, array. +* `main_address_pool_id` - (Optional, Int) Address pool set ID. +* `min_survive_num` - (Optional, Int) Switch threshold, cannot exceed the total number of addresses in the main set. +* `traffic_strategy` - (Optional, String) Switch strategy: ALL resolves all addresses; WEIGHT: load balancing. When ALL, the weight value of resolved addresses is 1; when WEIGHT, weight is address pool weight * address weight. + +The `main_address_pool_set` object supports the following: + +* `address_pools` - (Required, List) Address pool IDs and weights in the set, array. +* `main_address_pool_id` - (Optional, Int) Address pool set ID. +* `min_survive_num` - (Optional, Int) Switch threshold, cannot exceed the total number of addresses in the main set. +* `traffic_strategy` - (Optional, String) Switch strategy: ALL resolves all addresses; WEIGHT: load balancing. When ALL, the weight value of resolved addresses is 1; when WEIGHT, weight is address pool weight * address weight. + +The `source` object supports the following: + +* `dns_line_id` - (Required, Int) Resolution request source line ID. +* `name` - (Optional, String) Resolution request source line name. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. +* `strategy_id` - Strategy ID. + + +## Import + +IGTM strategy can be imported using the instanceId#strategyId, e.g. + +``` +terraform import tencentcloud_igtm_strategy.igtm_strategy gtm-uukztqtoaru#7556 +``` + diff --git a/website/tencentcloud.erb b/website/tencentcloud.erb index ad65ba7910..7e4d1d06fa 100644 --- a/website/tencentcloud.erb +++ b/website/tencentcloud.erb @@ -2902,17 +2902,44 @@
  • Data Sources
  • Resources