Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/apigw #2518

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/2518.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
tencentcloud_api_gateway_update_service
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的 changelog 补全?

```
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是新增了 2 个 operation 资源吗

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_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
}
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
Loading