From b4b2e02752c611874768f89127ae3a9a914a8141 Mon Sep 17 00:00:00 2001 From: mikatong Date: Fri, 15 Nov 2024 11:11:07 +0800 Subject: [PATCH 1/3] emr support pre_executed_file_settings --- .../services/emr/resource_tc_emr_cluster.go | 61 ++++++++++ .../emr/resource_tc_emr_cluster_test.go | 104 ++++++++++++++++++ .../services/emr/service_tencentcloud_emr.go | 32 ++++++ website/docs/r/emr_cluster.html.markdown | 12 ++ 4 files changed, 209 insertions(+) diff --git a/tencentcloud/services/emr/resource_tc_emr_cluster.go b/tencentcloud/services/emr/resource_tc_emr_cluster.go index 1d4d29277f..9625813f31 100644 --- a/tencentcloud/services/emr/resource_tc_emr_cluster.go +++ b/tencentcloud/services/emr/resource_tc_emr_cluster.go @@ -237,6 +237,67 @@ func ResourceTencentCloudEmrCluster() *schema.Resource { Computed: true, Description: "0 means turn off automatic renewal, 1 means turn on automatic renewal. Default is 0.", }, + "pre_executed_file_settings": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Description: "Pre executed file settings.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "args": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "Execution script parameters.", + }, + "run_order": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + Description: "Run order.", + }, + "when_run": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Description: "`resourceAfter` or `clusterAfter`.", + }, + "cos_file_name": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Description: "Script file name.", + }, + "cos_file_uri": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Description: "The cos address of the script.", + }, + "cos_secret_id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Description: "Cos secretId.", + }, + "cos_secret_key": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Description: "Cos secretKey.", + }, + "remark": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Description: "Remark.", + }, + }, + }, + }, }, } } diff --git a/tencentcloud/services/emr/resource_tc_emr_cluster_test.go b/tencentcloud/services/emr/resource_tc_emr_cluster_test.go index 3a3eeb7ab2..2c641347bd 100644 --- a/tencentcloud/services/emr/resource_tc_emr_cluster_test.go +++ b/tencentcloud/services/emr/resource_tc_emr_cluster_test.go @@ -176,6 +176,26 @@ func TestAccTencentCloudEmrClusterResource_Basic(t *testing.T) { }, }) } + +func TestAccTencentCloudEmrClusterResource_PreExecutedFileSettings(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { tcacctest.AccPreCheck(t) }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{ + { + Config: testEmrBasicPreExecutedFileSettings, + Check: resource.ComposeTestCheckFunc( + testAccCheckEmrExists(testEmrClusterResourceKey), + resource.TestCheckResourceAttr(testEmrClusterResourceKey, "pre_executed_file_settings.#", "1"), + resource.TestCheckResourceAttr(testEmrClusterResourceKey, "pre_executed_file_settings.0.cos_file_name", "test"), + resource.TestCheckResourceAttr(testEmrClusterResourceKey, "pre_executed_file_settings.0.when_run", "resourceAfter"), + resource.TestCheckResourceAttrSet(testEmrClusterResourceKey, "pre_executed_file_settings.0.cos_file_uri"), + ), + }, + }, + }) +} func TestAccTencentCloudEmrClusterResource_Prepay(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ @@ -347,6 +367,90 @@ resource "tencentcloud_emr_cluster" "emrrrr" { } ` +const testEmrBasicPreExecutedFileSettings = tcacctest.DefaultEMRVariable + ` +data "tencentcloud_instance_types" "cvm4c8m" { + exclude_sold_out=true + cpu_core_count=4 + memory_size=8 + filter { + name = "instance-charge-type" + values = ["POSTPAID_BY_HOUR"] + } + filter { + name = "zone" + values = ["ap-guangzhou-3"] + } +} + +resource "tencentcloud_emr_cluster" "emrrrr" { + product_id=38 + vpc_settings={ + vpc_id=var.vpc_id + subnet_id=var.subnet_id + } + softwares = [ + "hdfs-2.8.5", + "knox-1.6.1", + "openldap-2.4.44", + "yarn-2.8.5", + "zookeeper-3.6.3", + ] + support_ha=0 + instance_name="emr-test-demo" + resource_spec { + master_resource_spec { + mem_size=8192 + cpu=4 + disk_size=100 + disk_type="CLOUD_PREMIUM" + spec="CVM.${data.tencentcloud_instance_types.cvm4c8m.instance_types.0.family}" + storage_type=5 + root_size=50 + multi_disks { + disk_type = "CLOUD_PREMIUM" + volume = 200 + count = 1 + } + } + core_resource_spec { + mem_size=8192 + cpu=4 + disk_size=100 + disk_type="CLOUD_PREMIUM" + spec="CVM.${data.tencentcloud_instance_types.cvm4c8m.instance_types.0.family}" + storage_type=5 + root_size=50 + multi_disks { + disk_type = "CLOUD_PREMIUM" + volume = 100 + count = 2 + } + } + master_count=1 + core_count=2 + } + login_settings={ + password="Tencent@cloud123" + } + time_span=3600 + time_unit="s" + pay_mode=0 + placement_info { + zone="ap-guangzhou-3" + project_id=0 + } + sg_id=var.sg_id + tags = { + emr-key = "emr-value" + } + pre_executed_file_settings { + cos_file_name = "test" + cos_file_uri = "https://keep-tf-test-1308726196.cos.ap-guangzhou.myqcloud.com/test/tmp.sh" + when_run = "resourceAfter" + } + } +` + const testEmrBasic_AddCoreNode = tcacctest.DefaultEMRVariable + ` data "tencentcloud_instance_types" "cvm4c8m" { exclude_sold_out=true diff --git a/tencentcloud/services/emr/service_tencentcloud_emr.go b/tencentcloud/services/emr/service_tencentcloud_emr.go index cfff6c9231..261ec028ec 100644 --- a/tencentcloud/services/emr/service_tencentcloud_emr.go +++ b/tencentcloud/services/emr/service_tencentcloud_emr.go @@ -228,6 +228,38 @@ func (me *EMRService) CreateInstance(ctx context.Context, d *schema.ResourceData request.Tags = emrTags } + if v, ok := d.GetOk("pre_executed_file_settings"); ok { + preExecutedFileSettings := v.([]interface{}) + for _, preExecutedFileSetting := range preExecutedFileSettings { + preExecutedFileSettingMap := preExecutedFileSetting.(map[string]interface{}) + tmpPreExecutedFileSetting := &emr.PreExecuteFileSettings{} + if v, ok := preExecutedFileSettingMap["args"]; ok { + tmpPreExecutedFileSetting.Args = helper.InterfacesStringsPoint(v.([]interface{})) + } + if v, ok := preExecutedFileSettingMap["run_order"]; ok { + tmpPreExecutedFileSetting.RunOrder = helper.IntInt64(v.(int)) + } + if v, ok := preExecutedFileSettingMap["when_run"]; ok { + tmpPreExecutedFileSetting.WhenRun = helper.String(v.(string)) + } + if v, ok := preExecutedFileSettingMap["cos_file_name"]; ok { + tmpPreExecutedFileSetting.CosFileName = helper.String(v.(string)) + } + if v, ok := preExecutedFileSettingMap["cos_file_uri"]; ok { + tmpPreExecutedFileSetting.CosFileURI = helper.String(v.(string)) + } + if v, ok := preExecutedFileSettingMap["cos_secret_id"]; ok { + tmpPreExecutedFileSetting.CosSecretId = helper.String(v.(string)) + } + if v, ok := preExecutedFileSettingMap["cos_secret_key"]; ok { + tmpPreExecutedFileSetting.CosSecretKey = helper.String(v.(string)) + } + if v, ok := preExecutedFileSettingMap["remark"]; ok { + tmpPreExecutedFileSetting.Remark = helper.String(v.(string)) + } + request.PreExecutedFileSettings = append(request.PreExecutedFileSettings, tmpPreExecutedFileSetting) + } + } ratelimit.Check(request.GetAction()) //API: https://cloud.tencent.com/document/api/589/34261 response, err := me.client.UseEmrClient().CreateInstance(request) diff --git a/website/docs/r/emr_cluster.html.markdown b/website/docs/r/emr_cluster.html.markdown index 1bd35736dd..f1d0eea767 100644 --- a/website/docs/r/emr_cluster.html.markdown +++ b/website/docs/r/emr_cluster.html.markdown @@ -136,6 +136,7 @@ The following arguments are supported: By default, the cluster Master node internet is enabled. * `placement_info` - (Optional, List) The location of the instance. * `placement` - (Optional, Map, **Deprecated**) It will be deprecated in later versions. Use `placement_info` instead. The location of the instance. +* `pre_executed_file_settings` - (Optional, List, ForceNew) Pre executed file settings. * `resource_spec` - (Optional, List) Resource specification of EMR instance. * `sg_id` - (Optional, String, ForceNew) The ID of the security group to which the instance belongs, in the form of sg-xxxxxxxx. * `tags` - (Optional, Map) Tag description list. @@ -242,6 +243,17 @@ The `placement_info` object supports the following: * `zone` - (Required, String) Zone. * `project_id` - (Optional, Int) Project id. +The `pre_executed_file_settings` object supports the following: + +* `args` - (Optional, List, ForceNew) Execution script parameters. +* `cos_file_name` - (Optional, String, ForceNew) Script file name. +* `cos_file_uri` - (Optional, String, ForceNew) The cos address of the script. +* `cos_secret_id` - (Optional, String, ForceNew) Cos secretId. +* `cos_secret_key` - (Optional, String, ForceNew) Cos secretKey. +* `remark` - (Optional, String, ForceNew) Remark. +* `run_order` - (Optional, Int, ForceNew) Run order. +* `when_run` - (Optional, String, ForceNew) `resourceAfter` or `clusterAfter`. + The `resource_spec` object supports the following: * `common_count` - (Optional, Int, ForceNew) The number of common node. From b07c655bfc0460e33023313d218297c1d6d9f892 Mon Sep 17 00:00:00 2001 From: mikatong Date: Fri, 15 Nov 2024 15:17:35 +0800 Subject: [PATCH 2/3] add changelog --- .changelog/2960.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/2960.txt diff --git a/.changelog/2960.txt b/.changelog/2960.txt new file mode 100644 index 0000000000..58e3050bdd --- /dev/null +++ b/.changelog/2960.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_emr_cluster: support param pre_executed_file_settings +``` From 276c1265ab89bc0eb6e8d5c960213ac41f0eb72c Mon Sep 17 00:00:00 2001 From: mikatong Date: Fri, 15 Nov 2024 18:07:08 +0800 Subject: [PATCH 3/3] update doc --- tencentcloud/services/emr/resource_tc_emr_cluster.go | 2 +- website/docs/r/emr_cluster.html.markdown | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tencentcloud/services/emr/resource_tc_emr_cluster.go b/tencentcloud/services/emr/resource_tc_emr_cluster.go index 9625813f31..5d44ae9940 100644 --- a/tencentcloud/services/emr/resource_tc_emr_cluster.go +++ b/tencentcloud/services/emr/resource_tc_emr_cluster.go @@ -241,7 +241,7 @@ func ResourceTencentCloudEmrCluster() *schema.Resource { Type: schema.TypeList, Optional: true, ForceNew: true, - Description: "Pre executed file settings.", + Description: "Pre executed file settings. It can only be set at the time of creation, and cannot be modified.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "args": { diff --git a/website/docs/r/emr_cluster.html.markdown b/website/docs/r/emr_cluster.html.markdown index f1d0eea767..923b9012cc 100644 --- a/website/docs/r/emr_cluster.html.markdown +++ b/website/docs/r/emr_cluster.html.markdown @@ -136,7 +136,7 @@ The following arguments are supported: By default, the cluster Master node internet is enabled. * `placement_info` - (Optional, List) The location of the instance. * `placement` - (Optional, Map, **Deprecated**) It will be deprecated in later versions. Use `placement_info` instead. The location of the instance. -* `pre_executed_file_settings` - (Optional, List, ForceNew) Pre executed file settings. +* `pre_executed_file_settings` - (Optional, List, ForceNew) Pre executed file settings. It can only be set at the time of creation, and cannot be modified. * `resource_spec` - (Optional, List) Resource specification of EMR instance. * `sg_id` - (Optional, String, ForceNew) The ID of the security group to which the instance belongs, in the form of sg-xxxxxxxx. * `tags` - (Optional, Map) Tag description list.