Skip to content

Commit

Permalink
resource/alicloud_ga_accelerator: Added the field resource_group_id
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWolong committed Jun 25, 2024
1 parent 51e9a16 commit dbf909c
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
55 changes: 55 additions & 0 deletions alicloud/resource_alicloud_ga_accelerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ func resourceAliCloudGaAccelerator() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"resource_group_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"accelerator_name": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -153,6 +158,10 @@ func resourceAliCloudGaAcceleratorCreate(d *schema.ResourceData, meta interface{
request["PromotionOptionNo"] = v
}

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

runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2019-11-20"), StringPointer("AK"), nil, request, &runtime)
Expand Down Expand Up @@ -190,6 +199,7 @@ func resourceAliCloudGaAcceleratorRead(d *schema.ResourceData, meta interface{})
d.Set("payment_type", convertGaAcceleratorPaymentTypeResponse(object["InstanceChargeType"]))
d.Set("cross_border_status", object["CrossBorderStatus"])
d.Set("cross_border_mode", object["CrossBorderMode"])
d.Set("resource_group_id", object["ResourceGroupId"])
d.Set("accelerator_name", object["Name"])
d.Set("description", object["Description"])
d.Set("status", object["State"])
Expand Down Expand Up @@ -435,6 +445,51 @@ func resourceAliCloudGaAcceleratorUpdate(d *schema.ResourceData, meta interface{
d.SetPartial("cross_border_mode")
}

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

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

if update {
action := "ChangeResourceGroup"
conn, err := client.NewGaplusClient()
if err != nil {
return WrapError(err)
}

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-11-20"), 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 resourceAliCloudGaAcceleratorRead(d, meta)
Expand Down
32 changes: 30 additions & 2 deletions alicloud/resource_alicloud_ga_accelerator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,16 @@ func TestAccAliCloudGaAccelerator_basic0(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,
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"accelerator_name": name,
Expand Down Expand Up @@ -386,6 +396,7 @@ func TestAccAliCloudGaAccelerator_basic0_twin(t *testing.T) {
"auto_use_coupon": "false",
"renewal_status": "AutoRenewal",
"auto_renew_duration": "1",
"resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.groups.1.id}",
"accelerator_name": name,
"description": name,
"tags": map[string]string{
Expand All @@ -403,6 +414,7 @@ func TestAccAliCloudGaAccelerator_basic0_twin(t *testing.T) {
"auto_use_coupon": "false",
"renewal_status": "AutoRenewal",
"auto_renew_duration": "1",
"resource_group_id": CHECKSET,
"accelerator_name": name,
"description": name,
"tags.%": "2",
Expand Down Expand Up @@ -440,7 +452,7 @@ func TestAccAliCloudGaAccelerator_basic1(t *testing.T) {
},
IDRefreshName: resourceId,
Providers: testAccProviders,
CheckDestroy: nil,
CheckDestroy: rac.checkResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccConfig(map[string]interface{}{
Expand Down Expand Up @@ -474,6 +486,16 @@ func TestAccAliCloudGaAccelerator_basic1(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,
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"accelerator_name": name,
Expand Down Expand Up @@ -546,6 +568,7 @@ func TestAccAliCloudGaAccelerator_basic1_twin(t *testing.T) {
"payment_type": "PayAsYouGo",
"cross_border_status": "true",
"cross_border_mode": "bgpPro",
"resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.groups.1.id}",
"accelerator_name": name,
"description": name,
"tags": map[string]string{
Expand All @@ -559,6 +582,7 @@ func TestAccAliCloudGaAccelerator_basic1_twin(t *testing.T) {
"payment_type": "PayAsYouGo",
"cross_border_status": "true",
"cross_border_mode": "bgpPro",
"resource_group_id": CHECKSET,
"accelerator_name": name,
"description": name,
"tags.%": "2",
Expand All @@ -580,11 +604,15 @@ func TestAccAliCloudGaAccelerator_basic1_twin(t *testing.T) {
var AliCloudGaAcceleratorMap0 = map[string]string{
"bandwidth_billing_type": CHECKSET,
"payment_type": CHECKSET,
"resource_group_id": CHECKSET,
"status": CHECKSET,
}

func AliCloudGaAcceleratorBasicDependence0(name string) string {
return ""
return fmt.Sprintf(`
data "alicloud_resource_manager_resource_groups" "default" {
}
`)
}

func TestUnitAliCloudGaAccelerator(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/ga_accelerator.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ The following arguments are supported:
- `NotRenewal`: No renewal any longer. After you specify this value, Alibaba Cloud stop sending notification of instance expiry, and only gives a brief reminder on the third day before the instance expiry.
* `auto_renew_duration` - (Optional, Int, Available since v1.146.0) Auto renewal period of an instance, in the unit of month. The value range is 1-12.
* `promotion_option_no` - (Optional, Available since v1.208.1) The code of the coupon. **NOTE:** The `promotion_option_no` takes effect only for accounts registered on the international site (alibabacloud.com).
* `resource_group_id` - (Optional, Available since v1.226.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.
* `accelerator_name` - (Optional) The Name of the GA instance.
* `description` - (Optional) Descriptive information of the global acceleration instance.
* `tags` - (Optional, Available since v1.207.1) A mapping of tags to assign to the resource.
Expand Down

0 comments on commit dbf909c

Please sign in to comment.