Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(emr): [121046444] lite hbase support prepay #3002

Merged
merged 7 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/3002.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:deprecation
resource/tencentcloud_lite_hbase_instance
```

```release-note:new-resource
tencentcloud_serverless_hbase_instance
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/domain v1.0.414
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dts v1.0.628
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/eb v1.0.760
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/emr v1.0.1004
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/emr v1.0.1055
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es v1.0.777
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.970
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.563
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/eb v1.0.760 h1:IKP2LFgJ
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/eb v1.0.760/go.mod h1:pSQXTeuC6BahiUIfssVqvL1/BoXccLkyD7nJ+tKgygw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/emr v1.0.1004 h1:PbKCgIXZSwX0eraNZGG+AqVjgLZwW/C+up/6mL9FP3o=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/emr v1.0.1004/go.mod h1:6H1XZ2TIVV6VHdjkdQQl611NsIJkeTqugZ1jaUfPop4=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/emr v1.0.1055 h1:CAxiWYRFmvpcDMkpoF7E0HZXgpM2BPYE+uyrS92LPQE=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/emr v1.0.1055/go.mod h1:tmcOt09PyU+2nQgdbz0Lwe8aS8/Sb1spemL9kxusCPU=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es v1.0.777 h1:G1eX/DkiznhSjNVF97BAQyycFXOiPHxeTxgOadp5J/o=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es v1.0.777/go.mod h1:ehbc9eaNknF/VU/kPTFLZbIUmkL06vQ/JYydu6yeXp4=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.970 h1:Z82LbcEnE2m4CGvcOY024N7REhAN++xdEyE88HG2YBA=
Expand Down
1 change: 1 addition & 0 deletions tencentcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2190,6 +2190,7 @@ func Provider() *schema.Provider {
"tencentcloud_thpc_workspaces": thpc.ResourceTencentCloudThpcWorkspaces(),
"tencentcloud_kubernetes_health_check_policy": tke.ResourceTencentCloudKubernetesHealthCheckPolicy(),
"tencentcloud_lite_hbase_instance": emr.ResourceTencentCloudLiteHbaseInstance(),
"tencentcloud_serverless_hbase_instance": emr.ResourceTencentCloudServerlessHbaseInstance(),
"tencentcloud_kubernetes_log_config": tke.ResourceTencentCloudKubernetesLogConfig(),
"tencentcloud_tcss_image_registry": tcss.ResourceTencentCloudTcssImageRegistry(),
},
Expand Down
1 change: 1 addition & 0 deletions tencentcloud/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,7 @@ MapReduce(EMR)
tencentcloud_emr_cluster
tencentcloud_emr_user_manager
tencentcloud_lite_hbase_instance
tencentcloud_serverless_hbase_instance

DNSPOD
Resource
Expand Down
92 changes: 79 additions & 13 deletions tencentcloud/services/emr/resource_tc_lite_hbase_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import (

func ResourceTencentCloudLiteHbaseInstance() *schema.Resource {
return &schema.Resource{
Create: resourceTencentCloudLiteHbaseInstanceCreate,
Read: resourceTencentCloudLiteHbaseInstanceRead,
Update: resourceTencentCloudLiteHbaseInstanceUpdate,
Delete: resourceTencentCloudLiteHbaseInstanceDelete,
DeprecationMessage: "This resource will been deprecated in Terraform TencentCloud provider later version. Please use `tencentcloud_serverless_hbase_instance` instead.",
Create: resourceTencentCloudLiteHbaseInstanceCreate,
Read: resourceTencentCloudLiteHbaseInstanceRead,
Update: resourceTencentCloudLiteHbaseInstanceUpdate,
Delete: resourceTencentCloudLiteHbaseInstanceDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Expand All @@ -34,24 +35,24 @@ func ResourceTencentCloudLiteHbaseInstance() *schema.Resource {
"pay_mode": {
Type: schema.TypeInt,
Required: true,
Description: "Instance pay mode. Value range: 0: indicates post pay mode, that is, pay-as-you-go.",
Description: "Instance pay mode. Value range: 0: indicates post-pay mode, that is, pay-as-you-go. 1: indicates pre-pay mode, that is, monthly subscription.",
},

"disk_type": {
Type: schema.TypeString,
Required: true,
Description: "Instance disk type, fill in CLOUD_HSSD to indicate performance cloud storage.",
Description: "Instance disk type, Value range: CLOUD_HSSD: indicate performance cloud storage(ESSD). CLOUD_BSSD: indicate standard cloud storage(SSD).",
},

"disk_size": {
Type: schema.TypeInt,
Required: true,
Description: "Instance single-node disk capacity, in GB. The single-node disk capacity must be greater than or equal to 100 and less than or equal to 10000, with an adjustment step size of 20.",
Description: "Instance single-node disk capacity, in GB. The single-node disk capacity must be greater than or equal to 100 and less than or equal to 250 times the number of CPU cores. The capacity adjustment step is 100.",
},

"node_type": {
Type: schema.TypeString,
Required: true,
Optional: true,
Description: "Instance node type, can be filled in as 4C16G, 8C32G, 16C64G, 32C128G, case insensitive.",
},

Expand Down Expand Up @@ -114,6 +115,23 @@ func ResourceTencentCloudLiteHbaseInstance() *schema.Resource {
},
},
},

"time_span": {
Type: schema.TypeInt,
Optional: true,
Description: "Time span.",
},
"time_unit": {
Type: schema.TypeString,
Optional: true,
Description: "Time unit, fill in m which means month.",
},
"auto_renew_flag": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "AutoRenewFlag, Value range: 0: indicates NOTIFY_AND_MANUAL_RENEW; 1: indicates NOTIFY_AND_AUTO_RENEW; 2: indicates DISABLE_NOTIFY_AND_MANUAL_RENEW.",
},
},
}
}
Expand Down Expand Up @@ -189,6 +207,31 @@ func resourceTencentCloudLiteHbaseInstanceCreate(d *schema.ResourceData, meta in
}
}

var prePaySetting *emr.PrePaySetting
if v, ok := d.GetOk("time_span"); ok {
prePaySetting = &emr.PrePaySetting{}
prePaySetting.Period = &emr.Period{}
prePaySetting.Period.TimeSpan = helper.IntInt64(v.(int))
}
if v, ok := d.GetOk("time_unit"); ok {
if prePaySetting == nil {
prePaySetting = &emr.PrePaySetting{}
}
if prePaySetting.Period == nil {
prePaySetting.Period = &emr.Period{}
}
prePaySetting.Period.TimeUnit = helper.String(v.(string))
}
if v, ok := d.GetOk("auto_renew_flag"); ok {
if prePaySetting == nil {
prePaySetting = &emr.PrePaySetting{}
}
prePaySetting.AutoRenewFlag = helper.IntInt64(v.(int))
}
if prePaySetting != nil {
request.PrePaySetting = prePaySetting
}

err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseEmrClient().CreateSLInstanceWithContext(ctx, request)
if e != nil {
Expand Down Expand Up @@ -267,10 +310,6 @@ func resourceTencentCloudLiteHbaseInstanceRead(d *schema.ResourceData, meta inte
_ = d.Set("disk_size", respData.DiskSize)
}

if respData.NodeType != nil {
_ = d.Set("node_type", respData.NodeType)
}

zoneSettingsList := make([]map[string]interface{}, 0, len(respData.ZoneSettings))
if respData.ZoneSettings != nil {
for _, zoneSettings := range respData.ZoneSettings {
Expand Down Expand Up @@ -322,6 +361,9 @@ func resourceTencentCloudLiteHbaseInstanceRead(d *schema.ResourceData, meta inte

_ = d.Set("tags", tagsList)
}
if respData.AutoRenewFlag != nil {
_ = d.Set("auto_renew_flag", respData.AutoRenewFlag)
}

_ = instanceId
return nil
Expand All @@ -335,7 +377,7 @@ func resourceTencentCloudLiteHbaseInstanceUpdate(d *schema.ResourceData, meta in

ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)

immutableArgs := []string{"instance_name", "pay_mode", "disk_type", "disk_size", "node_type", "tags"}
immutableArgs := []string{"instance_name", "pay_mode", "disk_type", "disk_size", "node_type", "tags", "time_span", "time_unit", "auto_renew_flag"}
for _, v := range immutableArgs {
if d.HasChange(v) {
return fmt.Errorf("argument `%s` cannot be changed", v)
Expand Down Expand Up @@ -434,9 +476,33 @@ func resourceTencentCloudLiteHbaseInstanceDelete(d *schema.ResourceData, meta in
log.Printf("[CRITAL]%s delete lite hbase instance failed, reason:%+v", logId, err)
return err
}

emrService := EMRService{
client: meta.(tccommon.ProviderMeta).GetAPIV3Conn(),
}

if d.Get("pay_mode").(int) == 1 {
conf := tccommon.BuildStateChangeConf([]string{}, []string{"201"}, 10*tccommon.ReadRetryTimeout, time.Second, emrService.SLInstanceStateRefreshFunc(instanceId, []string{}))
if _, e := conf.WaitForState(); e != nil {
return e
}

err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseEmrClient().TerminateSLInstanceWithContext(ctx, request)
if e != nil {
return tccommon.RetryError(e)
} else {
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
}
response = result
return nil
})
if err != nil {
log.Printf("[CRITAL]%s delete lite hbase instance failed, reason:%+v", logId, err)
return err
}
}

conf := tccommon.BuildStateChangeConf([]string{}, []string{"-2"}, 10*tccommon.ReadRetryTimeout, time.Second, emrService.SLInstanceStateRefreshFunc(instanceId, []string{}))
if _, e := conf.WaitForState(); e != nil {
return e
Expand Down
64 changes: 61 additions & 3 deletions tencentcloud/services/emr/resource_tc_lite_hbase_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func TestAccTencentCloudLiteHbaseInstanceResource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
tcacctest.AccStepSetRegion(t, "ap-shanghai")
tcacctest.AccPreCheck(t)
},
Providers: tcacctest.AccProviders,
Expand Down Expand Up @@ -51,9 +52,40 @@ func TestAccTencentCloudLiteHbaseInstanceResource_basic(t *testing.T) {
),
},
{
ResourceName: "tencentcloud_lite_hbase_instance.lite_hbase_instance",
ImportState: true,
ImportStateVerify: true,
ResourceName: "tencentcloud_lite_hbase_instance.lite_hbase_instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"node_type", "time_span", "time_unit"},
},
},
})
}

func TestAccTencentCloudLiteHbaseInstanceResource_prepay(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
tcacctest.AccStepSetRegion(t, "ap-shanghai")
tcacctest.AccPreCheck(t)
},
Providers: tcacctest.AccProviders,
Steps: []resource.TestStep{
{
Config: testAccLiteHbaseInstancePrePay,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("tencentcloud_lite_hbase_instance.lite_hbase_instance_prepay", "id"),
resource.TestCheckResourceAttr("tencentcloud_lite_hbase_instance.lite_hbase_instance_prepay", "instance_name", "tf-test-prepay"),
resource.TestCheckResourceAttr("tencentcloud_lite_hbase_instance.lite_hbase_instance_prepay", "pay_mode", "1"),
resource.TestCheckResourceAttr("tencentcloud_lite_hbase_instance.lite_hbase_instance_prepay", "time_span", "1"),
resource.TestCheckResourceAttr("tencentcloud_lite_hbase_instance.lite_hbase_instance_prepay", "time_unit", "m"),
resource.TestCheckResourceAttr("tencentcloud_lite_hbase_instance.lite_hbase_instance_prepay", "auto_renew_flag", "1"),
),
},
{
ResourceName: "tencentcloud_lite_hbase_instance.lite_hbase_instance_prepay",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"node_type", "time_span", "time_unit"},
},
},
})
Expand All @@ -63,6 +95,7 @@ func TestAccTencentCloudLiteHbaseInstanceResource_multiZone(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
tcacctest.AccStepSetRegion(t, "ap-shanghai")
tcacctest.AccPreCheck(t)
},
Providers: tcacctest.AccProviders,
Expand Down Expand Up @@ -140,6 +173,31 @@ resource "tencentcloud_lite_hbase_instance" "lite_hbase_instance" {
}
`

const testAccLiteHbaseInstancePrePay = `
resource "tencentcloud_lite_hbase_instance" "lite_hbase_instance_prepay" {
instance_name = "tf-test-prepay"
pay_mode = 1
disk_type = "CLOUD_HSSD"
disk_size = 100
node_type = "4C16G"
zone_settings {
zone = "ap-shanghai-2"
vpc_settings {
vpc_id = "vpc-muytmxhk"
subnet_id = "subnet-9ye3xm5v"
}
node_num = 3
}
tags {
tag_key = "test"
tag_value = "test"
}
time_span = 1
time_unit = "m"
auto_renew_flag = 1
}
`

const testAccLiteHbaseInstanceMultiZone = `
resource "tencentcloud_lite_hbase_instance" "lite_hbase_instance_multi_zone" {
instance_name = "tf-test-multi-zone"
Expand Down
Loading
Loading