Skip to content

Commit

Permalink
resource/alicloud_db_instance:fix_Account_Modification
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenHanZhang authored and chaitiansheng0524 committed Nov 12, 2024
1 parent b317993 commit 34dbe81
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 33 deletions.
11 changes: 11 additions & 0 deletions alicloud/resource_alicloud_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,11 @@ func resourceAliCloudDBInstance() *schema.Resource {
Optional: true,
ValidateFunc: StringInSlice([]string{"Up", "Down", "TempUpgrade", "Serverless"}, false),
},
"bursting_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
}
}
Expand Down Expand Up @@ -1423,6 +1428,11 @@ func resourceAliCloudDBInstanceUpdate(d *schema.ResourceData, meta interface{})
}
request["DBInstanceStorage"] = d.Get("instance_storage")

if d.HasChange("bursting_enabled") {
update = true
}
request["BurstingEnabled"] = d.Get("bursting_enabled")

if d.HasChange("serverless_config") {
update = true
if v, ok := d.GetOk("serverless_config"); ok {
Expand Down Expand Up @@ -1708,6 +1718,7 @@ func resourceAliCloudDBInstanceRead(d *schema.ResourceData, meta interface{}) er
d.Set("zone_id", instance["ZoneId"])
d.Set("status", instance["DBInstanceStatus"])
d.Set("create_time", instance["CreationTime"])
d.Set("bursting_enabled", instance["BurstingEnabled"])

// MySQL Serverless instance query PayType return SERVERLESS, need to be consistent with the participant.
payType := instance["PayType"]
Expand Down
20 changes: 20 additions & 0 deletions alicloud/resource_alicloud_db_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,26 @@ func TestAccAliCloudRdsDBInstance_Mysql_8_0(t *testing.T) {
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"bursting_enabled": "true",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"bursting_enabled": "true",
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"bursting_enabled": "false",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"bursting_enabled": "false",
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"db_instance_storage_type": "cloud_essd",
Expand Down
88 changes: 71 additions & 17 deletions alicloud/resource_alicloud_governance_account.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package alicloud. This file is generated automatically. Please do not modify it manually, thank you!
package alicloud

import (
Expand All @@ -7,6 +8,7 @@ import (
"regexp"
"time"

"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
Expand Down Expand Up @@ -38,6 +40,25 @@ func resourceAliCloudGovernanceAccount() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"account_tags": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"tag_key": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"tag_value": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
},
},
},
"baseline_id": {
Type: schema.TypeString,
Required: true,
Expand All @@ -54,15 +75,15 @@ func resourceAliCloudGovernanceAccount() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"default_domain_name": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: StringMatch(regexp.MustCompile("^[A-Za-z0-9_.][A-Za-z0-9_.-]{0,49}[A-Za-z0-9_.].onaliyun.com$"), "The default_domain_name (with suffix) has a maximum length of 64 characters and must end with .onaliyun.com."),
},
"status": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand All @@ -81,24 +102,39 @@ func resourceAliCloudGovernanceAccountCreate(d *schema.ResourceData, meta interf
}
request = make(map[string]interface{})
if v, ok := d.GetOk("account_id"); ok {
query["AccountUid"] = v
request["AccountUid"] = v
}
query["RegionId"] = client.RegionId
request["RegionId"] = client.RegionId

if v, ok := d.GetOk("account_name_prefix"); ok {
request["AccountNamePrefix"] = v
}
request["BaselineId"] = d.Get("baseline_id")
if v, ok := d.GetOk("display_name"); ok {
request["DisplayName"] = v
}
if v, ok := d.GetOk("folder_id"); ok {
request["FolderId"] = v
}
if v, ok := d.GetOk("payer_account_id"); ok {
request["PayerAccountUid"] = v
if v, ok := d.GetOk("account_tags"); ok {
tagMapsArray := make([]interface{}, 0)
for _, dataLoop := range v.([]interface{}) {
dataLoopTmp := dataLoop.(map[string]interface{})
dataLoopMap := make(map[string]interface{})
dataLoopMap["Value"] = dataLoopTmp["tag_value"]
dataLoopMap["Key"] = dataLoopTmp["tag_key"]
tagMapsArray = append(tagMapsArray, dataLoopMap)
}
tagMapsJson, err := json.Marshal(tagMapsArray)
if err != nil {
return WrapError(err)
}
request["Tag"] = string(tagMapsJson)
}

request["BaselineId"] = d.Get("baseline_id")
if v, ok := d.GetOkExists("payer_account_id"); ok {
request["PayerAccountUid"] = v
}
if v, ok := d.GetOk("display_name"); ok {
request["DisplayName"] = v
}
baselineItemsMaps := make([]interface{}, 0)
if v, ok := d.GetOk("default_domain_name"); ok {
baselineItemConfig := make(map[string]interface{})
Expand All @@ -110,7 +146,6 @@ func resourceAliCloudGovernanceAccountCreate(d *schema.ResourceData, meta interf
baselineItemsMaps = append(baselineItemsMaps, baselineItem)
}
request["BaselineItems"] = baselineItemsMaps

runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 5*time.Second)
Expand All @@ -123,9 +158,9 @@ func resourceAliCloudGovernanceAccountCreate(d *schema.ResourceData, meta interf
}
return resource.NonRetryableError(err)
}
addDebug(action, response, request)
return nil
})
addDebug(action, response, request)

if err != nil {
return WrapErrorf(err, DefaultErrorMsg, "alicloud_governance_account", action, AlibabaCloudSdkGoERROR)
Expand Down Expand Up @@ -166,6 +201,24 @@ func resourceAliCloudGovernanceAccountRead(d *schema.ResourceData, meta interfac
d.Set("account_id", objectRaw["AccountUid"])
}

tag1Raw, _ := jsonpath.Get("$.Inputs.Tag", objectRaw)
accountTagsMaps := make([]map[string]interface{}, 0)
if tag1Raw != nil {
for _, tagChild1Raw := range tag1Raw.([]interface{}) {
accountTagsMap := make(map[string]interface{})
tagChild1Raw := tagChild1Raw.(map[string]interface{})
accountTagsMap["tag_key"] = tagChild1Raw["Key"]
accountTagsMap["tag_value"] = tagChild1Raw["Value"]

accountTagsMaps = append(accountTagsMaps, accountTagsMap)
}
}
if tag1Raw != nil {
if err := d.Set("account_tags", accountTagsMaps); err != nil {
return err
}
}

d.Set("account_id", d.Id())

return nil
Expand All @@ -184,12 +237,13 @@ func resourceAliCloudGovernanceAccountUpdate(d *schema.ResourceData, meta interf
}
request = make(map[string]interface{})
query = make(map[string]interface{})
query["AccountUid"] = d.Id()
query["RegionId"] = client.RegionId
request["AccountUid"] = d.Id()
request["RegionId"] = client.RegionId
if d.HasChange("baseline_id") {
update = true
}
request["BaselineId"] = d.Get("baseline_id")

if update {
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
Expand All @@ -203,9 +257,9 @@ func resourceAliCloudGovernanceAccountUpdate(d *schema.ResourceData, meta interf
}
return resource.NonRetryableError(err)
}
addDebug(action, response, request)
return nil
})
addDebug(action, response, request)
if err != nil {
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR)
}
Expand Down
27 changes: 27 additions & 0 deletions alicloud/resource_alicloud_governance_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ func TestAccAliCloudGovernanceAccount_basic0(t *testing.T) {
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"account_tags": []map[string]interface{}{
{
"tag_key": "tag-key1",
"tag_value": "tag-value1",
},
{
"tag_key": "tag-key2",
"tag_value": "tag-value2",
},
},
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{}),
),
},
{
ResourceName: resourceId,
ImportState: true,
Expand Down Expand Up @@ -90,6 +107,16 @@ func TestAccAliCloudGovernanceAccount_basic7372(t *testing.T) {
"account_name_prefix": name,
"folder_id": "${data.alicloud_resource_manager_folders.default.ids.0}",
"default_domain_name": defaultDomainName,
"account_tags": []map[string]interface{}{
{
"tag_key": "tag-key1",
"tag_value": "tag-value1",
},
{
"tag_key": "tag-key2",
"tag_value": "tag-value2",
},
},
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
Expand Down
4 changes: 2 additions & 2 deletions alicloud/resource_alicloud_rds_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ func resourceAlicloudRdsAccount() *schema.Resource {
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^[a-z][a-z0-9_]{0,61}[a-z0-9]$`), "The name can consist of lowercase letters, numbers, underscores, and must begin with letters and end with letters or numbers"),
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9_]{0,61}[a-zA-Z0-9]$`), "The name can consist of letters, numbers, underscores, and must begin with letters and end with letters or numbers"),
ConflictsWith: []string{"name"},
},
"name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^[a-z][a-z0-9_]{0,61}[a-z0-9]$`), "The name can consist of lowercase letters, numbers, underscores, and must begin with letters and end with letters or numbers"),
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9_]{0,61}[a-zA-Z0-9]$`), "The name can consist of letters, numbers, underscores, and must begin with letters and end with letters or numbers"),
Deprecated: "Field 'name' has been deprecated from provider version 1.120.0. New field 'account_name' instead.",
ConflictsWith: []string{"account_name"},
},
Expand Down
7 changes: 3 additions & 4 deletions alicloud/service_alicloud_governance_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func (s *GovernanceServiceV2) DescribeGovernanceAccount(id string) (object map[s
}
request = make(map[string]interface{})
query = make(map[string]interface{})
query["AccountUid"] = id
query["RegionId"] = client.RegionId
request["AccountUid"] = id
request["RegionId"] = client.RegionId

runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
Expand All @@ -112,14 +112,13 @@ func (s *GovernanceServiceV2) DescribeGovernanceAccount(id string) (object map[s
}
return resource.NonRetryableError(err)
}
addDebug(action, response, request)
return nil
})
addDebug(action, response, request)
if err != nil {
if IsExpectedErrors(err, []string{"InvalidBlueprint.NotFound"}) {
return object, WrapErrorf(Error(GetNotFoundMessage("Account", id)), NotFoundMsg, response)
}
addDebug(action, response, request)
return object, WrapErrorf(err, DefaultErrorMsg, id, action, AlibabaCloudSdkGoERROR)
}

Expand Down
18 changes: 8 additions & 10 deletions website/docs/r/governance_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ For information about Governance Account and how to use it, see [What is Account

Basic Usage

<div style="display: block;margin-bottom: 40px;"><div class="oics-button" style="float: right;position: absolute;margin-bottom: 10px;">
<a href="https://api.aliyun.com/api-tools/terraform?resource=alicloud_governance_account&exampleId=bafb2fc6-f2e3-9029-f2d2-1e21385b8fba7daab3c6&activeTab=example&spm=docs.r.governance_account.0.bafb2fc6f2&intl_lang=EN_US" target="_blank">
<img alt="Open in AliCloud" src="https://img.alicdn.com/imgextra/i1/O1CN01hjjqXv1uYUlY56FyX_!!6000000006049-55-tps-254-36.svg" style="max-height: 44px; max-width: 100%;">
</a>
</div></div>

```terraform
variable "name" {
default = "terraform-example"
Expand Down Expand Up @@ -65,13 +59,13 @@ Terraform cannot destroy resource `alicloud_governance_account`. Terraform will
## Argument Reference

The following arguments are supported:
* `account_id` - (Optional, ForceNew, Computed) The ID of the enrolled account.
* `account_id` - (Optional, ForceNew, Computed, Int) The ID of the enrolled account.
- If you are creating a new resource account, this parameter is not required.
- If you are enrolling a existing account to account factory, this parameter is required.
* `account_name_prefix` - (Optional) Account name prefix.
- This parameter is required if you are creating a new resource account.
- If the registration application is applied to an existing account, this parameter does not need to be filled in.

* `account_tags` - (Optional, ForceNew, List, Available since v1.234.0) The tags of the account See [`account_tags`](#account_tags) below.
* `baseline_id` - (Required) The baseline ID.

If it is left blank, the system default baseline is used by default.
Expand All @@ -83,10 +77,14 @@ The following arguments are supported:
If you want to create a new resource account and leave this parameter blank, the account is created in the Root folder by default.

If the registration application is applied to an existing account, this parameter does not need to be filled in.
* `payer_account_id` - (Optional) The ID of the billing account. If you leave this parameter empty, the current account is used as the billing account.
* `payer_account_id` - (Optional, Int) The ID of the billing account. If you leave this parameter empty, the current account is used as the billing account.
* `default_domain_name` - (Optional, Available since v1.231.0) The domain name is used to qualify the login name of RAM users and RAM roles.

Format: \<AccountAlias>.onaliyun.com where \<AccountAlias> is the account alias, and the default value is the Aliyun account ID. The default domain name must end with the .onaliyun.com suffix. The maximum length of the default domain name (including suffix) is 64 characters. It can contain English letters, numbers, English periods (.) , dashes (-) and underscores (_).
### `account_tags`

The account_tags supports the following:
* `tag_key` - (Optional, ForceNew, Available since v1.234.0) The key of the tags
* `tag_value` - (Optional, ForceNew, Available since v1.234.0) The value of the tags

## Attributes Reference

Expand Down

0 comments on commit 34dbe81

Please sign in to comment.