Skip to content

Commit 4544fc1

Browse files
hellertangmikatong
authored andcommitted
add as operation
1 parent 047529a commit 4544fc1

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-0
lines changed

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ Auto Scaling(AS)
125125
tencentcloud_as_schedule
126126
tencentcloud_as_lifecycle_hook
127127
tencentcloud_as_notification
128+
tencentcloud_as_remove_instances
128129
129130
Content Delivery Network(CDN)
130131
Data Source
@@ -1266,6 +1267,7 @@ func Provider() terraform.ResourceProvider {
12661267
"tencentcloud_as_schedule": resourceTencentCloudAsSchedule(),
12671268
"tencentcloud_as_lifecycle_hook": resourceTencentCloudAsLifecycleHook(),
12681269
"tencentcloud_as_notification": resourceTencentCloudAsNotification(),
1270+
"tencentcloud_as_remove_instances": resourceTencentCloudAsRemoveInstances(),
12691271
"tencentcloud_mongodb_instance": resourceTencentCloudMongodbInstance(),
12701272
"tencentcloud_mongodb_sharding_instance": resourceTencentCloudMongodbShardingInstance(),
12711273
"tencentcloud_dayu_cc_http_policy": resourceTencentCloudDayuCCHttpPolicy(),
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
Provides a resource to create a as remove_instances
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_as_remove_instances" "remove_instances" {
8+
auto_scaling_group_id = ""
9+
instance_ids = ""
10+
}
11+
```
12+
13+
Import
14+
15+
as remove_instances can be imported using the id, e.g.
16+
17+
```
18+
terraform import tencentcloud_as_remove_instances.remove_instances remove_instances_id
19+
```
20+
*/
21+
package tencentcloud
22+
23+
import (
24+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
25+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
26+
as "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as/v20180419"
27+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
28+
"log"
29+
)
30+
31+
func resourceTencentCloudAsRemoveInstances() *schema.Resource {
32+
return &schema.Resource{
33+
Create: resourceTencentCloudAsRemoveInstancesCreate,
34+
Read: resourceTencentCloudAsRemoveInstancesRead,
35+
Delete: resourceTencentCloudAsRemoveInstancesDelete,
36+
Importer: &schema.ResourceImporter{
37+
State: schema.ImportStatePassthrough,
38+
},
39+
Schema: map[string]*schema.Schema{
40+
"auto_scaling_group_id": {
41+
Required: true,
42+
ForceNew: true,
43+
Type: schema.TypeString,
44+
Description: "Launch configuration ID.",
45+
},
46+
47+
"instance_ids": {
48+
Required: true,
49+
ForceNew: true,
50+
Type: schema.TypeSet,
51+
Elem: &schema.Schema{
52+
Type: schema.TypeString,
53+
},
54+
Description: "List of cvm instances to remove .",
55+
},
56+
},
57+
}
58+
}
59+
60+
func resourceTencentCloudAsRemoveInstancesCreate(d *schema.ResourceData, meta interface{}) error {
61+
defer logElapsed("data_source.tencentcloud_as_remove_instances.read")()
62+
defer inconsistentCheck(d, meta)()
63+
64+
logId := getLogId(contextNil)
65+
66+
var (
67+
request = as.NewRemoveInstancesRequest()
68+
response = as.NewRemoveInstancesResponse()
69+
activityId string
70+
)
71+
if v, ok := d.GetOk("auto_scaling_group_id"); ok {
72+
request.AutoScalingGroupId = helper.String(v.(string))
73+
}
74+
75+
if v, ok := d.GetOk("instance_ids"); ok {
76+
instanceIdsSet := v.(*schema.Set).List()
77+
for i := range instanceIdsSet {
78+
instanceIds := instanceIdsSet[i].(string)
79+
request.InstanceIds = append(request.InstanceIds, &instanceIds)
80+
}
81+
}
82+
83+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
84+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseAsClient().RemoveInstances(request)
85+
if e != nil {
86+
return retryError(e)
87+
} else {
88+
log.Println("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
89+
}
90+
response = result
91+
return nil
92+
})
93+
if err != nil {
94+
log.Println("[CRITAL]%s operate as removeInstances failed, reason:%+v", logId, err)
95+
return nil
96+
}
97+
98+
activityId = *response.Response.ActivityId
99+
d.SetId(activityId)
100+
101+
return resourceTencentCloudAsRemoveInstancesRead(d, meta)
102+
}
103+
104+
func resourceTencentCloudAsRemoveInstancesRead(d *schema.ResourceData, meta interface{}) error {
105+
defer logElapsed("resource.tencentcloud_as_remove_instances.read")()
106+
defer inconsistentCheck(d, meta)()
107+
108+
return nil
109+
}
110+
111+
func resourceTencentCloudAsRemoveInstancesDelete(d *schema.ResourceData, meta interface{}) error {
112+
defer logElapsed("resource.tencentcloud_as_remove_instances.delete")()
113+
defer inconsistentCheck(d, meta)()
114+
115+
return nil
116+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package tencentcloud
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
5+
"testing"
6+
)
7+
8+
func TestTencentCloudAsRemoveInstancesResource_basic(t *testing.T) {
9+
t.Parallel()
10+
resource.Test(t, resource.TestCase{
11+
PreCheck: func() {
12+
testAccPreCheck(t)
13+
},
14+
Providers: testAccProviders,
15+
Steps: []resource.TestStep{
16+
{
17+
Config: testAccAsRemoveInstances,
18+
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_as_remove_instances.remove_instances", "id")),
19+
},
20+
{
21+
ResourceName: "tencentcloud_as_remove_instances.remove_instances",
22+
ImportState: true,
23+
ImportStateVerify: true,
24+
},
25+
},
26+
})
27+
}
28+
29+
const testAccAsRemoveInstances = `
30+
31+
resource "tencentcloud_as_remove_instances" "remove_instances" {
32+
auto_scaling_group_id = ""
33+
instance_ids = ""
34+
}
35+
36+
`

0 commit comments

Comments
 (0)