Skip to content

Commit

Permalink
feat/apigw
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenEarth committed Feb 4, 2024
1 parent b9a8fa4 commit 14b9057
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 1 deletion.
1 change: 1 addition & 0 deletions tencentcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion tencentcloud/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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_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
}
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"
}
```
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"
}
`
39 changes: 39 additions & 0 deletions website/docs/r/api_gateway_update_service.html.markdown
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.



3 changes: 3 additions & 0 deletions website/tencentcloud.erb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@
<li>
<a href="/docs/providers/tencentcloud/r/api_gateway_update_api_app_key.html">tencentcloud_api_gateway_update_api_app_key</a>
</li>
<li>
<a href="/docs/providers/tencentcloud/r/api_gateway_update_service.html">tencentcloud_api_gateway_update_service</a>
</li>
<li>
<a href="/docs/providers/tencentcloud/r/api_gateway_upstream.html">tencentcloud_api_gateway_upstream</a>
</li>
Expand Down

0 comments on commit 14b9057

Please sign in to comment.