Skip to content

Commit

Permalink
feat(GaussDB): fix gaussdb opengauss flavor update (#6026)
Browse files Browse the repository at this point in the history
  • Loading branch information
houpeng80 authored Dec 16, 2024
1 parent eb9541e commit bbb9702
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ func TestAccOpenGaussInstance_basic(t *testing.T) {
Config: testAccOpenGaussInstance_update(rName, newPassword, 3),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttrPair(resourceName, "flavor",
"data.huaweicloud_gaussdb_opengauss_flavors.test", "flavors.1.spec_code"),
resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("%s-update", rName)),
resource.TestCheckResourceAttr(resourceName, "password", newPassword),
resource.TestCheckResourceAttr(resourceName, "sharding_num", "2"),
Expand All @@ -122,6 +120,49 @@ func TestAccOpenGaussInstance_basic(t *testing.T) {
})
}

func TestAccOpenGaussInstance_flavor(t *testing.T) {
var (
instance instances.GaussDBInstance
resourceName = "huaweicloud_gaussdb_opengauss_instance.test"
rName = acceptance.RandomAccResourceNameWithDash()
password = fmt.Sprintf("%s@123", acctest.RandString(5))
)

rc := acceptance.InitResourceCheck(
resourceName,
&instance,
getOpenGaussInstanceFunc,
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckMigrateEpsID(t)
acceptance.TestAccPreCheckHighCostAllow(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccOpenGaussInstance_flavor(rName, password),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttrPair(resourceName, "flavor",
"data.huaweicloud_gaussdb_opengauss_flavors.test", "flavors.0.spec_code"),
),
},
{
Config: testAccOpenGaussInstance_flavor_update(rName, password),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttrPair(resourceName, "flavor",
"data.huaweicloud_gaussdb_opengauss_flavors.test", "flavors.1.spec_code"),
),
},
},
})
}

func TestAccOpenGaussInstance_haModeCentralized(t *testing.T) {
var (
instance instances.GaussDBInstance
Expand Down Expand Up @@ -277,7 +318,7 @@ resource "huaweicloud_gaussdb_opengauss_instance" "test" {
subnet_id = huaweicloud_vpc_subnet.test.id
security_group_id = huaweicloud_networking_secgroup.test.id
flavor = data.huaweicloud_gaussdb_opengauss_flavors.test.flavors[1].spec_code
flavor = data.huaweicloud_gaussdb_opengauss_flavors.test.flavors[0].spec_code
name = "%[2]s-update"
password = "%[3]s"
sharding_num = 2
Expand Down Expand Up @@ -309,6 +350,94 @@ resource "huaweicloud_gaussdb_opengauss_instance" "test" {
`, testAccOpenGaussInstance_base(rName), rName, password, replicaNum, acceptance.HW_ENTERPRISE_MIGRATE_PROJECT_ID_TEST)
}

func testAccOpenGaussInstance_flavor(rName, password string) string {
return fmt.Sprintf(`
%[1]s
data "huaweicloud_gaussdb_opengauss_flavors" "test" {
version = "8.201"
ha_mode = "centralization_standard"
}
resource "huaweicloud_gaussdb_opengauss_instance" "test" {
depends_on = [
huaweicloud_networking_secgroup_rule.in_v4_tcp_opengauss,
huaweicloud_networking_secgroup_rule.in_v4_tcp_opengauss_egress
]
vpc_id = huaweicloud_vpc.test.id
subnet_id = huaweicloud_vpc_subnet.test.id
security_group_id = huaweicloud_networking_secgroup.test.id
flavor = data.huaweicloud_gaussdb_opengauss_flavors.test.flavors[0].spec_code
name = "%[2]s"
password = "%[3]s"
replica_num = 3
availability_zone = join(",", [data.huaweicloud_availability_zones.test.names[0],
data.huaweicloud_availability_zones.test.names[1],
data.huaweicloud_availability_zones.test.names[2]])
enterprise_project_id = "%[4]s"
ha {
mode = "centralization_standard"
replication_mode = "sync"
consistency = "eventual"
instance_mode = "basic"
}
volume {
type = "ULTRAHIGH"
size = 40
}
}
`, testAccOpenGaussInstance_base(rName), rName, password, acceptance.HW_ENTERPRISE_PROJECT_ID_TEST)
}

func testAccOpenGaussInstance_flavor_update(rName, password string) string {
return fmt.Sprintf(`
%[1]s
data "huaweicloud_gaussdb_opengauss_flavors" "test" {
version = "8.201"
ha_mode = "centralization_standard"
}
resource "huaweicloud_gaussdb_opengauss_instance" "test" {
depends_on = [
huaweicloud_networking_secgroup_rule.in_v4_tcp_opengauss,
huaweicloud_networking_secgroup_rule.in_v4_tcp_opengauss_egress
]
vpc_id = huaweicloud_vpc.test.id
subnet_id = huaweicloud_vpc_subnet.test.id
security_group_id = huaweicloud_networking_secgroup.test.id
flavor = data.huaweicloud_gaussdb_opengauss_flavors.test.flavors[1].spec_code
name = "%[2]s"
password = "%[3]s"
replica_num = 3
availability_zone = join(",", [data.huaweicloud_availability_zones.test.names[0],
data.huaweicloud_availability_zones.test.names[1],
data.huaweicloud_availability_zones.test.names[2]])
enterprise_project_id = "%[4]s"
ha {
mode = "centralization_standard"
replication_mode = "sync"
consistency = "eventual"
instance_mode = "basic"
}
volume {
type = "ULTRAHIGH"
size = 40
}
}
`, testAccOpenGaussInstance_base(rName), rName, password, acceptance.HW_ENTERPRISE_MIGRATE_PROJECT_ID_TEST)
}

func testAccOpenGaussInstance_haModeCentralized(rName, password string) string {
return fmt.Sprintf(`
%[1]s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1128,8 +1128,10 @@ func updateInstanceFlavor(ctx context.Context, d *schema.ResourceData, client, b

func buildUpdateInstanceFlavorBodyParams(d *schema.ResourceData) map[string]interface{} {
bodyParams := map[string]interface{}{
"flavor_ref": d.Get("flavor"),
"is_auto_pay": true,
"flavor_ref": d.Get("flavor"),
}
if v, ok := d.GetOk("charging_mode"); ok && v.(string) == "prePaid" {
bodyParams["is_auto_pay"] = true
}
return bodyParams
}
Expand Down

0 comments on commit bbb9702

Please sign in to comment.