Skip to content

Commit b4b2e02

Browse files
author
mikatong
committed
emr support pre_executed_file_settings
1 parent fc9a908 commit b4b2e02

File tree

4 files changed

+209
-0
lines changed

4 files changed

+209
-0
lines changed

tencentcloud/services/emr/resource_tc_emr_cluster.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,67 @@ func ResourceTencentCloudEmrCluster() *schema.Resource {
237237
Computed: true,
238238
Description: "0 means turn off automatic renewal, 1 means turn on automatic renewal. Default is 0.",
239239
},
240+
"pre_executed_file_settings": {
241+
Type: schema.TypeList,
242+
Optional: true,
243+
ForceNew: true,
244+
Description: "Pre executed file settings.",
245+
Elem: &schema.Resource{
246+
Schema: map[string]*schema.Schema{
247+
"args": {
248+
Type: schema.TypeList,
249+
Optional: true,
250+
ForceNew: true,
251+
Elem: &schema.Schema{
252+
Type: schema.TypeString,
253+
},
254+
Description: "Execution script parameters.",
255+
},
256+
"run_order": {
257+
Type: schema.TypeInt,
258+
Optional: true,
259+
ForceNew: true,
260+
Description: "Run order.",
261+
},
262+
"when_run": {
263+
Type: schema.TypeString,
264+
Optional: true,
265+
ForceNew: true,
266+
Description: "`resourceAfter` or `clusterAfter`.",
267+
},
268+
"cos_file_name": {
269+
Type: schema.TypeString,
270+
Optional: true,
271+
ForceNew: true,
272+
Description: "Script file name.",
273+
},
274+
"cos_file_uri": {
275+
Type: schema.TypeString,
276+
Optional: true,
277+
ForceNew: true,
278+
Description: "The cos address of the script.",
279+
},
280+
"cos_secret_id": {
281+
Type: schema.TypeString,
282+
Optional: true,
283+
ForceNew: true,
284+
Description: "Cos secretId.",
285+
},
286+
"cos_secret_key": {
287+
Type: schema.TypeString,
288+
Optional: true,
289+
ForceNew: true,
290+
Description: "Cos secretKey.",
291+
},
292+
"remark": {
293+
Type: schema.TypeString,
294+
Optional: true,
295+
ForceNew: true,
296+
Description: "Remark.",
297+
},
298+
},
299+
},
300+
},
240301
},
241302
}
242303
}

tencentcloud/services/emr/resource_tc_emr_cluster_test.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,26 @@ func TestAccTencentCloudEmrClusterResource_Basic(t *testing.T) {
176176
},
177177
})
178178
}
179+
180+
func TestAccTencentCloudEmrClusterResource_PreExecutedFileSettings(t *testing.T) {
181+
t.Parallel()
182+
resource.Test(t, resource.TestCase{
183+
PreCheck: func() { tcacctest.AccPreCheck(t) },
184+
Providers: tcacctest.AccProviders,
185+
Steps: []resource.TestStep{
186+
{
187+
Config: testEmrBasicPreExecutedFileSettings,
188+
Check: resource.ComposeTestCheckFunc(
189+
testAccCheckEmrExists(testEmrClusterResourceKey),
190+
resource.TestCheckResourceAttr(testEmrClusterResourceKey, "pre_executed_file_settings.#", "1"),
191+
resource.TestCheckResourceAttr(testEmrClusterResourceKey, "pre_executed_file_settings.0.cos_file_name", "test"),
192+
resource.TestCheckResourceAttr(testEmrClusterResourceKey, "pre_executed_file_settings.0.when_run", "resourceAfter"),
193+
resource.TestCheckResourceAttrSet(testEmrClusterResourceKey, "pre_executed_file_settings.0.cos_file_uri"),
194+
),
195+
},
196+
},
197+
})
198+
}
179199
func TestAccTencentCloudEmrClusterResource_Prepay(t *testing.T) {
180200
t.Parallel()
181201
resource.Test(t, resource.TestCase{
@@ -347,6 +367,90 @@ resource "tencentcloud_emr_cluster" "emrrrr" {
347367
}
348368
`
349369

370+
const testEmrBasicPreExecutedFileSettings = tcacctest.DefaultEMRVariable + `
371+
data "tencentcloud_instance_types" "cvm4c8m" {
372+
exclude_sold_out=true
373+
cpu_core_count=4
374+
memory_size=8
375+
filter {
376+
name = "instance-charge-type"
377+
values = ["POSTPAID_BY_HOUR"]
378+
}
379+
filter {
380+
name = "zone"
381+
values = ["ap-guangzhou-3"]
382+
}
383+
}
384+
385+
resource "tencentcloud_emr_cluster" "emrrrr" {
386+
product_id=38
387+
vpc_settings={
388+
vpc_id=var.vpc_id
389+
subnet_id=var.subnet_id
390+
}
391+
softwares = [
392+
"hdfs-2.8.5",
393+
"knox-1.6.1",
394+
"openldap-2.4.44",
395+
"yarn-2.8.5",
396+
"zookeeper-3.6.3",
397+
]
398+
support_ha=0
399+
instance_name="emr-test-demo"
400+
resource_spec {
401+
master_resource_spec {
402+
mem_size=8192
403+
cpu=4
404+
disk_size=100
405+
disk_type="CLOUD_PREMIUM"
406+
spec="CVM.${data.tencentcloud_instance_types.cvm4c8m.instance_types.0.family}"
407+
storage_type=5
408+
root_size=50
409+
multi_disks {
410+
disk_type = "CLOUD_PREMIUM"
411+
volume = 200
412+
count = 1
413+
}
414+
}
415+
core_resource_spec {
416+
mem_size=8192
417+
cpu=4
418+
disk_size=100
419+
disk_type="CLOUD_PREMIUM"
420+
spec="CVM.${data.tencentcloud_instance_types.cvm4c8m.instance_types.0.family}"
421+
storage_type=5
422+
root_size=50
423+
multi_disks {
424+
disk_type = "CLOUD_PREMIUM"
425+
volume = 100
426+
count = 2
427+
}
428+
}
429+
master_count=1
430+
core_count=2
431+
}
432+
login_settings={
433+
password="Tencent@cloud123"
434+
}
435+
time_span=3600
436+
time_unit="s"
437+
pay_mode=0
438+
placement_info {
439+
zone="ap-guangzhou-3"
440+
project_id=0
441+
}
442+
sg_id=var.sg_id
443+
tags = {
444+
emr-key = "emr-value"
445+
}
446+
pre_executed_file_settings {
447+
cos_file_name = "test"
448+
cos_file_uri = "https://keep-tf-test-1308726196.cos.ap-guangzhou.myqcloud.com/test/tmp.sh"
449+
when_run = "resourceAfter"
450+
}
451+
}
452+
`
453+
350454
const testEmrBasic_AddCoreNode = tcacctest.DefaultEMRVariable + `
351455
data "tencentcloud_instance_types" "cvm4c8m" {
352456
exclude_sold_out=true

tencentcloud/services/emr/service_tencentcloud_emr.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,38 @@ func (me *EMRService) CreateInstance(ctx context.Context, d *schema.ResourceData
228228
request.Tags = emrTags
229229
}
230230

231+
if v, ok := d.GetOk("pre_executed_file_settings"); ok {
232+
preExecutedFileSettings := v.([]interface{})
233+
for _, preExecutedFileSetting := range preExecutedFileSettings {
234+
preExecutedFileSettingMap := preExecutedFileSetting.(map[string]interface{})
235+
tmpPreExecutedFileSetting := &emr.PreExecuteFileSettings{}
236+
if v, ok := preExecutedFileSettingMap["args"]; ok {
237+
tmpPreExecutedFileSetting.Args = helper.InterfacesStringsPoint(v.([]interface{}))
238+
}
239+
if v, ok := preExecutedFileSettingMap["run_order"]; ok {
240+
tmpPreExecutedFileSetting.RunOrder = helper.IntInt64(v.(int))
241+
}
242+
if v, ok := preExecutedFileSettingMap["when_run"]; ok {
243+
tmpPreExecutedFileSetting.WhenRun = helper.String(v.(string))
244+
}
245+
if v, ok := preExecutedFileSettingMap["cos_file_name"]; ok {
246+
tmpPreExecutedFileSetting.CosFileName = helper.String(v.(string))
247+
}
248+
if v, ok := preExecutedFileSettingMap["cos_file_uri"]; ok {
249+
tmpPreExecutedFileSetting.CosFileURI = helper.String(v.(string))
250+
}
251+
if v, ok := preExecutedFileSettingMap["cos_secret_id"]; ok {
252+
tmpPreExecutedFileSetting.CosSecretId = helper.String(v.(string))
253+
}
254+
if v, ok := preExecutedFileSettingMap["cos_secret_key"]; ok {
255+
tmpPreExecutedFileSetting.CosSecretKey = helper.String(v.(string))
256+
}
257+
if v, ok := preExecutedFileSettingMap["remark"]; ok {
258+
tmpPreExecutedFileSetting.Remark = helper.String(v.(string))
259+
}
260+
request.PreExecutedFileSettings = append(request.PreExecutedFileSettings, tmpPreExecutedFileSetting)
261+
}
262+
}
231263
ratelimit.Check(request.GetAction())
232264
//API: https://cloud.tencent.com/document/api/589/34261
233265
response, err := me.client.UseEmrClient().CreateInstance(request)

website/docs/r/emr_cluster.html.markdown

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ The following arguments are supported:
136136
By default, the cluster Master node internet is enabled.
137137
* `placement_info` - (Optional, List) The location of the instance.
138138
* `placement` - (Optional, Map, **Deprecated**) It will be deprecated in later versions. Use `placement_info` instead. The location of the instance.
139+
* `pre_executed_file_settings` - (Optional, List, ForceNew) Pre executed file settings.
139140
* `resource_spec` - (Optional, List) Resource specification of EMR instance.
140141
* `sg_id` - (Optional, String, ForceNew) The ID of the security group to which the instance belongs, in the form of sg-xxxxxxxx.
141142
* `tags` - (Optional, Map) Tag description list.
@@ -242,6 +243,17 @@ The `placement_info` object supports the following:
242243
* `zone` - (Required, String) Zone.
243244
* `project_id` - (Optional, Int) Project id.
244245

246+
The `pre_executed_file_settings` object supports the following:
247+
248+
* `args` - (Optional, List, ForceNew) Execution script parameters.
249+
* `cos_file_name` - (Optional, String, ForceNew) Script file name.
250+
* `cos_file_uri` - (Optional, String, ForceNew) The cos address of the script.
251+
* `cos_secret_id` - (Optional, String, ForceNew) Cos secretId.
252+
* `cos_secret_key` - (Optional, String, ForceNew) Cos secretKey.
253+
* `remark` - (Optional, String, ForceNew) Remark.
254+
* `run_order` - (Optional, Int, ForceNew) Run order.
255+
* `when_run` - (Optional, String, ForceNew) `resourceAfter` or `clusterAfter`.
256+
245257
The `resource_spec` object supports the following:
246258

247259
* `common_count` - (Optional, Int, ForceNew) The number of common node.

0 commit comments

Comments
 (0)