-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
214 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-resource | ||
tencentcloud_api_gateway_update_service | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
tencentcloud/services/apigateway/resource_tc_api_gateway_update_service.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_api_gateway_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_api_gateway_update_service.read")() | ||
defer tccommon.InconsistentCheck(d, meta)() | ||
|
||
return nil | ||
} | ||
|
||
func resourceTencentCloudAPIGatewayUpdateServiceDelete(d *schema.ResourceData, meta interface{}) error { | ||
defer tccommon.LogElapsed("resource.tencentcloud_api_gateway_update_service.delete")() | ||
defer tccommon.InconsistentCheck(d, meta)() | ||
|
||
return nil | ||
} |
11 changes: 11 additions & 0 deletions
11
tencentcloud/services/apigateway/resource_tc_api_gateway_update_service.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
``` |
56 changes: 56 additions & 0 deletions
56
tencentcloud/services/apigateway/resource_tc_api_gateway_update_service_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters