diff --git a/.changelog/3163.txt b/.changelog/3163.txt new file mode 100644 index 0000000000..988034a8a9 --- /dev/null +++ b/.changelog/3163.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +tencentcloud_clb_customized_config_attachment +``` \ No newline at end of file diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index 2cfb479fc6..dae3bad123 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -1293,6 +1293,7 @@ func Provider() *schema.Provider { "tencentcloud_clb_log_topic": clb.ResourceTencentCloudClbLogTopic(), "tencentcloud_clb_customized_config": clb.ResourceTencentCloudClbCustomizedConfig(), "tencentcloud_clb_customized_config_v2": clb.ResourceTencentCloudClbCustomizedConfigV2(), + "tencentcloud_clb_customized_config_attachment": clb.ResourceTencentCloudClbCustomizedConfigAttachment(), "tencentcloud_clb_snat_ip": clb.ResourceTencentCloudClbSnatIp(), "tencentcloud_clb_function_targets_attachment": clb.ResourceTencentCloudClbFunctionTargetsAttachment(), "tencentcloud_clb_instance_mix_ip_target_config": clb.ResourceTencentCloudClbInstanceMixIpTargetConfig(), diff --git a/tencentcloud/provider.md b/tencentcloud/provider.md index 4ba242934a..f56b0a930b 100644 --- a/tencentcloud/provider.md +++ b/tencentcloud/provider.md @@ -402,6 +402,7 @@ tencentcloud_clb_log_set tencentcloud_clb_log_topic tencentcloud_clb_customized_config tencentcloud_clb_customized_config_v2 +tencentcloud_clb_customized_config_attachment tencentcloud_clb_snat_ip tencentcloud_clb_function_targets_attachment tencentcloud_clb_instance_sla_config diff --git a/tencentcloud/services/clb/resource_tc_clb_customized_config_attachment.go b/tencentcloud/services/clb/resource_tc_clb_customized_config_attachment.go new file mode 100644 index 0000000000..91b6327fe4 --- /dev/null +++ b/tencentcloud/services/clb/resource_tc_clb_customized_config_attachment.go @@ -0,0 +1,364 @@ +package clb + +import ( + "context" + "fmt" + "log" + + "github.com/pkg/errors" + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + clb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317" +) + +func ResourceTencentCloudClbCustomizedConfigAttachment() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudClbCustomizedConfigAttachmentCreate, + Read: resourceTencentCloudClbCustomizedConfigAttachmentRead, + Update: resourceTencentCloudClbCustomizedConfigAttachmentUpdate, + Delete: resourceTencentCloudClbCustomizedConfigAttachmentDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "config_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "ID of Customized Config.", + }, + "bind_list": { + Type: schema.TypeSet, + Required: true, + Description: "Associated server or location.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "load_balancer_id": { + Type: schema.TypeString, + Required: true, + Description: "Clb ID.", + }, + "listener_id": { + Type: schema.TypeString, + Required: true, + Description: "Listener ID.", + }, + "domain": { + Type: schema.TypeString, + Required: true, + Description: "Domain.", + }, + "location_id": { + Type: schema.TypeString, + Optional: true, + Description: "Location ID.", + }, + }, + }, + }, + }, + } +} + +func resourceTencentCloudClbCustomizedConfigAttachmentCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_clb_customized_config_attachment.create")() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + request = clb.NewAssociateCustomizedConfigRequest() + configId string + ) + + if v, ok := d.GetOk("config_id"); ok { + request.UconfigId = helper.String(v.(string)) + configId = v.(string) + } + + if v, ok := d.GetOk("bind_list"); ok { + for _, item := range v.(*schema.Set).List() { + bindItem := clb.BindItem{} + dMap := item.(map[string]interface{}) + if v, ok := dMap["load_balancer_id"]; ok { + bindItem.LoadBalancerId = helper.String(v.(string)) + } + + if v, ok := dMap["listener_id"]; ok { + bindItem.ListenerId = helper.String(v.(string)) + } + + if v, ok := dMap["domain"]; ok { + bindItem.Domain = helper.String(v.(string)) + } + + if v, ok := dMap["location_id"]; ok { + bindItem.LocationId = helper.String(v.(string)) + } + + request.BindList = append(request.BindList, &bindItem) + } + } + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient().AssociateCustomizedConfig(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.RequestId == nil { + return resource.NonRetryableError(fmt.Errorf("Associate CLB Customized Config Failed, Response is nil.")) + } + + requestId := *result.Response.RequestId + retryErr := waitForTaskFinish(requestId, meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient()) + if retryErr != nil { + return tccommon.RetryError(errors.WithStack(retryErr)) + } + } + + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s Associate CLB Customized Config Failed, reason:%+v", logId, err) + return err + } + + d.SetId(configId) + + return resourceTencentCloudClbCustomizedConfigAttachmentRead(d, meta) +} + +func resourceTencentCloudClbCustomizedConfigAttachmentRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_clb_customized_config_attachment.read")() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + clbService = ClbService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + configId = d.Id() + ) + + bindList, err := clbService.DescribeDescribeCustomizedConfigAssociateListById(ctx, configId) + if err != nil { + return err + } + + if bindList == nil || len(bindList) == 0 { + d.SetId("") + return fmt.Errorf("resource `tencentcloud_clb_customized_config_attachment` %s does not exist", configId) + } + + _ = d.Set("config_id", configId) + + tmpList := make([]map[string]interface{}, 0, len(bindList)) + for _, item := range bindList { + dMap := make(map[string]interface{}) + if item.LoadBalancerId != nil { + dMap["load_balancer_id"] = *item.LoadBalancerId + } + + if item.ListenerId != nil { + dMap["listener_id"] = *item.ListenerId + } + + if item.Domain != nil { + dMap["domain"] = *item.Domain + } + + if item.LocationId != nil { + dMap["location_id"] = *item.LocationId + } + + tmpList = append(tmpList, dMap) + } + + _ = d.Set("bind_list", tmpList) + + return nil +} + +func resourceTencentCloudClbCustomizedConfigAttachmentUpdate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_clb_customized_config_attachment.delete")() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + id = d.Id() + ) + + if d.HasChange("bind_list") { + oldInterface, newInterface := d.GetChange("bind_list") + olds := oldInterface.(*schema.Set) + news := newInterface.(*schema.Set) + remove := olds.Difference(news).List() + add := news.Difference(olds).List() + if len(remove) > 0 { + request := clb.NewDisassociateCustomizedConfigRequest() + for _, item := range remove { + bindItem := clb.BindItem{} + dMap := item.(map[string]interface{}) + if v, ok := dMap["load_balancer_id"]; ok { + bindItem.LoadBalancerId = helper.String(v.(string)) + } + + if v, ok := dMap["listener_id"]; ok { + bindItem.ListenerId = helper.String(v.(string)) + } + + if v, ok := dMap["domain"]; ok { + bindItem.Domain = helper.String(v.(string)) + } + + if v, ok := dMap["location_id"]; ok { + bindItem.LocationId = helper.String(v.(string)) + } + + request.BindList = append(request.BindList, &bindItem) + } + + request.UconfigId = helper.String(id) + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient().DisassociateCustomizedConfig(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.RequestId == nil { + return resource.NonRetryableError(fmt.Errorf("Disassociate CLB Customized Config Failed, Response is nil.")) + } + + requestId := *result.Response.RequestId + retryErr := waitForTaskFinish(requestId, meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient()) + if retryErr != nil { + return tccommon.RetryError(errors.WithStack(retryErr)) + } + } + + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s Disassociate CLB Customized Config Failed, reason:%+v", logId, err) + return err + } + } + + if len(add) > 0 { + request := clb.NewAssociateCustomizedConfigRequest() + request.UconfigId = helper.String(id) + for _, item := range add { + bindItem := clb.BindItem{} + dMap := item.(map[string]interface{}) + if v, ok := dMap["load_balancer_id"]; ok { + bindItem.LoadBalancerId = helper.String(v.(string)) + } + + if v, ok := dMap["listener_id"]; ok { + bindItem.ListenerId = helper.String(v.(string)) + } + + if v, ok := dMap["domain"]; ok { + bindItem.Domain = helper.String(v.(string)) + } + + if v, ok := dMap["location_id"]; ok { + bindItem.LocationId = helper.String(v.(string)) + } + + request.BindList = append(request.BindList, &bindItem) + } + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient().AssociateCustomizedConfig(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.RequestId == nil { + return resource.NonRetryableError(fmt.Errorf("Associate CLB Customized Config Failed, Response is nil.")) + } + + requestId := *result.Response.RequestId + retryErr := waitForTaskFinish(requestId, meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient()) + if retryErr != nil { + return tccommon.RetryError(errors.WithStack(retryErr)) + } + } + + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s Associate CLB Customized Config Failed, reason:%+v", logId, err) + return err + } + } + } + + return resourceTencentCloudClbCustomizedConfigAttachmentRead(d, meta) +} + +func resourceTencentCloudClbCustomizedConfigAttachmentDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_clb_customized_config_attachment.delete")() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + request = clb.NewDisassociateCustomizedConfigRequest() + id = d.Id() + ) + + request.UconfigId = helper.String(id) + if v, ok := d.GetOk("bind_list"); ok { + for _, item := range v.(*schema.Set).List() { + bindItem := clb.BindItem{} + dMap := item.(map[string]interface{}) + if v, ok := dMap["load_balancer_id"]; ok { + bindItem.LoadBalancerId = helper.String(v.(string)) + } + + if v, ok := dMap["listener_id"]; ok { + bindItem.ListenerId = helper.String(v.(string)) + } + + if v, ok := dMap["domain"]; ok { + bindItem.Domain = helper.String(v.(string)) + } + + if v, ok := dMap["location_id"]; ok { + bindItem.LocationId = helper.String(v.(string)) + } + + request.BindList = append(request.BindList, &bindItem) + } + } + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient().DisassociateCustomizedConfig(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.RequestId == nil { + return resource.NonRetryableError(fmt.Errorf("Disassociate CLB Customized Config Failed, Response is nil.")) + } + + requestId := *result.Response.RequestId + retryErr := waitForTaskFinish(requestId, meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient()) + if retryErr != nil { + return tccommon.RetryError(errors.WithStack(retryErr)) + } + } + + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s Disassociate CLB Customized Config Failed, reason:%+v", logId, err) + return err + } + + return nil +} diff --git a/tencentcloud/services/clb/resource_tc_clb_customized_config_attachment.md b/tencentcloud/services/clb/resource_tc_clb_customized_config_attachment.md new file mode 100644 index 0000000000..51fdd839db --- /dev/null +++ b/tencentcloud/services/clb/resource_tc_clb_customized_config_attachment.md @@ -0,0 +1,65 @@ +Provides a resource to create a CLB customized config attachment. + +~> **NOTE:** This resource must exclusive in one CLB customized config attachment, do not declare additional rule resources of this CLB customized config attachment elsewhere. + +Example Usage + +If config_type is SERVER + +```hcl +resource "tencentcloud_clb_customized_config_v2" "example" { + config_content = "client_max_body_size 224M;\r\nclient_body_timeout 60s;" + config_name = "tf-example" + config_type = "SERVER" +} + +resource "tencentcloud_clb_customized_config_attachment" "example" { + config_id = tencentcloud_clb_customized_config_v2.example.config_id + bind_list { + load_balancer_id = "lb-g1miv1ok" + listener_id = "lbl-9bsa90io" + domain = "demo1.com" + } + + bind_list { + load_balancer_id = "lb-g1miv1ok" + listener_id = "lbl-qfljudr4" + domain = "demo2.com" + } +} +``` + +If config_type is LOCATION + +```hcl +resource "tencentcloud_clb_customized_config_v2" "example" { + config_content = "client_max_body_size 224M;\r\nclient_body_timeout 60s;" + config_name = "tf-example" + config_type = "LOCATION" +} + +resource "tencentcloud_clb_customized_config_attachment" "example" { + config_id = tencentcloud_clb_customized_config_v2.example.config_id + bind_list { + load_balancer_id = "lb-g1miv1ok" + listener_id = "lbl-9bsa90io" + domain = "demo1.com" + location_id = "loc-5he3og2u" + } + + bind_list { + load_balancer_id = "lb-g1miv1ok" + listener_id = "lbl-qfljudr4" + domain = "demo2.com" + location_id = "loc-0oxl4lfw" + } +} +``` + +Import + +CLB customized config attachment can be imported using the id, e.g. + +``` +$ terraform import tencentcloud_clb_customized_config_attachment.example pz-ivj39268 +``` \ No newline at end of file diff --git a/tencentcloud/services/clb/resource_tc_clb_customized_config_attachment_test.go b/tencentcloud/services/clb/resource_tc_clb_customized_config_attachment_test.go new file mode 100644 index 0000000000..dd2749949f --- /dev/null +++ b/tencentcloud/services/clb/resource_tc_clb_customized_config_attachment_test.go @@ -0,0 +1,81 @@ +package clb_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudClbCustomizedConfigAttachment_basic(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { tcacctest.AccPreCheck(t) }, + Providers: tcacctest.AccProviders, + CheckDestroy: testAccCheckClbLogsetDestroy, + Steps: []resource.TestStep{ + { + Config: testAccClbCustomizedConfigAttachmentCreate, + Check: resource.ComposeTestCheckFunc( + testAccCheckClbLogsetExists("tencentcloud_clb_customized_config_attachment.example"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_customized_config_attachment.example", "config_id"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_customized_config_attachment.example", "bind_list"), + ), + }, + { + Config: testAccClbCustomizedConfigAttachmentUpdate, + Check: resource.ComposeTestCheckFunc( + testAccCheckClbLogsetExists("tencentcloud_clb_customized_config_attachment.example"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_customized_config_attachment.example", "config_id"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_customized_config_attachment.example", "bind_list"), + ), + }, + { + ResourceName: "tencentcloud_clb_customized_config_attachment.example", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccClbCustomizedConfigAttachmentCreate = ` +resource "tencentcloud_clb_customized_config_v2" "example" { + config_content = "client_max_body_size 224M;\r\nclient_body_timeout 60s;" + config_name = "tf-example" + config_type = "SERVER" +} + +resource "tencentcloud_clb_customized_config_attachment" "example" { + config_id = tencentcloud_clb_customized_config_v2.example.config_id + bind_list { + load_balancer_id = "lb-g1miv1ok" + listener_id = "lbl-9bsa90io" + domain = "demo1.com" + } + + bind_list { + load_balancer_id = "lb-g1miv1ok" + listener_id = "lbl-qfljudr4" + domain = "demo2.com" + } +} +` + +const testAccClbCustomizedConfigAttachmentUpdate = ` +resource "tencentcloud_clb_customized_config_v2" "example" { + config_content = "client_max_body_size 224M;\r\nclient_body_timeout 60s;" + config_name = "tf-example" + config_type = "SERVER" +} + +resource "tencentcloud_clb_customized_config_attachment" "example" { + config_id = tencentcloud_clb_customized_config_v2.example.config_id + bind_list { + load_balancer_id = "lb-g1miv1ok" + listener_id = "lbl-9bsa90io" + domain = "demo1.com" + } +} +` diff --git a/tencentcloud/services/clb/resource_tc_clb_customized_config_v2.go b/tencentcloud/services/clb/resource_tc_clb_customized_config_v2.go index d4ad95583e..982839edb6 100644 --- a/tencentcloud/services/clb/resource_tc_clb_customized_config_v2.go +++ b/tencentcloud/services/clb/resource_tc_clb_customized_config_v2.go @@ -37,7 +37,7 @@ func ResourceTencentCloudClbCustomizedConfigV2() *schema.Resource { Required: true, ForceNew: true, ValidateFunc: tccommon.ValidateAllowedStringValue([]string{"CLB", "SERVER", "LOCATION"}), - Description: "Type of Customized Config. Valid values: `CLB`, `SERVER` and `LOCATION`.", + Description: "Type of Customized Config. Valid values: `SERVER` and `LOCATION`.", }, "config_content": { Type: schema.TypeString, diff --git a/tencentcloud/services/clb/resource_tc_clb_customized_config_v2.md b/tencentcloud/services/clb/resource_tc_clb_customized_config_v2.md index 39d6aab0b0..888edc2324 100644 --- a/tencentcloud/services/clb/resource_tc_clb_customized_config_v2.md +++ b/tencentcloud/services/clb/resource_tc_clb_customized_config_v2.md @@ -2,13 +2,27 @@ Provides a resource to create a CLB customized V2 config. Example Usage -Create clb customized V2 config without CLB instance +If config_type is SERVER ```hcl resource "tencentcloud_clb_customized_config_v2" "example" { config_content = "client_max_body_size 224M;\r\nclient_body_timeout 60s;" config_name = "tf-example" - config_type = "CLB" + config_type = "SERVER" +} + +output "configId" { + value = tencentcloud_clb_customized_config_v2.example.config_id +} +``` + +If config_type is LOCATION + +```hcl +resource "tencentcloud_clb_customized_config_v2" "example" { + config_content = "client_max_body_size 224M;\r\nclient_body_timeout 60s;" + config_name = "tf-example" + config_type = "LOCATION" } output "configId" { @@ -21,5 +35,9 @@ Import CLB customized V2 config can be imported using the id, e.g. ``` -$ terraform import tencentcloud_clb_customized_config_v2.example pz-diowqstq +$ terraform import tencentcloud_clb_customized_config_v2.example pz-diowqstq#SERVER + +Or + +$ terraform import tencentcloud_clb_customized_config_v2.example pz-4r10y4b2#LOCATION ``` \ No newline at end of file diff --git a/tencentcloud/services/clb/service_tencentcloud_clb.go b/tencentcloud/services/clb/service_tencentcloud_clb.go index 98b95776e5..a48787736d 100644 --- a/tencentcloud/services/clb/service_tencentcloud_clb.go +++ b/tencentcloud/services/clb/service_tencentcloud_clb.go @@ -2527,3 +2527,40 @@ func waitTaskReady(ctx context.Context, client *clb.Client, reqeustId string) er } return nil } + +func (me *ClbService) DescribeDescribeCustomizedConfigAssociateListById(ctx context.Context, configId string) (bindList []*clb.BindDetailItem, errRet error) { + logId := tccommon.GetLogId(ctx) + request := clb.NewDescribeCustomizedConfigAssociateListRequest() + request.UconfigId = helper.String(configId) + + var ( + offset int64 = 0 + limit int64 = 100 + ) + + for { + request.Offset = &offset + request.Limit = &limit + ratelimit.Check(request.GetAction()) + response, err := me.client.UseClbClient().DescribeCustomizedConfigAssociateList(request) + if err != nil { + errRet = err + return + } + + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + if response == nil || len(response.Response.BindList) < 1 { + break + } + + bindList = append(bindList, response.Response.BindList...) + if len(response.Response.BindList) < int(limit) { + break + } + + offset += limit + } + + return +} diff --git a/website/docs/r/clb_customized_config_attachment.html.markdown b/website/docs/r/clb_customized_config_attachment.html.markdown new file mode 100644 index 0000000000..124d463b47 --- /dev/null +++ b/website/docs/r/clb_customized_config_attachment.html.markdown @@ -0,0 +1,99 @@ +--- +subcategory: "Cloud Load Balancer(CLB)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_clb_customized_config_attachment" +sidebar_current: "docs-tencentcloud-resource-clb_customized_config_attachment" +description: |- + Provides a resource to create a CLB customized config attachment. +--- + +# tencentcloud_clb_customized_config_attachment + +Provides a resource to create a CLB customized config attachment. + +~> **NOTE:** This resource must exclusive in one CLB customized config attachment, do not declare additional rule resources of this CLB customized config attachment elsewhere. + +## Example Usage + +### If config_type is SERVER + +```hcl +resource "tencentcloud_clb_customized_config_v2" "example" { + config_content = "client_max_body_size 224M;\r\nclient_body_timeout 60s;" + config_name = "tf-example" + config_type = "SERVER" +} + +resource "tencentcloud_clb_customized_config_attachment" "example" { + config_id = tencentcloud_clb_customized_config_v2.example.config_id + bind_list { + load_balancer_id = "lb-g1miv1ok" + listener_id = "lbl-9bsa90io" + domain = "demo1.com" + } + + bind_list { + load_balancer_id = "lb-g1miv1ok" + listener_id = "lbl-qfljudr4" + domain = "demo2.com" + } +} +``` + +### If config_type is LOCATION + +```hcl +resource "tencentcloud_clb_customized_config_v2" "example" { + config_content = "client_max_body_size 224M;\r\nclient_body_timeout 60s;" + config_name = "tf-example" + config_type = "LOCATION" +} + +resource "tencentcloud_clb_customized_config_attachment" "example" { + config_id = tencentcloud_clb_customized_config_v2.example.config_id + bind_list { + load_balancer_id = "lb-g1miv1ok" + listener_id = "lbl-9bsa90io" + domain = "demo1.com" + location_id = "loc-5he3og2u" + } + + bind_list { + load_balancer_id = "lb-g1miv1ok" + listener_id = "lbl-qfljudr4" + domain = "demo2.com" + location_id = "loc-0oxl4lfw" + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `bind_list` - (Required, Set) Associated server or location. +* `config_id` - (Required, String, ForceNew) ID of Customized Config. + +The `bind_list` object supports the following: + +* `domain` - (Required, String) Domain. +* `listener_id` - (Required, String) Listener ID. +* `load_balancer_id` - (Required, String) Clb ID. +* `location_id` - (Optional, String) Location ID. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. + + + +## Import + +CLB customized config attachment can be imported using the id, e.g. + +``` +$ terraform import tencentcloud_clb_customized_config_attachment.example pz-ivj39268 +``` + diff --git a/website/docs/r/clb_customized_config_v2.html.markdown b/website/docs/r/clb_customized_config_v2.html.markdown index 40ccc4bb66..630c990a86 100644 --- a/website/docs/r/clb_customized_config_v2.html.markdown +++ b/website/docs/r/clb_customized_config_v2.html.markdown @@ -13,13 +13,27 @@ Provides a resource to create a CLB customized V2 config. ## Example Usage -### Create clb customized V2 config without CLB instance +### If config_type is SERVER ```hcl resource "tencentcloud_clb_customized_config_v2" "example" { config_content = "client_max_body_size 224M;\r\nclient_body_timeout 60s;" config_name = "tf-example" - config_type = "CLB" + config_type = "SERVER" +} + +output "configId" { + value = tencentcloud_clb_customized_config_v2.example.config_id +} +``` + +### If config_type is LOCATION + +```hcl +resource "tencentcloud_clb_customized_config_v2" "example" { + config_content = "client_max_body_size 224M;\r\nclient_body_timeout 60s;" + config_name = "tf-example" + config_type = "LOCATION" } output "configId" { @@ -33,7 +47,7 @@ The following arguments are supported: * `config_content` - (Required, String) Content of Customized Config. * `config_name` - (Required, String) Name of Customized Config. -* `config_type` - (Required, String, ForceNew) Type of Customized Config. Valid values: `CLB`, `SERVER` and `LOCATION`. +* `config_type` - (Required, String, ForceNew) Type of Customized Config. Valid values: `SERVER` and `LOCATION`. ## Attributes Reference @@ -50,6 +64,10 @@ In addition to all arguments above, the following attributes are exported: CLB customized V2 config can be imported using the id, e.g. ``` -$ terraform import tencentcloud_clb_customized_config_v2.example pz-diowqstq +$ terraform import tencentcloud_clb_customized_config_v2.example pz-diowqstq#SERVER + +Or + +$ terraform import tencentcloud_clb_customized_config_v2.example pz-4r10y4b2#LOCATION ``` diff --git a/website/tencentcloud.erb b/website/tencentcloud.erb index 0e1c76f86e..4201333c13 100644 --- a/website/tencentcloud.erb +++ b/website/tencentcloud.erb @@ -1422,6 +1422,9 @@
  • tencentcloud_clb_customized_config
  • +
  • + tencentcloud_clb_customized_config_attachment +
  • tencentcloud_clb_customized_config_v2