Skip to content

Commit

Permalink
lite hbase support prepay
Browse files Browse the repository at this point in the history
  • Loading branch information
mikatong committed Dec 6, 2024
1 parent 1722c24 commit ae5ffd7
Show file tree
Hide file tree
Showing 10 changed files with 1,392 additions and 188 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1034
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1046
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1052
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1055
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1014
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.692
Expand All @@ -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
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1051 h1:3mg
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1051/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1052 h1:RCs8aH5Gy1sn4qc22KweqQE7usx1S2reyZcedo0ZXBI=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1052/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1055 h1:qDpGP5ee98ZW5m0192E/cvw18PGAjaqIqYuqaFME2iE=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1055/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993 h1:WlPgXldQCxt7qi5Xrc6j6zTrsXWzN5BcOGs7Irq7fwQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993/go.mod h1:Z9U8zNtyuyKhjS0698wqsrG/kLx1TQ5CEixXBwVe7xY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860 h1:F3esKBIT3HW9+7Gt8cVgf8X06VdGIczpgLBUECzSEzU=
Expand Down Expand Up @@ -966,6 +968,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
81 changes: 73 additions & 8 deletions tencentcloud/services/emr/resource_tc_lite_hbase_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ 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": {
Expand Down Expand Up @@ -114,6 +114,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 +206,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 +309,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 +360,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 +376,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 +475,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
61 changes: 58 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 @@ -51,9 +51,39 @@ 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.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 Down Expand Up @@ -140,6 +170,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-guangzhou-6"
vpc_settings {
vpc_id = "vpc-a5pph3hr"
subnet_id = "subnet-bpr2mo2g"
}
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ae5ffd7

Please sign in to comment.