Skip to content

Commit

Permalink
resource/alicloud_alikafka_instance: Added the field resource_group_id
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWolong authored and ChenHanZhang committed May 29, 2024
1 parent 205cd4f commit 9b37430
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 44 deletions.
60 changes: 60 additions & 0 deletions alicloud/resource_alicloud_alikafka_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ func resourceAliCloudAlikafkaInstance() *schema.Resource {
return d.Get("deploy_type").(int) == 5
},
},
"resource_group_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"security_group": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -204,26 +209,39 @@ func resourceAliCloudAlikafkaInstanceCreate(d *schema.ResourceData, meta interfa
createOrderResponse := make(map[string]interface{})
createOrderReq := make(map[string]interface{})
createOrderReq["RegionId"] = client.RegionId

if v, ok := d.GetOk("partition_num"); ok {
createOrderReq["PartitionNum"] = v
} else if v, ok := d.GetOk("topic_quota"); ok {
createOrderReq["TopicQuota"] = v
}

createOrderReq["DiskType"] = d.Get("disk_type")

createOrderReq["DiskSize"] = d.Get("disk_size")

createOrderReq["DeployType"] = d.Get("deploy_type")

if v, ok := d.GetOk("io_max"); ok {
createOrderReq["IoMax"] = v
}

if v, ok := d.GetOk("io_max_spec"); ok {
createOrderReq["IoMaxSpec"] = v
}

if v, ok := d.GetOk("spec_type"); ok {
createOrderReq["SpecType"] = v
}

if v, ok := d.GetOkExists("eip_max"); ok {
createOrderReq["EipMax"] = v
}

if v, ok := d.GetOk("resource_group_id"); ok {
createOrderReq["ResourceGroupId"] = v
}

if v, ok := d.GetOk("paid_type"); ok {
switch v.(string) {
case "PostPaid":
Expand Down Expand Up @@ -360,6 +378,7 @@ func resourceAliCloudAlikafkaInstanceRead(d *schema.ResourceData, meta interface
d.Set("deploy_type", object["DeployType"])
d.Set("io_max", object["IoMax"])
d.Set("eip_max", object["EipMax"])
d.Set("resource_group_id", object["ResourceGroupId"])
d.Set("vpc_id", object["VpcId"])
d.Set("vswitch_id", object["VSwitchId"])
d.Set("zone_id", object["ZoneId"])
Expand Down Expand Up @@ -415,6 +434,7 @@ func resourceAliCloudAlikafkaInstanceUpdate(d *schema.ResourceData, meta interfa
if err := alikafkaService.setInstanceTags(d, TagResourceInstance); err != nil {
return WrapError(err)
}

if d.IsNewResource() {
d.Partial(false)
return resourceAliCloudAlikafkaInstanceRead(d, meta)
Expand Down Expand Up @@ -693,7 +713,47 @@ func resourceAliCloudAlikafkaInstanceUpdate(d *schema.ResourceData, meta interfa
d.SetPartial("config")
}

update = false
changeResourceGroupReq := map[string]interface{}{
"RegionId": client.RegionId,
"ResourceId": d.Id(),
}

if d.HasChange("resource_group_id") {
update = true
}
if v, ok := d.GetOk("resource_group_id"); ok {
changeResourceGroupReq["NewResourceGroupId"] = v
}

if update {
action := "ChangeResourceGroup"

runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(client.GetRetryTimeout(d.Timeout(schema.TimeoutUpdate)), func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-09-16"), StringPointer("AK"), nil, changeResourceGroupReq, &runtime)
if err != nil {
if NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
addDebug(action, response, changeResourceGroupReq)

if err != nil {
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR)
}

d.SetPartial("resource_group_id")
}

d.Partial(false)

return resourceAliCloudAlikafkaInstanceRead(d, meta)
}

Expand Down
90 changes: 46 additions & 44 deletions alicloud/resource_alicloud_alikafka_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,42 +319,42 @@ func TestAccAliCloudAlikafkaInstance_convert(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccConfig(map[string]interface{}{
"name": "${var.name}",
"partition_num": "50",
"disk_type": "1",
"disk_size": "500",
"deploy_type": "4",
"eip_max": "3",
"io_max": "20",
"vswitch_id": "${data.alicloud_vswitches.default.ids.0}",
"paid_type": "PostPaid",
"spec_type": "normal",
"service_version": "2.2.0",
"name": "${var.name}",
"partition_num": "50",
"disk_type": "1",
"disk_size": "500",
"deploy_type": "4",
"eip_max": "3",
"io_max": "20",
"vswitch_id": "${data.alicloud_vswitches.default.ids.0}",
"paid_type": "PostPaid",
"spec_type": "normal",
"service_version": "2.2.0",
"resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.groups.1.id}",
//"config": `{\"enable.vpc_sasl_ssl\":\"false\",\"kafka.log.retention.hours\":\"72\",\"enable.acl\":\"false\",\"kafka.message.max.bytes\":\"1048576\"}`,
"tags": map[string]string{
"Created": "TF",
"For": "acceptance test",
},
"security_group": "${data.alicloud_security_groups.default.ids.0}",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"name": name,
"partition_num": "50",
"topic_quota": "1050",
"disk_type": "1",
"disk_size": "500",
"deploy_type": "4",
"eip_max": "3",
"io_max": "20",
"paid_type": "PostPaid",
"spec_type": "normal",
"service_version": "2.2.0",
"name": name,
"partition_num": "50",
"topic_quota": "1050",
"disk_type": "1",
"disk_size": "500",
"deploy_type": "4",
"eip_max": "3",
"io_max": "20",
"paid_type": "PostPaid",
"spec_type": "normal",
"service_version": "2.2.0",
"resource_group_id": CHECKSET,
//"config": "{\"enable.vpc_sasl_ssl\":\"false\",\"kafka.log.retention.hours\":\"72\",\"enable.acl\":\"false\",\"kafka.message.max.bytes\":\"1048576\"}",
"tags.%": "2",
"tags.Created": "TF",
"tags.For": "acceptance test",
"security_group": CHECKSET,
"tags.%": "2",
"tags.Created": "TF",
"tags.For": "acceptance test",
}),
),
},
Expand Down Expand Up @@ -386,12 +386,10 @@ func TestAccAliCloudAlikafkaInstance_prepaid(t *testing.T) {
}
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, serviceFunc, "DescribeAliKafkaInstance")
rac := resourceAttrCheckInit(rc, ra)

rand := acctest.RandInt()
testAccCheck := rac.resourceAttrMapUpdateSet()
name := fmt.Sprintf("tf-testacc-alikafkainstancepre%v", rand)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, resourceAlikafkaInstancePrePaidConfigDependence)

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
Expand All @@ -418,7 +416,6 @@ func TestAccAliCloudAlikafkaInstance_prepaid(t *testing.T) {
"Created": "TF",
"For": "acceptance test",
},
"security_group": "${data.alicloud_security_groups.default.ids.0}",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
Expand All @@ -434,10 +431,9 @@ func TestAccAliCloudAlikafkaInstance_prepaid(t *testing.T) {
"spec_type": "normal",
"service_version": "2.2.0",
//"config": "{\"enable.vpc_sasl_ssl\":\"false\",\"kafka.log.retention.hours\":\"72\",\"enable.acl\":\"false\",\"kafka.message.max.bytes\":\"1048576\"}",
"tags.%": "2",
"tags.Created": "TF",
"tags.For": "acceptance test",
"security_group": CHECKSET,
"tags.%": "2",
"tags.Created": "TF",
"tags.For": "acceptance test",
}),
),
},
Expand Down Expand Up @@ -545,6 +541,16 @@ func TestAccAliCloudAlikafkaInstance_VpcId(t *testing.T) {
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.groups.1.id}",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"resource_group_id": CHECKSET,
}),
),
},
{
ResourceName: resourceId,
ImportState: true,
Expand All @@ -561,6 +567,9 @@ func resourceAlikafkaInstanceConfigDependence(name string) string {
default = "%s"
}
data "alicloud_resource_manager_resource_groups" "default" {
}
data "alicloud_vpcs" "default" {
name_regex = "^default-NODELETING$"
}
Expand Down Expand Up @@ -588,23 +597,16 @@ func resourceAlikafkaInstancePrePaidConfigDependence(name string) string {
default = "%s"
}
data "alicloud_resource_manager_resource_groups" "default" {
}
data "alicloud_vpcs" "default" {
name_regex = "^default-NODELETING$"
}
data "alicloud_vswitches" "default" {
vpc_id = data.alicloud_vpcs.default.ids.0
}
data "alicloud_security_groups" "default" {
vpc_id = data.alicloud_vpcs.default.ids.0
}
resource "alicloud_kms_key" "key" {
description = var.name
pending_window_in_days = "7"
status = "Enabled"
}
`, name)
}

Expand Down
1 change: 1 addition & 0 deletions website/docs/r/alikafka_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ The following arguments are supported:
- You should specify one of the `io_max` and `io_max_spec` parameters, and `io_max_spec` is recommended.
- For more information about the valid values, see [Billing](https://www.alibabacloud.com/help/en/message-queue-for-apache-kafka/latest/billing-overview).
* `eip_max` - (Optional) The max bandwidth of the instance. It will be ignored when `deploy_type = 5`. When modify this value, it only supports adjust to a greater value.
* `resource_group_id` - (Optional, Available since v1.224.0) The ID of the resource group. **Note:** Once you set a value of this property, you cannot set it to an empty string anymore.
* `paid_type` - (Optional) The paid type of the instance. Support two type, "PrePaid": pre paid type instance, "PostPaid": post paid type instance. Default is PostPaid. When modify this value, it only support adjust from post pay to pre pay.
* `spec_type` - (Optional) The spec type of the instance. Support two type, "normal": normal version instance, "professional": professional version instance. Default is normal. When modify this value, it only support adjust from normal to professional. Note only pre paid type instance support professional specific type.
* `vswitch_id` - (Required, ForceNew) The ID of attaching vswitch to instance.
Expand Down

0 comments on commit 9b37430

Please sign in to comment.