diff --git a/alicloud/provider.go b/alicloud/provider.go index f2118ba65264..6f4ff3561bda 100644 --- a/alicloud/provider.go +++ b/alicloud/provider.go @@ -918,6 +918,7 @@ func Provider() terraform.ResourceProvider { ResourcesMap: map[string]*schema.Resource{ "alicloud_alidns_cloud_gtm_instance_config": resourceAliCloudAlidnsCloudGtmInstanceConfig(), "alicloud_alidns_cloud_gtm_monitor_template": resourceAliCloudAlidnsCloudGtmMonitorTemplate(), + "alicloud_alidns_cloud_gtm_address": resourceAliCloudAlidnsCloudGtmAddress(), "alicloud_ecs_disk_encryption_by_default": resourceAliCloudEcsDiskEncryptionByDefault(), "alicloud_cms_integration_policy": resourceAliCloudCmsIntegrationPolicy(), "alicloud_cms_workspace": resourceAliCloudCmsWorkspace(), diff --git a/alicloud/resource_alicloud_alidns_cloud_gtm_address.go b/alicloud/resource_alicloud_alidns_cloud_gtm_address.go new file mode 100644 index 000000000000..d4df52543c87 --- /dev/null +++ b/alicloud/resource_alicloud_alidns_cloud_gtm_address.go @@ -0,0 +1,397 @@ +// Package alicloud. This file is generated automatically. Please do not modify it manually, thank you! +package alicloud + +import ( + "encoding/json" + "fmt" + "log" + "time" + + "github.com/PaesslerAG/jsonpath" + "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func resourceAliCloudAlidnsCloudGtmAddress() *schema.Resource { + return &schema.Resource{ + Create: resourceAliCloudAlidnsCloudGtmAddressCreate, + Read: resourceAliCloudAlidnsCloudGtmAddressRead, + Update: resourceAliCloudAlidnsCloudGtmAddressUpdate, + Delete: resourceAliCloudAlidnsCloudGtmAddressDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(5 * time.Minute), + Delete: schema.DefaultTimeout(5 * time.Minute), + }, + Schema: map[string]*schema.Schema{ + "address": { + Type: schema.TypeString, + Required: true, + }, + "available_mode": { + Type: schema.TypeString, + Required: true, + ValidateFunc: StringInSlice([]string{"auto", "manual"}, false), + }, + "create_time": { + Type: schema.TypeString, + Computed: true, + }, + "enable_status": { + Type: schema.TypeString, + Required: true, + ValidateFunc: StringInSlice([]string{"enable", "disable"}, false), + }, + "health_judgement": { + Type: schema.TypeString, + Required: true, + ValidateFunc: StringInSlice([]string{"any_ok", "all_ok", "p30_ok", "p50_ok", "p70_ok"}, false), + }, + "health_tasks": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "port": { + Type: schema.TypeInt, + Optional: true, + }, + "template_id": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + "manual_available_status": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: StringInSlice([]string{"available", "unavailable"}, false), + }, + "name": { + Type: schema.TypeString, + Required: true, + }, + "remark": { + Type: schema.TypeString, + Optional: true, + }, + "type": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: StringInSlice([]string{"IPv4", "IPv6", "domain"}, false), + }, + }, + } +} + +func resourceAliCloudAlidnsCloudGtmAddressCreate(d *schema.ResourceData, meta interface{}) error { + + client := meta.(*connectivity.AliyunClient) + + action := "CreateCloudGtmAddress" + var request map[string]interface{} + var response map[string]interface{} + query := make(map[string]interface{}) + var err error + request = make(map[string]interface{}) + + request["ClientToken"] = buildClientToken(action) + + if v, ok := d.GetOk("health_tasks"); ok { + healthTasksMapsArray := make([]interface{}, 0) + for _, dataLoop := range convertToInterfaceArray(v) { + dataLoopTmp := dataLoop.(map[string]interface{}) + dataLoopMap := make(map[string]interface{}) + dataLoopMap["Port"] = dataLoopTmp["port"] + dataLoopMap["TemplateId"] = dataLoopTmp["template_id"] + healthTasksMapsArray = append(healthTasksMapsArray, dataLoopMap) + } + healthTasksMapsJson, err := json.Marshal(healthTasksMapsArray) + if err != nil { + return WrapError(err) + } + request["HealthTasks"] = string(healthTasksMapsJson) + } + + request["HealthJudgement"] = d.Get("health_judgement") + request["Name"] = d.Get("name") + request["Address"] = d.Get("address") + request["EnableStatus"] = d.Get("enable_status") + if v, ok := d.GetOk("manual_available_status"); ok { + request["ManualAvailableStatus"] = v + } + if v, ok := d.GetOk("remark"); ok { + request["Remark"] = v + } + request["AvailableMode"] = d.Get("available_mode") + request["Type"] = d.Get("type") + wait := incrementalWait(3*time.Second, 5*time.Second) + err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { + response, err = client.RpcPost("Alidns", "2015-01-09", action, query, request, true) + if err != nil { + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil + }) + addDebug(action, response, request) + + if err != nil { + return WrapErrorf(err, DefaultErrorMsg, "alicloud_alidns_cloud_gtm_address", action, AlibabaCloudSdkGoERROR) + } + + d.SetId(fmt.Sprint(response["AddressId"])) + + return resourceAliCloudAlidnsCloudGtmAddressRead(d, meta) +} + +func resourceAliCloudAlidnsCloudGtmAddressRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*connectivity.AliyunClient) + alidnsServiceV2 := AlidnsServiceV2{client} + + objectRaw, err := alidnsServiceV2.DescribeAlidnsCloudGtmAddress(d.Id()) + if err != nil { + if !d.IsNewResource() && NotFoundError(err) { + log.Printf("[DEBUG] Resource alicloud_alidns_cloud_gtm_address DescribeAlidnsCloudGtmAddress Failed!!! %s", err) + d.SetId("") + return nil + } + return WrapError(err) + } + + d.Set("address", objectRaw["Address"]) + d.Set("available_mode", objectRaw["AvailableMode"]) + d.Set("create_time", objectRaw["CreateTime"]) + d.Set("enable_status", objectRaw["EnableStatus"]) + d.Set("health_judgement", objectRaw["HealthJudgement"]) + d.Set("manual_available_status", objectRaw["ManualAvailableStatus"]) + d.Set("name", objectRaw["Name"]) + d.Set("remark", objectRaw["Remark"]) + d.Set("type", objectRaw["Type"]) + + healthTaskRaw, _ := jsonpath.Get("$.HealthTasks.HealthTask", objectRaw) + healthTasksMaps := make([]map[string]interface{}, 0) + if healthTaskRaw != nil { + for _, healthTaskChildRaw := range convertToInterfaceArray(healthTaskRaw) { + healthTasksMap := make(map[string]interface{}) + healthTaskChildRaw := healthTaskChildRaw.(map[string]interface{}) + healthTasksMap["port"] = healthTaskChildRaw["Port"] + healthTasksMap["template_id"] = healthTaskChildRaw["TemplateId"] + + healthTasksMaps = append(healthTasksMaps, healthTasksMap) + } + } + if err := d.Set("health_tasks", healthTasksMaps); err != nil { + return err + } + + return nil +} + +func resourceAliCloudAlidnsCloudGtmAddressUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*connectivity.AliyunClient) + var request map[string]interface{} + var response map[string]interface{} + var query map[string]interface{} + update := false + d.Partial(true) + + var err error + action := "UpdateCloudGtmAddress" + request = make(map[string]interface{}) + query = make(map[string]interface{}) + request["AddressId"] = d.Id() + + request["ClientToken"] = buildClientToken(action) + if d.HasChange("health_tasks") { + update = true + if v, ok := d.GetOk("health_tasks"); ok || d.HasChange("health_tasks") { + healthTasksMapsArray := make([]interface{}, 0) + for _, dataLoop := range convertToInterfaceArray(v) { + dataLoopTmp := dataLoop.(map[string]interface{}) + dataLoopMap := make(map[string]interface{}) + dataLoopMap["Port"] = dataLoopTmp["port"] + dataLoopMap["TemplateId"] = dataLoopTmp["template_id"] + healthTasksMapsArray = append(healthTasksMapsArray, dataLoopMap) + } + healthTasksMapsJson, err := json.Marshal(healthTasksMapsArray) + if err != nil { + return WrapError(err) + } + request["HealthTasks"] = string(healthTasksMapsJson) + } + } + + if d.HasChange("health_judgement") { + update = true + } + request["HealthJudgement"] = d.Get("health_judgement") + if d.HasChange("name") { + update = true + } + request["Name"] = d.Get("name") + if d.HasChange("address") { + update = true + } + request["Address"] = d.Get("address") + if update { + wait := incrementalWait(3*time.Second, 5*time.Second) + err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { + response, err = client.RpcPost("Alidns", "2015-01-09", action, query, request, true) + if err != nil { + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil + }) + addDebug(action, response, request) + if err != nil { + return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) + } + } + update = false + action = "UpdateCloudGtmAddressEnableStatus" + request = make(map[string]interface{}) + query = make(map[string]interface{}) + request["AddressId"] = d.Id() + + request["ClientToken"] = buildClientToken(action) + if d.HasChange("enable_status") { + update = true + } + request["EnableStatus"] = d.Get("enable_status") + if update { + wait := incrementalWait(3*time.Second, 5*time.Second) + err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { + response, err = client.RpcPost("Alidns", "2015-01-09", action, query, request, true) + if err != nil { + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil + }) + addDebug(action, response, request) + if err != nil { + return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) + } + } + update = false + action = "UpdateCloudGtmAddressManualAvailableStatus" + request = make(map[string]interface{}) + query = make(map[string]interface{}) + request["AddressId"] = d.Id() + + request["ClientToken"] = buildClientToken(action) + if d.HasChange("manual_available_status") { + update = true + request["ManualAvailableStatus"] = d.Get("manual_available_status") + } + + if d.HasChange("available_mode") { + update = true + } + request["AvailableMode"] = d.Get("available_mode") + if update { + wait := incrementalWait(3*time.Second, 5*time.Second) + err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { + response, err = client.RpcPost("Alidns", "2015-01-09", action, query, request, true) + if err != nil { + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil + }) + addDebug(action, response, request) + if err != nil { + return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) + } + } + update = false + action = "UpdateCloudGtmAddressRemark" + request = make(map[string]interface{}) + query = make(map[string]interface{}) + request["AddressId"] = d.Id() + + request["ClientToken"] = buildClientToken(action) + if d.HasChange("remark") { + update = true + request["Remark"] = d.Get("remark") + } + + if update { + wait := incrementalWait(3*time.Second, 5*time.Second) + err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { + response, err = client.RpcPost("Alidns", "2015-01-09", action, query, request, true) + if err != nil { + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil + }) + addDebug(action, response, request) + if err != nil { + return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) + } + } + + d.Partial(false) + return resourceAliCloudAlidnsCloudGtmAddressRead(d, meta) +} + +func resourceAliCloudAlidnsCloudGtmAddressDelete(d *schema.ResourceData, meta interface{}) error { + + client := meta.(*connectivity.AliyunClient) + action := "DeleteCloudGtmAddress" + var request map[string]interface{} + var response map[string]interface{} + query := make(map[string]interface{}) + var err error + request = make(map[string]interface{}) + request["AddressId"] = d.Id() + + request["ClientToken"] = buildClientToken(action) + + wait := incrementalWait(3*time.Second, 5*time.Second) + err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { + response, err = client.RpcPost("Alidns", "2015-01-09", action, query, request, true) + if err != nil { + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil + }) + addDebug(action, response, request) + + if err != nil { + if NotFoundError(err) { + return nil + } + return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) + } + + return nil +} diff --git a/alicloud/resource_alicloud_alidns_cloud_gtm_address_test.go b/alicloud/resource_alicloud_alidns_cloud_gtm_address_test.go new file mode 100644 index 000000000000..0dacee3f1eb0 --- /dev/null +++ b/alicloud/resource_alicloud_alidns_cloud_gtm_address_test.go @@ -0,0 +1,352 @@ +// Package alicloud. This file is generated automatically. Please do not modify it manually, thank you! +package alicloud + +import ( + "fmt" + "testing" + + "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +// Test Alidns CloudGtmAddress. >>> Resource test cases, automatically generated. +// Case resourceCase_20260320_c1u6VV 12687 +func TestAccAliCloudAlidnsCloudGtmAddress_basic12687(t *testing.T) { + var v map[string]interface{} + resourceId := "alicloud_alidns_cloud_gtm_address.default" + ra := resourceAttrInit(resourceId, AlicloudAlidnsCloudGtmAddressMap12687) + rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} { + return &AlidnsServiceV2{testAccProvider.Meta().(*connectivity.AliyunClient)} + }, "DescribeAlidnsCloudGtmAddress") + rac := resourceAttrCheckInit(rc, ra) + testAccCheck := rac.resourceAttrMapUpdateSet() + rand := acctest.RandIntRange(10000, 99999) + name := fmt.Sprintf("tfaccalidns%d", rand) + testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudAlidnsCloudGtmAddressBasicDependence12687) + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + IDRefreshName: resourceId, + Providers: testAccProviders, + CheckDestroy: rac.checkResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testAccConfig(map[string]interface{}{ + "type": "IPv4", + "health_judgement": "all_ok", + "health_tasks": []map[string]interface{}{ + { + "template_id": "${alicloud_alidns_cloud_gtm_monitor_template.create_ping_template.id}", + }, + { + "port": "53", + "template_id": "${alicloud_alidns_cloud_gtm_monitor_template.create_tcp_template.id}", + }, + { + "port": "443", + "template_id": "${alicloud_alidns_cloud_gtm_monitor_template.create_https_template.id}", + }, + }, + "address": "1.1.1.1", + "enable_status": "enable", + "available_mode": "manual", + "manual_available_status": "available", + "name": name, + "remark": "remark", + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "type": "IPv4", + "health_judgement": "all_ok", + "health_tasks.#": "3", + "address": "1.1.1.1", + "enable_status": "enable", + "available_mode": "manual", + "manual_available_status": "available", + "name": name, + "remark": "remark", + }), + ), + }, + { + Config: testAccConfig(map[string]interface{}{ + "health_judgement": "any_ok", + "health_tasks": []map[string]interface{}{ + { + "template_id": "${alicloud_alidns_cloud_gtm_monitor_template.create_ping_template.id}", + }, + { + "port": "443", + "template_id": "${alicloud_alidns_cloud_gtm_monitor_template.create_https_template.id}", + }, + }, + "address": "2.2.2.2", + "enable_status": "disable", + "name": name + "_update", + "remark": "add-test-modify", + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "health_judgement": "any_ok", + "health_tasks.#": "2", + "address": "2.2.2.2", + "enable_status": "disable", + "name": name + "_update", + "remark": "add-test-modify", + }), + ), + }, + { + Config: testAccConfig(map[string]interface{}{ + "health_tasks": REMOVEKEY, + "available_mode": "auto", + "name": name + "_update", + "remark": "test", + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "health_tasks.#": "0", + "available_mode": "auto", + "name": name + "_update", + "remark": "test", + }), + ), + }, + { + ResourceName: resourceId, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{}, + }, + }, + }) +} + +var AlicloudAlidnsCloudGtmAddressMap12687 = map[string]string{ + "create_time": CHECKSET, +} + +func AlicloudAlidnsCloudGtmAddressBasicDependence12687(name string) string { + return fmt.Sprintf(` +variable "name" { + default = "%s" +} + +resource "alicloud_alidns_cloud_gtm_monitor_template" "create_tcp_template" { + ip_version = "IPv4" + timeout = "3000" + isp_city_nodes { + city_code = "357" + isp_code = "465" + } + isp_city_nodes { + city_code = "738" + isp_code = "465" + } + evaluation_count = "1" + protocol = "tcp" + failure_rate = "50" + extend_info = "{}" + name = "test-case-2" + interval = "60" +} + +resource "alicloud_alidns_cloud_gtm_monitor_template" "create_https_template" { + ip_version = "IPv4" + timeout = "2000" + isp_city_nodes { + city_code = "357" + isp_code = "465" + } + isp_city_nodes { + city_code = "738" + isp_code = "465" + } + evaluation_count = "1" + protocol = "https" + failure_rate = "50" + extend_info = "{\"code\":400,\"followRedirect\":true,\"path\":\"/\",\"sni\":false}" + name = "test-case-3" + interval = "60" +} + +resource "alicloud_alidns_cloud_gtm_monitor_template" "create_ping_template" { + ip_version = "IPv4" + timeout = "3000" + isp_city_nodes { + city_code = "357" + isp_code = "465" + } + isp_city_nodes { + city_code = "738" + isp_code = "465" + } + evaluation_count = "1" + protocol = "ping" + failure_rate = "50" + extend_info = "{\"packetLossRate\":10,\"packetNum\":20}" + name = "test-case-1" + interval = "60" +} + + +`, name) +} + +// Case resourceCase_20260323_h98fTA 12680 +func TestAccAliCloudAlidnsCloudGtmAddress_basic12680(t *testing.T) { + var v map[string]interface{} + resourceId := "alicloud_alidns_cloud_gtm_address.default" + ra := resourceAttrInit(resourceId, AlicloudAlidnsCloudGtmAddressMap12680) + rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} { + return &AlidnsServiceV2{testAccProvider.Meta().(*connectivity.AliyunClient)} + }, "DescribeAlidnsCloudGtmAddress") + rac := resourceAttrCheckInit(rc, ra) + testAccCheck := rac.resourceAttrMapUpdateSet() + rand := acctest.RandIntRange(10000, 99999) + name := fmt.Sprintf("tfaccalidns%d", rand) + testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudAlidnsCloudGtmAddressBasicDependence12680) + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + IDRefreshName: resourceId, + Providers: testAccProviders, + CheckDestroy: rac.checkResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testAccConfig(map[string]interface{}{ + "type": "domain", + "health_judgement": "all_ok", + "address": "www.tianxuan.top", + "enable_status": "enable", + "available_mode": "auto", + "name": name, + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "type": "domain", + "health_judgement": "all_ok", + "address": "www.tianxuan.top", + "enable_status": "enable", + "available_mode": "auto", + "name": name, + }), + ), + }, + { + Config: testAccConfig(map[string]interface{}{ + "available_mode": "manual", + "manual_available_status": "available", + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "available_mode": "manual", + "manual_available_status": "available", + }), + ), + }, + { + ResourceName: resourceId, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{}, + }, + }, + }) +} + +var AlicloudAlidnsCloudGtmAddressMap12680 = map[string]string{ + "create_time": CHECKSET, +} + +func AlicloudAlidnsCloudGtmAddressBasicDependence12680(name string) string { + return fmt.Sprintf(` +variable "name" { + default = "%s" +} + + +`, name) +} + +// Case resourceCase_20260323_8FMXi4 12683 +func TestAccAliCloudAlidnsCloudGtmAddress_basic12683(t *testing.T) { + var v map[string]interface{} + resourceId := "alicloud_alidns_cloud_gtm_address.default" + ra := resourceAttrInit(resourceId, AlicloudAlidnsCloudGtmAddressMap12683) + rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} { + return &AlidnsServiceV2{testAccProvider.Meta().(*connectivity.AliyunClient)} + }, "DescribeAlidnsCloudGtmAddress") + rac := resourceAttrCheckInit(rc, ra) + testAccCheck := rac.resourceAttrMapUpdateSet() + rand := acctest.RandIntRange(10000, 99999) + name := fmt.Sprintf("tfaccalidns%d", rand) + testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudAlidnsCloudGtmAddressBasicDependence12683) + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + IDRefreshName: resourceId, + Providers: testAccProviders, + CheckDestroy: rac.checkResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testAccConfig(map[string]interface{}{ + "type": "IPv6", + "health_judgement": "any_ok", + "address": "2400:3200:baba:0:0:0:0:1", + "enable_status": "enable", + "available_mode": "auto", + "name": name, + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "type": "IPv6", + "health_judgement": "any_ok", + "address": "2400:3200:baba:0:0:0:0:1", + "enable_status": "enable", + "available_mode": "auto", + "name": name, + }), + ), + }, + { + Config: testAccConfig(map[string]interface{}{ + "health_judgement": "all_ok", + "enable_status": "disable", + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "health_judgement": "all_ok", + "enable_status": "disable", + }), + ), + }, + { + ResourceName: resourceId, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{}, + }, + }, + }) +} + +var AlicloudAlidnsCloudGtmAddressMap12683 = map[string]string{ + "create_time": CHECKSET, +} + +func AlicloudAlidnsCloudGtmAddressBasicDependence12683(name string) string { + return fmt.Sprintf(` +variable "name" { + default = "%s" +} + + +`, name) +} + +// Test Alidns CloudGtmAddress. <<< Resource test cases, automatically generated. diff --git a/alicloud/service_alicloud_alidns_v2.go b/alicloud/service_alicloud_alidns_v2.go index b80ac70f46dc..3c5a33588706 100644 --- a/alicloud/service_alicloud_alidns_v2.go +++ b/alicloud/service_alicloud_alidns_v2.go @@ -244,3 +244,78 @@ func (s *AlidnsServiceV2) AlidnsCloudGtmMonitorTemplateStateRefreshFuncWithApi(i } // DescribeAlidnsCloudGtmMonitorTemplate >>> Encapsulated. + +// DescribeAlidnsCloudGtmAddress <<< Encapsulated get interface for Alidns CloudGtmAddress. + +func (s *AlidnsServiceV2) DescribeAlidnsCloudGtmAddress(id string) (object map[string]interface{}, err error) { + client := s.client + var request map[string]interface{} + var response map[string]interface{} + var query map[string]interface{} + request = make(map[string]interface{}) + query = make(map[string]interface{}) + request["AddressId"] = id + + action := "DescribeCloudGtmAddress" + request["ClientToken"] = buildClientToken(action) + + wait := incrementalWait(3*time.Second, 5*time.Second) + err = resource.Retry(1*time.Minute, func() *resource.RetryError { + response, err = client.RpcPost("Alidns", "2015-01-09", action, query, request, true) + request["ClientToken"] = buildClientToken(action) + + if err != nil { + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil + }) + addDebug(action, response, request) + if err != nil { + return object, WrapErrorf(err, DefaultErrorMsg, id, action, AlibabaCloudSdkGoERROR) + } + + currentStatus := response["AddressId"] + if currentStatus == nil { + return object, WrapErrorf(NotFoundErr("CloudGtmAddress", id), NotFoundMsg, response) + } + + return response, nil +} + +func (s *AlidnsServiceV2) AlidnsCloudGtmAddressStateRefreshFunc(id string, field string, failStates []string) resource.StateRefreshFunc { + return s.AlidnsCloudGtmAddressStateRefreshFuncWithApi(id, field, failStates, s.DescribeAlidnsCloudGtmAddress) +} + +func (s *AlidnsServiceV2) AlidnsCloudGtmAddressStateRefreshFuncWithApi(id string, field string, failStates []string, call func(id string) (map[string]interface{}, error)) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + object, err := call(id) + if err != nil { + if NotFoundError(err) { + return object, "", nil + } + return nil, "", WrapError(err) + } + v, err := jsonpath.Get(field, object) + currentStatus := fmt.Sprint(v) + + if strings.HasPrefix(field, "#") { + v, _ := jsonpath.Get(strings.TrimPrefix(field, "#"), object) + if v != nil { + currentStatus = "#CHECKSET" + } + } + + for _, failState := range failStates { + if currentStatus == failState { + return object, currentStatus, WrapError(Error(FailedToReachTargetStatus, currentStatus)) + } + } + return object, currentStatus, nil + } +} + +// DescribeAlidnsCloudGtmAddress >>> Encapsulated. diff --git a/website/docs/r/alidns_cloud_gtm_address.html.markdown b/website/docs/r/alidns_cloud_gtm_address.html.markdown new file mode 100644 index 000000000000..d3c284b259b2 --- /dev/null +++ b/website/docs/r/alidns_cloud_gtm_address.html.markdown @@ -0,0 +1,177 @@ +--- +subcategory: "Alidns" +layout: "alicloud" +page_title: "Alicloud: alicloud_alidns_cloud_gtm_address" +description: |- + Provides a Alicloud Alidns Cloud Gtm Address resource. +--- + +# alicloud_alidns_cloud_gtm_address + +Provides a Alidns Cloud Gtm Address resource. + +A Cloud GTM address represents an individual service endpoint (IPv4, IPv6, or domain name) that can be grouped into a Cloud GTM address pool. Each address carries its own health-check configuration — one or more probe tasks that reference Cloud GTM monitor templates — so that Cloud GTM can determine whether the endpoint is available before returning it in DNS responses. + +For information about Alidns Cloud Gtm Address and how to use it, see [What is Cloud Gtm Address](https://next.api.alibabacloud.com/document/Alidns/2015-01-09/CreateCloudGtmAddress). + +-> **NOTE:** Available since v1.277.0. + +## Example Usage + +Basic Usage + +```terraform +variable "name" { + default = "terraform-example" +} + +provider "alicloud" { + region = "cn-hangzhou" +} + +resource "alicloud_alidns_cloud_gtm_monitor_template" "tcp" { + name = "${var.name}-tcp" + protocol = "tcp" + ip_version = "IPv4" + interval = "60" + timeout = "3000" + evaluation_count = 1 + failure_rate = 50 + extend_info = "{}" + + isp_city_nodes { + city_code = "357" + isp_code = "465" + } + isp_city_nodes { + city_code = "738" + isp_code = "465" + } +} + +resource "alicloud_alidns_cloud_gtm_monitor_template" "https" { + name = "${var.name}-https" + protocol = "https" + ip_version = "IPv4" + interval = "60" + timeout = "2000" + evaluation_count = 1 + failure_rate = 50 + extend_info = jsonencode({ + code = 400 + followRedirect = true + path = "/" + sni = false + }) + + isp_city_nodes { + city_code = "357" + isp_code = "465" + } + isp_city_nodes { + city_code = "738" + isp_code = "465" + } +} + +resource "alicloud_alidns_cloud_gtm_monitor_template" "ping" { + name = "${var.name}-ping" + protocol = "ping" + ip_version = "IPv4" + interval = "60" + timeout = "3000" + evaluation_count = 1 + failure_rate = 50 + extend_info = jsonencode({ + packetNum = 20 + packetLossRate = 10 + }) + + isp_city_nodes { + city_code = "357" + isp_code = "465" + } + isp_city_nodes { + city_code = "738" + isp_code = "465" + } +} + +resource "alicloud_alidns_cloud_gtm_address" "default" { + name = var.name + type = "IPv4" + address = "1.1.1.1" + enable_status = "enable" + available_mode = "manual" + manual_available_status = "available" + health_judgement = "all_ok" + remark = "terraform-example-remark" + + health_tasks { + template_id = alicloud_alidns_cloud_gtm_monitor_template.ping.id + } + + health_tasks { + port = 53 + template_id = alicloud_alidns_cloud_gtm_monitor_template.tcp.id + } + + health_tasks { + port = 443 + template_id = alicloud_alidns_cloud_gtm_monitor_template.https.id + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the address. Used to identify the address in the Cloud GTM console. +* `type` - (Required, ForceNew) The address type. Valid values: `IPv4`, `IPv6`, `domain`. +* `address` - (Required) The address value. Must match `type`: an IPv4 address, an IPv6 address, or a domain name. +* `enable_status` - (Required) Whether the address participates in DNS resolution. Valid values: + * `enable` - The address participates in resolution when its health check is normal. + * `disable` - The address does not participate in resolution regardless of health status. +* `available_mode` - (Required) How the availability of the address is determined. Valid values: + * `auto` - Availability is computed from the attached health-check tasks. + * `manual` - Availability is set explicitly via `manual_available_status`; health-check results are informational only. +* `manual_available_status` - (Optional) The manually-set availability status. Only meaningful when `available_mode` is `manual`. Valid values: `available`, `unavailable`. +* `health_judgement` - (Required) The rule used to judge overall health when the address has multiple health-check tasks. Valid values: + * `any_ok` - Any task reports healthy. + * `all_ok` - All tasks report healthy. + * `p30_ok` - At least 30% of tasks report healthy. + * `p50_ok` - At least 50% of tasks report healthy. + * `p70_ok` - At least 70% of tasks report healthy. +* `health_tasks` - (Optional, Set) The health-check tasks attached to this address. Each task references a Cloud GTM monitor template. See [`health_tasks`](#health_tasks) below. +* `remark` - (Optional) The remark of the address. Passing an empty value clears the existing remark. + +### `health_tasks` + +The `health_tasks` block supports: + +* `template_id` - (Optional) The ID of the Cloud GTM monitor template to probe this address with. Usually referenced as `alicloud_alidns_cloud_gtm_monitor_template..id`. +* `port` - (Optional, Int) The port to probe. If omitted, the default port of the template's protocol is used (for example, 80 for HTTP, 443 for HTTPS). + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the address. It is the same as the `address_id` returned by the API. +* `create_time` - The creation time of the address. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts) for certain actions: + +* `create` - (Defaults to 5 mins) Used when creating the Cloud Gtm Address. +* `update` - (Defaults to 5 mins) Used when updating the Cloud Gtm Address. +* `delete` - (Defaults to 5 mins) Used when deleting the Cloud Gtm Address. + +## Import + +Alidns Cloud Gtm Address can be imported using the id, e.g. + +```shell +$ terraform import alicloud_alidns_cloud_gtm_address.example +```