Skip to content

Commit

Permalink
fix(emr): [119015728] update read need_master_wan (#2768)
Browse files Browse the repository at this point in the history
* fix emr need_master_wan

* add changelog

---------

Co-authored-by: mikatong <mikatong@tencent.com>
  • Loading branch information
tongyiming and mikatong authored Aug 9, 2024
1 parent b6e5577 commit ffbf490
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .changelog/2768.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_emr_cluster: fix read need_master_wan
```
6 changes: 3 additions & 3 deletions tencentcloud/acctest/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ variable "default_project" {

// EMR
const (
DefaultEMRVpcId = DefaultVpcId
DefaultEMRSubnetId = DefaultSubnetId
DefaultEMRSgId = "sg-694qit0p"
DefaultEMRVpcId = "vpc-axrsmmrv"
DefaultEMRSubnetId = "subnet-j5vja918"
DefaultEMRSgId = "sg-bzbu5ezt"
)

const DefaultEMRVariable = `
Expand Down
16 changes: 4 additions & 12 deletions tencentcloud/services/emr/resource_tc_emr_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,8 @@ func resourceTencentCloudEmrClusterCreate(d *schema.ResourceData, meta interface
err = resource.Retry(10*tccommon.ReadRetryTimeout, func() *resource.RetryError {
clusters, err := emrService.DescribeInstancesById(ctx, instanceId, displayStrategy)

if e, ok := err.(*errors.TencentCloudSDKError); ok {
if e.GetCode() == "InternalError.ClusterNotFound" {
return nil
}
if err != nil {
return resource.RetryableError(err)
}

if len(clusters) > 0 {
Expand All @@ -342,9 +340,6 @@ func resourceTencentCloudEmrClusterCreate(d *schema.ResourceData, meta interface
}
}

if err != nil {
return resource.RetryableError(err)
}
return nil
})
if err != nil {
Expand Down Expand Up @@ -377,10 +372,7 @@ func resourceTencentCloudEmrClusterDelete(d *schema.ResourceData, meta interface
clusters, err := emrService.DescribeInstancesById(ctx, instanceId, DisplayStrategyIsclusterList)

if e, ok := err.(*errors.TencentCloudSDKError); ok {
if e.GetCode() == "InternalError.ClusterNotFound" {
return nil
}
if e.GetCode() == "UnauthorizedOperation" {
if e.GetCode() == "ResourceNotFound.InstanceNotFound" {
return nil
}
}
Expand Down Expand Up @@ -619,7 +611,7 @@ func resourceTencentCloudEmrClusterRead(d *schema.ResourceData, meta interface{}
"zone": *instance.Zone,
})
_ = d.Set("placement_info", []interface{}{placement})
if instance.MasterIp != nil {
if instance.MasterIp != nil && len(*instance.MasterIp) > 2 {
_ = d.Set("need_master_wan", "NEED_MASTER_WAN")
} else {
_ = d.Set("need_master_wan", "NOT_NEED_MASTER_WAN")
Expand Down
89 changes: 88 additions & 1 deletion tencentcloud/services/emr/resource_tc_emr_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ var testEmrClusterResourceKey = "tencentcloud_emr_cluster.emrrrr"
func TestAccTencentCloudEmrClusterResource(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { tcacctest.AccPreCheckCommon(t, tcacctest.ACCOUNT_TYPE_COMMON) },
PreCheck: func() { tcacctest.AccPreCheck(t) },
Providers: tcacctest.AccProviders,
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -167,6 +167,23 @@ func TestAccTencentCloudEmrClusterResource(t *testing.T) {
})
}

func TestAccTencentCloudEmrClusterResource_NotNeedMasterWan(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { tcacctest.AccPreCheck(t) },
Providers: tcacctest.AccProviders,
Steps: []resource.TestStep{
{
Config: testEmrNotNeedMasterWan,
Check: resource.ComposeTestCheckFunc(
testAccCheckEmrExists(testEmrClusterResourceKey),
resource.TestCheckResourceAttr(testEmrClusterResourceKey, "need_master_wan", "NOT_NEED_MASTER_WAN"),
),
},
},
})
}

func testAccCheckEmrExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {

Expand Down Expand Up @@ -277,3 +294,73 @@ resource "tencentcloud_emr_cluster" "emrrrr" {
}
}
`

const testEmrNotNeedMasterWan = 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
}
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
}
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"
}
need_master_wan = "NOT_NEED_MASTER_WAN"
}
`

0 comments on commit ffbf490

Please sign in to comment.