From 14b905743dc5a67892228f87074d33c8db491f79 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Sun, 4 Feb 2024 15:21:36 +0800 Subject: [PATCH] feat/apigw --- tencentcloud/provider.go | 1 + tencentcloud/provider.md | 3 +- .../resource_tc_api_gateway_update_service.go | 99 +++++++++++++++++++ .../resource_tc_api_gateway_update_service.md | 11 +++ ...urce_tc_api_gateway_update_service_test.go | 56 +++++++++++ .../api_gateway_update_service.html.markdown | 39 ++++++++ website/tencentcloud.erb | 3 + 7 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 tencentcloud/services/apigateway/resource_tc_api_gateway_update_service.go create mode 100644 tencentcloud/services/apigateway/resource_tc_api_gateway_update_service.md create mode 100644 tencentcloud/services/apigateway/resource_tc_api_gateway_update_service_test.go create mode 100644 website/docs/r/api_gateway_update_service.html.markdown diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index 25ea1d8616..d51e452250 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -1441,6 +1441,7 @@ func Provider() *schema.Provider { "tencentcloud_api_gateway_plugin_attachment": apigateway.ResourceTencentCloudAPIGatewayPluginAttachment(), "tencentcloud_api_gateway_upstream": apigateway.ResourceTencentCloudAPIGatewayUpstream(), "tencentcloud_api_gateway_api_app_attachment": apigateway.ResourceTencentCloudAPIGatewayApiAppAttachment(), + "tencentcloud_api_gateway_update_service": apigateway.ResourceTencentCloudAPIGatewayUpdateService(), "tencentcloud_sqlserver_basic_instance": sqlserver.ResourceTencentCloudSqlserverBasicInstance(), "tencentcloud_sqlserver_instance_tde": sqlserver.ResourceTencentCloudSqlserverInstanceTDE(), "tencentcloud_sqlserver_database_tde": sqlserver.ResourceTencentCloudSqlserverDatabaseTDE(), diff --git a/tencentcloud/provider.md b/tencentcloud/provider.md index afb3c4c859..a2774681ab 100644 --- a/tencentcloud/provider.md +++ b/tencentcloud/provider.md @@ -147,7 +147,8 @@ API GateWay(apigateway) tencentcloud_api_gateway_upstream tencentcloud_api_gateway_api_app_attachment tencentcloud_api_gateway_update_api_app_key - tencentcloud_api_gateway_import_open_api + tencentcloud_api_gateway_import_open_api + tencentcloud_api_gateway_update_service Cloud Audit(Audit) Data Source diff --git a/tencentcloud/services/apigateway/resource_tc_api_gateway_update_service.go b/tencentcloud/services/apigateway/resource_tc_api_gateway_update_service.go new file mode 100644 index 0000000000..c78e069a8c --- /dev/null +++ b/tencentcloud/services/apigateway/resource_tc_api_gateway_update_service.go @@ -0,0 +1,99 @@ +package apigateway + +import ( + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + apigateway "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway/v20180808" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func ResourceTencentCloudAPIGatewayUpdateService() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudApigatewayUpdateServiceCreate, + Read: resourceTencentCloudApigatewayUpdateServiceRead, + Delete: resourceTencentCloudApigatewayUpdateServiceDelete, + + Schema: map[string]*schema.Schema{ + "service_id": { + Required: true, + ForceNew: true, + Type: schema.TypeString, + Description: "Service ID.", + }, + "environment_name": { + Required: true, + ForceNew: true, + Type: schema.TypeString, + ValidateFunc: tccommon.ValidateAllowedStringValue([]string{"test", "prepub", "release"}), + Description: "The name of the environment to be switched, currently supporting three environments: test (test environment), prepub (pre release environment), and release (release environment).", + }, + "version_name": { + Required: true, + ForceNew: true, + Type: schema.TypeString, + Description: "The version number of the switch.", + }, + }, + } +} + +func resourceTencentCloudApigatewayUpdateServiceCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_apigateway_update_service.create")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + request = apigateway.NewUpdateServiceRequest() + serviceId string + ) + + if v, ok := d.GetOk("service_id"); ok { + request.ServiceId = helper.String(v.(string)) + serviceId = v.(string) + } + + if v, ok := d.GetOk("environment_name"); ok { + request.EnvironmentName = helper.String(v.(string)) + } + + if v, ok := d.GetOk("version_name"); ok { + request.VersionName = helper.String(v.(string)) + } + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseAPIGatewayClient().UpdateService(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 operate apigateway updateService failed, reason:%+v", logId, err) + return err + } + + d.SetId(serviceId) + return resourceTencentCloudApigatewayUpdateServiceRead(d, meta) +} + +func resourceTencentCloudApigatewayUpdateServiceRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_apigateway_update_service.read")() + defer tccommon.InconsistentCheck(d, meta)() + + return nil +} + +func resourceTencentCloudApigatewayUpdateServiceDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_apigateway_update_service.delete")() + defer tccommon.InconsistentCheck(d, meta)() + + return nil +} diff --git a/tencentcloud/services/apigateway/resource_tc_api_gateway_update_service.md b/tencentcloud/services/apigateway/resource_tc_api_gateway_update_service.md new file mode 100644 index 0000000000..3e20f72278 --- /dev/null +++ b/tencentcloud/services/apigateway/resource_tc_api_gateway_update_service.md @@ -0,0 +1,11 @@ +Provides a resource to create a apigateway update_service + +Example Usage + +```hcl +resource "tencentcloud_api_gateway_update_service" "example" { + service_id = "service-oczq2nyk" + environment_name = "test" + version_name = "20240204142759-b5a4f741-adc0-4964-b01b-2a4a04ff6964" +} +``` diff --git a/tencentcloud/services/apigateway/resource_tc_api_gateway_update_service_test.go b/tencentcloud/services/apigateway/resource_tc_api_gateway_update_service_test.go new file mode 100644 index 0000000000..f20ad8131a --- /dev/null +++ b/tencentcloud/services/apigateway/resource_tc_api_gateway_update_service_test.go @@ -0,0 +1,56 @@ +package apigateway_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +// go test -i; go test -test.run TestAccTencentCloudAPIGatewayUpdateServiceResource_basic -v +func TestAccTencentCloudAPIGatewayUpdateServiceResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{ + { + Config: testAccAPIGatewayUpdateService1, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_api_gateway_update_service.example", "id"), + resource.TestCheckResourceAttr("tencentcloud_api_gateway_update_service.example", "service_id", "service-oczq2nyk"), + resource.TestCheckResourceAttr("tencentcloud_api_gateway_update_service.example", "environment_name", "test"), + resource.TestCheckResourceAttr("tencentcloud_api_gateway_update_service.example", "version_name", "20240204142759-b5a4f741-adc0-4964-b01b-2a4a04ff6964"), + ), + }, + { + Config: testAccAPIGatewayUpdateService2, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_api_gateway_update_service.example", "id"), + resource.TestCheckResourceAttr("tencentcloud_api_gateway_update_service.example", "service_id", "service-oczq2nyk"), + resource.TestCheckResourceAttr("tencentcloud_api_gateway_update_service.example", "environment_name", "test"), + resource.TestCheckResourceAttr("tencentcloud_api_gateway_update_service.example", "version_name", "20240126164018-c6ec85b5-8aae-4896-bc26-8afbf88dcbcc"), + ), + }, + }, + }) +} + +const testAccAPIGatewayUpdateService1 = ` +resource "tencentcloud_api_gateway_update_service" "example" { + service_id = "service-oczq2nyk" + environment_name = "test" + version_name = "20240204142759-b5a4f741-adc0-4964-b01b-2a4a04ff6964" +} +` + +const testAccAPIGatewayUpdateService2 = ` +resource "tencentcloud_api_gateway_update_service" "example" { + service_id = "service-oczq2nyk" + environment_name = "test" + version_name = "20240126164018-c6ec85b5-8aae-4896-bc26-8afbf88dcbcc" +} +` diff --git a/website/docs/r/api_gateway_update_service.html.markdown b/website/docs/r/api_gateway_update_service.html.markdown new file mode 100644 index 0000000000..3fdf4dd880 --- /dev/null +++ b/website/docs/r/api_gateway_update_service.html.markdown @@ -0,0 +1,39 @@ +--- +subcategory: "API GateWay(apigateway)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_api_gateway_update_service" +sidebar_current: "docs-tencentcloud-resource-api_gateway_update_service" +description: |- + Provides a resource to create a apigateway update_service +--- + +# tencentcloud_api_gateway_update_service + +Provides a resource to create a apigateway update_service + +## Example Usage + +```hcl +resource "tencentcloud_api_gateway_update_service" "example" { + service_id = "service-oczq2nyk" + environment_name = "test" + version_name = "20240204142759-b5a4f741-adc0-4964-b01b-2a4a04ff6964" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `environment_name` - (Required, String, ForceNew) The name of the environment to be switched, currently supporting three environments: test (test environment), prepub (pre release environment), and release (release environment). +* `service_id` - (Required, String, ForceNew) Service ID. +* `version_name` - (Required, String, ForceNew) The version number of the switch. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. + + + diff --git a/website/tencentcloud.erb b/website/tencentcloud.erb index 35c78deb92..033cf3de45 100644 --- a/website/tencentcloud.erb +++ b/website/tencentcloud.erb @@ -140,6 +140,9 @@
  • tencentcloud_api_gateway_update_api_app_key
  • +
  • + tencentcloud_api_gateway_update_service +
  • tencentcloud_api_gateway_upstream