Skip to content

Commit a72cdb4

Browse files
authored
feat/apigw (#2518)
* feat/apigw * feat/apigw * feat/apigw
1 parent 2aced90 commit a72cdb4

File tree

8 files changed

+214
-1
lines changed

8 files changed

+214
-1
lines changed

.changelog/2518.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
tencentcloud_api_gateway_update_service
3+
```

tencentcloud/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,7 @@ func Provider() *schema.Provider {
14371437
"tencentcloud_api_gateway_plugin_attachment": apigateway.ResourceTencentCloudAPIGatewayPluginAttachment(),
14381438
"tencentcloud_api_gateway_upstream": apigateway.ResourceTencentCloudAPIGatewayUpstream(),
14391439
"tencentcloud_api_gateway_api_app_attachment": apigateway.ResourceTencentCloudAPIGatewayApiAppAttachment(),
1440+
"tencentcloud_api_gateway_update_service": apigateway.ResourceTencentCloudAPIGatewayUpdateService(),
14401441
"tencentcloud_sqlserver_basic_instance": sqlserver.ResourceTencentCloudSqlserverBasicInstance(),
14411442
"tencentcloud_sqlserver_instance_tde": sqlserver.ResourceTencentCloudSqlserverInstanceTDE(),
14421443
"tencentcloud_sqlserver_database_tde": sqlserver.ResourceTencentCloudSqlserverDatabaseTDE(),

tencentcloud/provider.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ API GateWay(apigateway)
147147
tencentcloud_api_gateway_upstream
148148
tencentcloud_api_gateway_api_app_attachment
149149
tencentcloud_api_gateway_update_api_app_key
150-
tencentcloud_api_gateway_import_open_api
150+
tencentcloud_api_gateway_import_open_api
151+
tencentcloud_api_gateway_update_service
151152

152153
Cloud Audit(Audit)
153154
Data Source
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package apigateway
2+
3+
import (
4+
"log"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8+
apigateway "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway/v20180808"
9+
10+
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
11+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
12+
)
13+
14+
func ResourceTencentCloudAPIGatewayUpdateService() *schema.Resource {
15+
return &schema.Resource{
16+
Create: resourceTencentCloudAPIGatewayUpdateServiceCreate,
17+
Read: resourceTencentCloudAPIGatewayUpdateServiceRead,
18+
Delete: resourceTencentCloudAPIGatewayUpdateServiceDelete,
19+
20+
Schema: map[string]*schema.Schema{
21+
"service_id": {
22+
Required: true,
23+
ForceNew: true,
24+
Type: schema.TypeString,
25+
Description: "Service ID.",
26+
},
27+
"environment_name": {
28+
Required: true,
29+
ForceNew: true,
30+
Type: schema.TypeString,
31+
ValidateFunc: tccommon.ValidateAllowedStringValue([]string{"test", "prepub", "release"}),
32+
Description: "The name of the environment to be switched, currently supporting three environments: test (test environment), prepub (pre release environment), and release (release environment).",
33+
},
34+
"version_name": {
35+
Required: true,
36+
ForceNew: true,
37+
Type: schema.TypeString,
38+
Description: "The version number of the switch.",
39+
},
40+
},
41+
}
42+
}
43+
44+
func resourceTencentCloudAPIGatewayUpdateServiceCreate(d *schema.ResourceData, meta interface{}) error {
45+
defer tccommon.LogElapsed("resource.tencentcloud_api_gateway_update_service.create")()
46+
defer tccommon.InconsistentCheck(d, meta)()
47+
48+
var (
49+
logId = tccommon.GetLogId(tccommon.ContextNil)
50+
request = apigateway.NewUpdateServiceRequest()
51+
serviceId string
52+
)
53+
54+
if v, ok := d.GetOk("service_id"); ok {
55+
request.ServiceId = helper.String(v.(string))
56+
serviceId = v.(string)
57+
}
58+
59+
if v, ok := d.GetOk("environment_name"); ok {
60+
request.EnvironmentName = helper.String(v.(string))
61+
}
62+
63+
if v, ok := d.GetOk("version_name"); ok {
64+
request.VersionName = helper.String(v.(string))
65+
}
66+
67+
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
68+
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseAPIGatewayClient().UpdateService(request)
69+
if e != nil {
70+
return tccommon.RetryError(e)
71+
} else {
72+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
73+
}
74+
75+
return nil
76+
})
77+
78+
if err != nil {
79+
log.Printf("[CRITAL]%s operate apigateway updateService failed, reason:%+v", logId, err)
80+
return err
81+
}
82+
83+
d.SetId(serviceId)
84+
return resourceTencentCloudAPIGatewayUpdateServiceRead(d, meta)
85+
}
86+
87+
func resourceTencentCloudAPIGatewayUpdateServiceRead(d *schema.ResourceData, meta interface{}) error {
88+
defer tccommon.LogElapsed("resource.tencentcloud_api_gateway_update_service.read")()
89+
defer tccommon.InconsistentCheck(d, meta)()
90+
91+
return nil
92+
}
93+
94+
func resourceTencentCloudAPIGatewayUpdateServiceDelete(d *schema.ResourceData, meta interface{}) error {
95+
defer tccommon.LogElapsed("resource.tencentcloud_api_gateway_update_service.delete")()
96+
defer tccommon.InconsistentCheck(d, meta)()
97+
98+
return nil
99+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Provides a resource to create a apigateway update_service
2+
3+
Example Usage
4+
5+
```hcl
6+
resource "tencentcloud_api_gateway_update_service" "example" {
7+
service_id = "service-oczq2nyk"
8+
environment_name = "test"
9+
version_name = "20240204142759-b5a4f741-adc0-4964-b01b-2a4a04ff6964"
10+
}
11+
```
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package apigateway_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
8+
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
9+
)
10+
11+
// go test -i; go test -test.run TestAccTencentCloudAPIGatewayUpdateServiceResource_basic -v
12+
func TestAccTencentCloudAPIGatewayUpdateServiceResource_basic(t *testing.T) {
13+
t.Parallel()
14+
resource.Test(t, resource.TestCase{
15+
PreCheck: func() {
16+
tcacctest.AccPreCheck(t)
17+
},
18+
Providers: tcacctest.AccProviders,
19+
Steps: []resource.TestStep{
20+
{
21+
Config: testAccAPIGatewayUpdateService1,
22+
Check: resource.ComposeTestCheckFunc(
23+
resource.TestCheckResourceAttrSet("tencentcloud_api_gateway_update_service.example", "id"),
24+
resource.TestCheckResourceAttr("tencentcloud_api_gateway_update_service.example", "service_id", "service-oczq2nyk"),
25+
resource.TestCheckResourceAttr("tencentcloud_api_gateway_update_service.example", "environment_name", "test"),
26+
resource.TestCheckResourceAttr("tencentcloud_api_gateway_update_service.example", "version_name", "20240204142759-b5a4f741-adc0-4964-b01b-2a4a04ff6964"),
27+
),
28+
},
29+
{
30+
Config: testAccAPIGatewayUpdateService2,
31+
Check: resource.ComposeTestCheckFunc(
32+
resource.TestCheckResourceAttrSet("tencentcloud_api_gateway_update_service.example", "id"),
33+
resource.TestCheckResourceAttr("tencentcloud_api_gateway_update_service.example", "service_id", "service-oczq2nyk"),
34+
resource.TestCheckResourceAttr("tencentcloud_api_gateway_update_service.example", "environment_name", "test"),
35+
resource.TestCheckResourceAttr("tencentcloud_api_gateway_update_service.example", "version_name", "20240126164018-c6ec85b5-8aae-4896-bc26-8afbf88dcbcc"),
36+
),
37+
},
38+
},
39+
})
40+
}
41+
42+
const testAccAPIGatewayUpdateService1 = `
43+
resource "tencentcloud_api_gateway_update_service" "example" {
44+
service_id = "service-oczq2nyk"
45+
environment_name = "test"
46+
version_name = "20240204142759-b5a4f741-adc0-4964-b01b-2a4a04ff6964"
47+
}
48+
`
49+
50+
const testAccAPIGatewayUpdateService2 = `
51+
resource "tencentcloud_api_gateway_update_service" "example" {
52+
service_id = "service-oczq2nyk"
53+
environment_name = "test"
54+
version_name = "20240126164018-c6ec85b5-8aae-4896-bc26-8afbf88dcbcc"
55+
}
56+
`
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
subcategory: "API GateWay(apigateway)"
3+
layout: "tencentcloud"
4+
page_title: "TencentCloud: tencentcloud_api_gateway_update_service"
5+
sidebar_current: "docs-tencentcloud-resource-api_gateway_update_service"
6+
description: |-
7+
Provides a resource to create a apigateway update_service
8+
---
9+
10+
# tencentcloud_api_gateway_update_service
11+
12+
Provides a resource to create a apigateway update_service
13+
14+
## Example Usage
15+
16+
```hcl
17+
resource "tencentcloud_api_gateway_update_service" "example" {
18+
service_id = "service-oczq2nyk"
19+
environment_name = "test"
20+
version_name = "20240204142759-b5a4f741-adc0-4964-b01b-2a4a04ff6964"
21+
}
22+
```
23+
24+
## Argument Reference
25+
26+
The following arguments are supported:
27+
28+
* `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).
29+
* `service_id` - (Required, String, ForceNew) Service ID.
30+
* `version_name` - (Required, String, ForceNew) The version number of the switch.
31+
32+
## Attributes Reference
33+
34+
In addition to all arguments above, the following attributes are exported:
35+
36+
* `id` - ID of the resource.
37+
38+
39+

website/tencentcloud.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@
140140
<li>
141141
<a href="/docs/providers/tencentcloud/r/api_gateway_update_api_app_key.html">tencentcloud_api_gateway_update_api_app_key</a>
142142
</li>
143+
<li>
144+
<a href="/docs/providers/tencentcloud/r/api_gateway_update_service.html">tencentcloud_api_gateway_update_service</a>
145+
</li>
143146
<li>
144147
<a href="/docs/providers/tencentcloud/r/api_gateway_upstream.html">tencentcloud_api_gateway_upstream</a>
145148
</li>

0 commit comments

Comments
 (0)