From 85369f290eb5272278c9013b17ee5b644629602a Mon Sep 17 00:00:00 2001 From: arunma Date: Fri, 14 Jun 2024 18:06:20 +0800 Subject: [PATCH 1/3] fix(teo): [118016440] support ipv6 --- .../resource_tc_teo_acceleration_domain.go | 98 ++++++++++++++----- .../services/teo/service_tencentcloud_teo.go | 5 +- .../r/teo_acceleration_domain.html.markdown | 4 + 3 files changed, 80 insertions(+), 27 deletions(-) diff --git a/tencentcloud/services/teo/resource_tc_teo_acceleration_domain.go b/tencentcloud/services/teo/resource_tc_teo_acceleration_domain.go index e3d6b301f2..4fb11f438a 100644 --- a/tencentcloud/services/teo/resource_tc_teo_acceleration_domain.go +++ b/tencentcloud/services/teo/resource_tc_teo_acceleration_domain.go @@ -100,6 +100,30 @@ func ResourceTencentCloudTeoAccelerationDomain() *schema.Resource { Computed: true, Description: "CNAME address.", }, + + "origin_protocol": { + Type: schema.TypeString, + Optional: true, + Description: "Origin return protocol, possible values are: `FOLLOW`: protocol follow; `HTTP`: HTTP protocol back to source; `HTTPS`: HTTPS protocol back to source. If not filled in, the default is: `FOLLOW`.", + }, + + "http_origin_port": { + Type: schema.TypeInt, + Optional: true, + Description: "HTTP back-to-origin port, the value is 1-65535, effective when OriginProtocol=FOLLOW/HTTP, if not filled in, the default value is 80.", + }, + + "https_origin_port": { + Type: schema.TypeInt, + Optional: true, + Description: "HTTPS back-to-origin port. The value range is 1-65535. It takes effect when OriginProtocol=FOLLOW/HTTPS. If it is not filled in, the default value is 443.", + }, + + "ipv6_status": { + Type: schema.TypeString, + Optional: true, + Description: "IPv6 status, the value is: `follow`: follow the site IPv6 configuration; `on`: on; `off`: off. If not filled in, the default is: `follow`.", + }, }, } } @@ -275,6 +299,22 @@ func resourceTencentCloudTeoAccelerationDomainRead(d *schema.ResourceData, meta _ = d.Set("origin_info", []interface{}{originDetailMap}) } + if respData.OriginProtocol != nil { + _ = d.Set("origin_protocol", respData.OriginProtocol) + } + + if respData.HttpOriginPort != nil { + _ = d.Set("http_origin_port", respData.HttpOriginPort) + } + + if respData.HttpsOriginPort != nil { + _ = d.Set("http_origin_port", respData.HttpsOriginPort) + } + + if respData.IPv6Status != nil { + _ = d.Set("ipv6_status", respData.IPv6Status) + } + return nil } @@ -286,6 +326,12 @@ func resourceTencentCloudTeoAccelerationDomainUpdate(d *schema.ResourceData, met ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + immutableArgs := []string{"https_origin_port"} + for _, v := range immutableArgs { + if d.HasChange(v) { + return fmt.Errorf("argument `%s` cannot be changed", v) + } + } idSplit := strings.Split(d.Id(), tccommon.FILED_SP) if len(idSplit) != 2 { return fmt.Errorf("id is broken,%s", d.Id()) @@ -294,7 +340,7 @@ func resourceTencentCloudTeoAccelerationDomainUpdate(d *schema.ResourceData, met domainName := idSplit[1] needChange := false - mutableArgs := []string{"origin_info"} + mutableArgs := []string{"origin_info", "origin_protocol", "http_origin_port", "http_origin_port", "ipv6_status"} for _, v := range mutableArgs { if d.HasChange(v) { needChange = true @@ -305,9 +351,9 @@ func resourceTencentCloudTeoAccelerationDomainUpdate(d *schema.ResourceData, met if needChange { request := teo.NewModifyAccelerationDomainRequest() - request.ZoneId = &zoneId + request.ZoneId = helper.String(zoneId) - request.DomainName = &domainName + request.DomainName = helper.String(domainName) if originInfoMap, ok := helper.InterfacesHeadMap(d, "origin_info"); ok { originInfo := teo.OriginInfo{} @@ -339,6 +385,22 @@ func resourceTencentCloudTeoAccelerationDomainUpdate(d *schema.ResourceData, met request.OriginInfo = &originInfo } + if v, ok := d.GetOk("origin_protocol"); ok { + request.OriginProtocol = helper.String(v.(string)) + } + + if v, ok := d.GetOkExists("http_origin_port"); ok { + request.HttpOriginPort = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOkExists("http_origin_port"); ok { + request.HttpsOriginPort = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOk("ipv6_status"); ok { + request.IPv6Status = helper.String(v.(string)) + } + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTeoClient().ModifyAccelerationDomainWithContext(ctx, request) if e != nil { @@ -366,9 +428,9 @@ func resourceTencentCloudTeoAccelerationDomainUpdate(d *schema.ResourceData, met if needChange1 { request1 := teo.NewModifyAccelerationDomainStatusesRequest() - request1.ZoneId = &zoneId + request1.ZoneId = helper.String(zoneId) - request1.DomainNames = []*string{&domainName} + request1.DomainNames = []*string{helper.String(domainName)} if v, ok := d.GetOk("status"); ok { request1.Status = helper.String(v.(string)) @@ -415,16 +477,9 @@ func resourceTencentCloudTeoAccelerationDomainDelete(d *schema.ResourceData, met response = teo.NewModifyAccelerationDomainStatusesResponse() ) - if v, ok := d.GetOk("zone_id"); ok { - zoneId = v.(string) - } - if v, ok := d.GetOk("domain_name"); ok { - domainName = v.(string) - } - - request.ZoneId = &zoneId + request.ZoneId = helper.String(zoneId) - request.DomainNames = []*string{&domainName} + request.DomainNames = []*string{helper.String(domainName)} status := "offline" request.Status = &status @@ -440,7 +495,7 @@ func resourceTencentCloudTeoAccelerationDomainDelete(d *schema.ResourceData, met return nil }) if err != nil { - log.Printf("[CRITAL]%s create teo acceleration domain failed, reason:%+v", logId, err) + log.Printf("[CRITAL]%s delete teo acceleration domain failed, reason:%+v", logId, err) return err } @@ -454,16 +509,9 @@ func resourceTencentCloudTeoAccelerationDomainDelete(d *schema.ResourceData, met response1 = teo.NewDeleteAccelerationDomainsResponse() ) - if v, ok := d.GetOk("zone_id"); ok { - zoneId = v.(string) - } - if v, ok := d.GetOk("domain_name"); ok { - domainName = v.(string) - } - - request1.ZoneId = &zoneId + request1.ZoneId = helper.String(zoneId) - request1.DomainNames = []*string{&domainName} + request1.DomainNames = []*string{helper.String(domainName)} err = resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTeoClient().DeleteAccelerationDomainsWithContext(ctx, request1) @@ -476,7 +524,7 @@ func resourceTencentCloudTeoAccelerationDomainDelete(d *schema.ResourceData, met return nil }) if err != nil { - log.Printf("[CRITAL]%s create teo acceleration domain failed, reason:%+v", logId, err) + log.Printf("[CRITAL]%s delete teo acceleration domain failed, reason:%+v", logId, err) return err } diff --git a/tencentcloud/services/teo/service_tencentcloud_teo.go b/tencentcloud/services/teo/service_tencentcloud_teo.go index 68d34d3146..40433cba28 100644 --- a/tencentcloud/services/teo/service_tencentcloud_teo.go +++ b/tencentcloud/services/teo/service_tencentcloud_teo.go @@ -688,10 +688,10 @@ func (me *TeoService) DescribeTeoAccelerationDomainById(ctx context.Context, zon logId := tccommon.GetLogId(ctx) request := teo.NewDescribeAccelerationDomainsRequest() - request.ZoneId = &zoneId + request.ZoneId = helper.String(zoneId) advancedFilter := &teo.AdvancedFilter{ Name: helper.String("domain-name"), - Values: []*string{&domainName}, + Values: []*string{helper.String(domainName)}, } request.Filters = append(request.Filters, advancedFilter) @@ -732,6 +732,7 @@ func (me *TeoService) DescribeTeoAccelerationDomainById(ctx context.Context, zon if len(instances) < 1 { return } + ret = instances[0] return } diff --git a/website/docs/r/teo_acceleration_domain.html.markdown b/website/docs/r/teo_acceleration_domain.html.markdown index a0cd03cf78..0b5cfe1a0d 100644 --- a/website/docs/r/teo_acceleration_domain.html.markdown +++ b/website/docs/r/teo_acceleration_domain.html.markdown @@ -32,6 +32,10 @@ The following arguments are supported: * `domain_name` - (Required, String, ForceNew) Accelerated domain name. * `origin_info` - (Required, List) Details of the origin. * `zone_id` - (Required, String, ForceNew) ID of the site related with the accelerated domain name. +* `http_origin_port` - (Optional, Int) HTTP back-to-origin port, the value is 1-65535, effective when OriginProtocol=FOLLOW/HTTP, if not filled in, the default value is 80. +* `https_origin_port` - (Optional, Int) HTTPS back-to-origin port. The value range is 1-65535. It takes effect when OriginProtocol=FOLLOW/HTTPS. If it is not filled in, the default value is 443. +* `ipv6_status` - (Optional, String) IPv6 status, the value is: `follow`: follow the site IPv6 configuration; `on`: on; `off`: off. If not filled in, the default is: `follow`. +* `origin_protocol` - (Optional, String) Origin return protocol, possible values are: `FOLLOW`: protocol follow; `HTTP`: HTTP protocol back to source; `HTTPS`: HTTPS protocol back to source. If not filled in, the default is: `FOLLOW`. * `status` - (Optional, String) Accelerated domain name status, the values are: `online`: enabled; `offline`: disabled. The `origin_info` object supports the following: From ce1c12e9f556374b348806b39fe0305cfc089c31 Mon Sep 17 00:00:00 2001 From: arunma Date: Fri, 14 Jun 2024 18:08:17 +0800 Subject: [PATCH 2/3] feat: add changelog --- .changelog/2685.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/2685.txt diff --git a/.changelog/2685.txt b/.changelog/2685.txt new file mode 100644 index 0000000000..93aca5777a --- /dev/null +++ b/.changelog/2685.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_teo_acceleration_domain: Add `origin_protocol`, `http_origin_port`, `https_origin_port` and `ipv6_status` fields +``` \ No newline at end of file From da3421521c01a3468e463671034d6e875b401e1b Mon Sep 17 00:00:00 2001 From: arunma Date: Mon, 17 Jun 2024 16:59:14 +0800 Subject: [PATCH 3/3] fix: support ipv6 --- .../resource_tc_teo_acceleration_domain.go | 26 ++++++++++++-- ...esource_tc_teo_acceleration_domain_test.go | 34 +++++++++++++++++++ 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/tencentcloud/services/teo/resource_tc_teo_acceleration_domain.go b/tencentcloud/services/teo/resource_tc_teo_acceleration_domain.go index 4fb11f438a..7a241d6c95 100644 --- a/tencentcloud/services/teo/resource_tc_teo_acceleration_domain.go +++ b/tencentcloud/services/teo/resource_tc_teo_acceleration_domain.go @@ -104,24 +104,28 @@ func ResourceTencentCloudTeoAccelerationDomain() *schema.Resource { "origin_protocol": { Type: schema.TypeString, Optional: true, + Computed: true, Description: "Origin return protocol, possible values are: `FOLLOW`: protocol follow; `HTTP`: HTTP protocol back to source; `HTTPS`: HTTPS protocol back to source. If not filled in, the default is: `FOLLOW`.", }, "http_origin_port": { Type: schema.TypeInt, Optional: true, + Computed: true, Description: "HTTP back-to-origin port, the value is 1-65535, effective when OriginProtocol=FOLLOW/HTTP, if not filled in, the default value is 80.", }, "https_origin_port": { Type: schema.TypeInt, Optional: true, + Computed: true, Description: "HTTPS back-to-origin port. The value range is 1-65535. It takes effect when OriginProtocol=FOLLOW/HTTPS. If it is not filled in, the default value is 443.", }, "ipv6_status": { Type: schema.TypeString, Optional: true, + Computed: true, Description: "IPv6 status, the value is: `follow`: follow the site IPv6 configuration; `on`: on; `off`: off. If not filled in, the default is: `follow`.", }, }, @@ -190,6 +194,22 @@ func resourceTencentCloudTeoAccelerationDomainCreate(d *schema.ResourceData, met request.OriginInfo = &originInfo } + if v, ok := d.GetOk("origin_protocol"); ok { + request.OriginProtocol = helper.String(v.(string)) + } + + if v, ok := d.GetOk("http_origin_port"); ok { + request.HttpOriginPort = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOk("https_origin_port"); ok { + request.HttpsOriginPort = helper.IntUint64(v.(int)) + } + + if v, ok := d.GetOk("ipv6_status"); ok { + request.IPv6Status = helper.String(v.(string)) + } + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTeoClient().CreateAccelerationDomainWithContext(ctx, request) if e != nil { @@ -308,7 +328,7 @@ func resourceTencentCloudTeoAccelerationDomainRead(d *schema.ResourceData, meta } if respData.HttpsOriginPort != nil { - _ = d.Set("http_origin_port", respData.HttpsOriginPort) + _ = d.Set("https_origin_port", respData.HttpsOriginPort) } if respData.IPv6Status != nil { @@ -340,7 +360,7 @@ func resourceTencentCloudTeoAccelerationDomainUpdate(d *schema.ResourceData, met domainName := idSplit[1] needChange := false - mutableArgs := []string{"origin_info", "origin_protocol", "http_origin_port", "http_origin_port", "ipv6_status"} + mutableArgs := []string{"origin_info", "origin_protocol", "http_origin_port", "https_origin_port", "ipv6_status"} for _, v := range mutableArgs { if d.HasChange(v) { needChange = true @@ -393,7 +413,7 @@ func resourceTencentCloudTeoAccelerationDomainUpdate(d *schema.ResourceData, met request.HttpOriginPort = helper.IntUint64(v.(int)) } - if v, ok := d.GetOkExists("http_origin_port"); ok { + if v, ok := d.GetOkExists("https_origin_port"); ok { request.HttpsOriginPort = helper.IntUint64(v.(int)) } diff --git a/tencentcloud/services/teo/resource_tc_teo_acceleration_domain_test.go b/tencentcloud/services/teo/resource_tc_teo_acceleration_domain_test.go index 43ba85d710..615761869e 100644 --- a/tencentcloud/services/teo/resource_tc_teo_acceleration_domain_test.go +++ b/tencentcloud/services/teo/resource_tc_teo_acceleration_domain_test.go @@ -31,6 +31,10 @@ func TestAccTencentCloudTeoAccelerationDomainResource_basic(t *testing.T) { resource.TestCheckResourceAttr("tencentcloud_teo_acceleration_domain.acceleration_domain", "origin_info.0.origin", "150.109.8.1"), resource.TestCheckResourceAttr("tencentcloud_teo_acceleration_domain.acceleration_domain", "origin_info.0.origin_type", "IP_DOMAIN"), resource.TestCheckResourceAttrSet("tencentcloud_teo_acceleration_domain.acceleration_domain", "cname"), + resource.TestCheckResourceAttr("tencentcloud_teo_acceleration_domain.acceleration_domain", "origin_protocol", "FOLLOW"), + resource.TestCheckResourceAttr("tencentcloud_teo_acceleration_domain.acceleration_domain", "http_origin_port", "80"), + resource.TestCheckResourceAttr("tencentcloud_teo_acceleration_domain.acceleration_domain", "https_origin_port", "443"), + resource.TestCheckResourceAttr("tencentcloud_teo_acceleration_domain.acceleration_domain", "ipv6_status", "follow"), ), }, { @@ -38,6 +42,20 @@ func TestAccTencentCloudTeoAccelerationDomainResource_basic(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + Config: testAccTeoAccelerationDomainUp, + Check: resource.ComposeTestCheckFunc( + testAccCheckTeoAccelerationDomainExists("tencentcloud_teo_acceleration_domain.acceleration_domain"), + resource.TestCheckResourceAttrSet("tencentcloud_teo_acceleration_domain.acceleration_domain", "id"), + resource.TestCheckResourceAttr("tencentcloud_teo_acceleration_domain.acceleration_domain", "domain_name", "test.tf-teo.xyz"), + resource.TestCheckResourceAttr("tencentcloud_teo_acceleration_domain.acceleration_domain", "origin_info.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_teo_acceleration_domain.acceleration_domain", "origin_info.0.origin", "150.109.8.1"), + resource.TestCheckResourceAttr("tencentcloud_teo_acceleration_domain.acceleration_domain", "origin_info.0.origin_type", "IP_DOMAIN"), + resource.TestCheckResourceAttrSet("tencentcloud_teo_acceleration_domain.acceleration_domain", "cname"), + resource.TestCheckResourceAttr("tencentcloud_teo_acceleration_domain.acceleration_domain", "origin_protocol", "HTTP"), + resource.TestCheckResourceAttr("tencentcloud_teo_acceleration_domain.acceleration_domain", "http_origin_port", "81"), + ), + }, }, }) } @@ -120,3 +138,19 @@ resource "tencentcloud_teo_acceleration_domain" "acceleration_domain" { } ` + +const testAccTeoAccelerationDomainUp = testAccTeoZone + ` + +resource "tencentcloud_teo_acceleration_domain" "acceleration_domain" { + zone_id = tencentcloud_teo_zone.basic.id + domain_name = "test.tf-teo.xyz" + + origin_info { + origin = "150.109.8.1" + origin_type = "IP_DOMAIN" + } + origin_protocol = "HTTP" + http_origin_port = 81 +} + +`