Skip to content

Commit cb661d5

Browse files
author
mikatong
committed
emr support autorenew
1 parent 77e1581 commit cb661d5

File tree

4 files changed

+161
-2
lines changed

4 files changed

+161
-2
lines changed

tencentcloud/services/emr/resource_tc_emr_cluster.go

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ func ResourceTencentCloudEmrCluster() *schema.Resource {
205205
Computed: true,
206206
Description: "Tag description list.",
207207
},
208+
"auto_renew": {
209+
Type: schema.TypeInt,
210+
Optional: true,
211+
Computed: true,
212+
Description: "0 means turn off automatic renewal, 1 means turn on automatic renewal. Default is 0.",
213+
},
208214
},
209215
}
210216
}
@@ -214,7 +220,7 @@ func resourceTencentCloudEmrClusterUpdate(d *schema.ResourceData, meta interface
214220
logId := tccommon.GetLogId(tccommon.ContextNil)
215221
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
216222

217-
immutableFields := []string{"placement", "placement_info", "display_strategy", "login_settings", "resource_spec.0.master_count", "resource_spec.0.task_count", "resource_spec.0.core_count"}
223+
immutableFields := []string{"auto_renew", "placement", "placement_info", "display_strategy", "login_settings", "resource_spec.0.master_count", "resource_spec.0.task_count", "resource_spec.0.core_count"}
218224
for _, f := range immutableFields {
219225
if d.HasChange(f) {
220226
return fmt.Errorf("cannot update argument `%s`", f)
@@ -394,6 +400,35 @@ func resourceTencentCloudEmrClusterDelete(d *schema.ResourceData, meta interface
394400
return err
395401
}
396402

403+
// 预付费删除
404+
payMode := d.Get("pay_mode").(int)
405+
if payMode == 1 {
406+
if err = emrService.DeleteInstance(ctx, d); err != nil {
407+
return err
408+
}
409+
err = resource.Retry(10*tccommon.ReadRetryTimeout, func() *resource.RetryError {
410+
clusters, err := emrService.DescribeInstancesById(ctx, instanceId, DisplayStrategyIsclusterList)
411+
412+
if e, ok := err.(*errors.TencentCloudSDKError); ok {
413+
if e.GetCode() == "ResourceNotFound.InstanceNotFound" {
414+
return nil
415+
}
416+
}
417+
418+
if len(clusters) > 0 {
419+
return resource.RetryableError(fmt.Errorf("%v being destroyed", instanceId))
420+
}
421+
422+
if err != nil {
423+
return resource.RetryableError(err)
424+
}
425+
return nil
426+
})
427+
if err != nil {
428+
return err
429+
}
430+
}
431+
397432
if metaDB != nil && *metaDB != "" {
398433
// remove metadb
399434
mysqlService := svccdb.NewMysqlService(meta.(tccommon.ProviderMeta).GetAPIV3Conn())
@@ -625,5 +660,22 @@ func resourceTencentCloudEmrClusterRead(d *schema.ResourceData, meta interface{}
625660
return err
626661
}
627662
_ = d.Set("tags", tags)
663+
err = resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
664+
result, err := emrService.DescribeClusterNodes(ctx, instanceId, "all", "all", 0, 10)
665+
666+
if err != nil {
667+
return resource.RetryableError(err)
668+
}
669+
670+
if len(result) > 0 {
671+
_ = d.Set("auto_renew", result[0].IsAutoRenew)
672+
}
673+
674+
return nil
675+
})
676+
677+
if err != nil {
678+
return err
679+
}
628680
return nil
629681
}

tencentcloud/services/emr/resource_tc_emr_cluster_test.go

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func init() {
130130

131131
var testEmrClusterResourceKey = "tencentcloud_emr_cluster.emrrrr"
132132

133-
func TestAccTencentCloudEmrClusterResource(t *testing.T) {
133+
func TestAccTencentCloudEmrClusterResource_Basic(t *testing.T) {
134134
t.Parallel()
135135
resource.Test(t, resource.TestCase{
136136
PreCheck: func() { tcacctest.AccPreCheck(t) },
@@ -166,6 +166,38 @@ func TestAccTencentCloudEmrClusterResource(t *testing.T) {
166166
},
167167
})
168168
}
169+
func TestAccTencentCloudEmrClusterResource_Prepay(t *testing.T) {
170+
t.Parallel()
171+
resource.Test(t, resource.TestCase{
172+
PreCheck: func() { tcacctest.AccPreCheck(t) },
173+
Providers: tcacctest.AccProviders,
174+
Steps: []resource.TestStep{
175+
{
176+
Config: testEmrBasicPrepay,
177+
Check: resource.ComposeTestCheckFunc(
178+
testAccCheckEmrExists(testEmrClusterResourceKey),
179+
resource.TestCheckResourceAttr(testEmrClusterResourceKey, "product_id", "38"),
180+
resource.TestCheckResourceAttr(testEmrClusterResourceKey, "vpc_settings.vpc_id", tcacctest.DefaultEMRVpcId),
181+
resource.TestCheckResourceAttr(testEmrClusterResourceKey, "vpc_settings.subnet_id", tcacctest.DefaultEMRSubnetId),
182+
resource.TestCheckResourceAttr(testEmrClusterResourceKey, "softwares.#", "5"),
183+
resource.TestCheckResourceAttr(testEmrClusterResourceKey, "support_ha", "0"),
184+
resource.TestCheckResourceAttr(testEmrClusterResourceKey, "instance_name", "emr-test-demo"),
185+
resource.TestCheckResourceAttr(testEmrClusterResourceKey, "resource_spec.#", "1"),
186+
resource.TestCheckResourceAttr(testEmrClusterResourceKey, "login_settings.password", "Tencent@cloud123"),
187+
resource.TestCheckResourceAttr(testEmrClusterResourceKey, "time_span", "1"),
188+
resource.TestCheckResourceAttr(testEmrClusterResourceKey, "time_unit", "m"),
189+
resource.TestCheckResourceAttr(testEmrClusterResourceKey, "pay_mode", "1"),
190+
resource.TestCheckResourceAttr(testEmrClusterResourceKey, "placement_info.0.zone", "ap-guangzhou-3"),
191+
resource.TestCheckResourceAttr(testEmrClusterResourceKey, "placement_info.0.project_id", "0"),
192+
resource.TestCheckResourceAttrSet(testEmrClusterResourceKey, "instance_id"),
193+
resource.TestCheckResourceAttr(testEmrClusterResourceKey, "sg_id", tcacctest.DefaultEMRSgId),
194+
resource.TestCheckResourceAttr(testEmrClusterResourceKey, "tags.emr-key", "emr-value"),
195+
resource.TestCheckResourceAttr(testEmrClusterResourceKey, "auto_renew", "1"),
196+
),
197+
},
198+
},
199+
})
200+
}
169201

170202
func TestAccTencentCloudEmrClusterResource_NotNeedMasterWan(t *testing.T) {
171203
t.Parallel()
@@ -295,6 +327,75 @@ resource "tencentcloud_emr_cluster" "emrrrr" {
295327
}
296328
`
297329

330+
const testEmrBasicPrepay = tcacctest.DefaultEMRVariable + `
331+
data "tencentcloud_instance_types" "cvm4c8m" {
332+
exclude_sold_out=true
333+
cpu_core_count=4
334+
memory_size=8
335+
filter {
336+
name = "instance-charge-type"
337+
values = ["POSTPAID_BY_HOUR"]
338+
}
339+
filter {
340+
name = "zone"
341+
values = ["ap-guangzhou-3"]
342+
}
343+
}
344+
345+
resource "tencentcloud_emr_cluster" "emrrrr" {
346+
product_id=38
347+
vpc_settings={
348+
vpc_id=var.vpc_id
349+
subnet_id=var.subnet_id
350+
}
351+
softwares = [
352+
"hdfs-2.8.5",
353+
"knox-1.6.1",
354+
"openldap-2.4.44",
355+
"yarn-2.8.5",
356+
"zookeeper-3.6.3",
357+
]
358+
support_ha=0
359+
instance_name="emr-test-demo"
360+
resource_spec {
361+
master_resource_spec {
362+
mem_size=8192
363+
cpu=4
364+
disk_size=100
365+
disk_type="CLOUD_PREMIUM"
366+
spec="CVM.${data.tencentcloud_instance_types.cvm4c8m.instance_types.0.family}"
367+
storage_type=5
368+
root_size=50
369+
}
370+
core_resource_spec {
371+
mem_size=8192
372+
cpu=4
373+
disk_size=100
374+
disk_type="CLOUD_PREMIUM"
375+
spec="CVM.${data.tencentcloud_instance_types.cvm4c8m.instance_types.0.family}"
376+
storage_type=5
377+
root_size=50
378+
}
379+
master_count=1
380+
core_count=2
381+
}
382+
login_settings={
383+
password="Tencent@cloud123"
384+
}
385+
time_span=1
386+
time_unit="m"
387+
pay_mode=1
388+
placement_info {
389+
zone="ap-guangzhou-3"
390+
project_id=0
391+
}
392+
sg_id=var.sg_id
393+
tags = {
394+
emr-key = "emr-value"
395+
}
396+
auto_renew=1
397+
}
398+
`
298399
const testEmrNotNeedMasterWan = tcacctest.DefaultEMRVariable + `
299400
data "tencentcloud_instance_types" "cvm4c8m" {
300401
exclude_sold_out=true

tencentcloud/services/emr/service_tencentcloud_emr.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ func (me *EMRService) DeleteInstance(ctx context.Context, d *schema.ResourceData
6060
func (me *EMRService) CreateInstance(ctx context.Context, d *schema.ResourceData) (id string, err error) {
6161
logId := tccommon.GetLogId(ctx)
6262
request := emr.NewCreateInstanceRequest()
63+
64+
if v, ok := d.GetOk("auto_renew"); ok {
65+
request.AutoRenew = common.Uint64Ptr((uint64)(v.(int)))
66+
}
67+
6368
if v, ok := d.GetOk("product_id"); ok {
6469
request.ProductId = common.Uint64Ptr((uint64)(v.(int)))
6570
}

website/docs/r/emr_cluster.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ The following arguments are supported:
124124
* `softwares` - (Required, Set: [`String`], ForceNew) The softwares of a EMR instance.
125125
* `support_ha` - (Required, Int, ForceNew) The flag whether the instance support high availability.(0=>not support, 1=>support).
126126
* `vpc_settings` - (Required, Map, ForceNew) The private net config of EMR instance.
127+
* `auto_renew` - (Optional, Int) 0 means turn off automatic renewal, 1 means turn on automatic renewal. Default is 0.
127128
* `display_strategy` - (Optional, String, **Deprecated**) It will be deprecated in later versions. Display strategy of EMR instance.
128129
* `extend_fs_field` - (Optional, String) Access the external file system.
129130
* `login_settings` - (Optional, Map) Instance login settings. There are two optional fields:- password: Instance login password: 8-16 characters, including uppercase letters, lowercase letters, numbers and special characters. Special symbols only support! @% ^ *. The first bit of the password cannot be a special character;- public_key_id: Public key id. After the key is associated, the instance can be accessed through the corresponding private key.

0 commit comments

Comments
 (0)