Skip to content

Commit

Permalink
feat(cph): supports parameters related to cph server 2.0 flavor
Browse files Browse the repository at this point in the history
  • Loading branch information
luoping-12345 committed Nov 15, 2024
1 parent e1fe3cd commit 288a19f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 11 deletions.
2 changes: 0 additions & 2 deletions docs/resources/cph_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@ The `Address` block supports:
* `phone_data_volume` - The phone data volume.
The [phone_data_volume](#attr_phone_data_volume) structure is documented below.

* `security_groups` - The list of the security groups bound to the extension NIC of the CPH server.

* `server_share_data_volume` - The server share data volume.
The [server_share_data_volume](#attr_server_share_data_volume) structure is documented below.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ func TestAccCphServer_basic(t *testing.T) {
resource.TestCheckResourceAttrSet(rName, "order_id"),
resource.TestCheckResourceAttrSet(rName, "addresses.#"),
resource.TestCheckResourceAttrSet(rName, "status"),
resource.TestCheckResourceAttrSet(rName, "phone_data_volume.#"),
resource.TestCheckResourceAttrSet(rName, "phone_data_volume.0.volume_type"),
resource.TestCheckResourceAttrSet(rName, "phone_data_volume.0.volume_size"),
resource.TestCheckResourceAttrSet(rName, "phone_data_volume.0.volume_id"),
resource.TestCheckResourceAttrSet(rName, "phone_data_volume.0.volume_name"),
resource.TestCheckResourceAttrSet(rName, "phone_data_volume.0.created_at"),
resource.TestCheckResourceAttrSet(rName, "phone_data_volume.0.updated_at"),
resource.TestCheckResourceAttrSet(rName, "server_share_data_volume.#"),
resource.TestCheckResourceAttrSet(rName, "server_share_data_volume.0.volume_type"),
resource.TestCheckResourceAttrSet(rName, "server_share_data_volume.0.size"),
Expand Down Expand Up @@ -143,8 +150,8 @@ func testCphServer_basic(name string) string {
resource "huaweicloud_cph_server" "test" {
name = "%s"
server_flavor = "physical.rx1.xlarge"
phone_flavor = "rx1.cp.c15.d46.e1v1"
server_flavor = "physical.kg1.4xlarge.cp"
phone_flavor = "rs2.plus"
image_id = data.huaweicloud_cph_phone_images.test.images[0].id
keypair_name = huaweicloud_kps_keypair.test.name
Expand All @@ -158,6 +165,16 @@ resource "huaweicloud_cph_server" "test" {
size = 300
}
phone_data_volume {
volume_type = "GPSSD"
volume_size = 100
}
server_share_data_volume {
volume_type = "GPSSD"
size = 100
}
period_unit = "month"
period = 1
auto_renew = "true"
Expand All @@ -177,8 +194,8 @@ func testCphServer_basic_update(name, cphServerName string) string {
resource "huaweicloud_cph_server" "test" {
name = "%s"
server_flavor = "physical.rx1.xlarge"
phone_flavor = "rx1.cp.c15.d46.e1v1"
server_flavor = "physical.kg1.4xlarge.cp"
phone_flavor = "rs2.plus"
image_id = data.huaweicloud_cph_phone_images.test.images[0].id
keypair_name = huaweicloud_kps_keypair.test1.name
Expand All @@ -192,6 +209,16 @@ resource "huaweicloud_cph_server" "test" {
size = 300
}
phone_data_volume {
volume_type = "GPSSD"
volume_size = 100
}
server_share_data_volume {
volume_type = "GPSSD"
size = 100
}
period_unit = "month"
period = 1
auto_renew = "true"
Expand Down
46 changes: 41 additions & 5 deletions huaweicloud/services/cph/resource_huaweicloud_cph_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,13 @@ func buildCreateCphServerBodyParams(d *schema.ResourceData, cfg *config.Config)
"subnet_id": utils.ValueIgnoreEmpty(d.Get("subnet_id")),
},
},
"public_ip": buildCreateCphServerRequestBodyPublicIp(d),
"band_width": buildCreateCphServerRequestBodyBandWidth(d.Get("bandwidth")),
"keypair_name": utils.ValueIgnoreEmpty(d.Get("keypair_name")),
"availability_zone": utils.ValueIgnoreEmpty(d.Get("availability_zone")),
"ports": buildCreateCphServerRequestBodyApplicationPort(d.Get("ports")),
"public_ip": buildCreateCphServerRequestBodyPublicIp(d),
"band_width": buildCreateCphServerRequestBodyBandWidth(d.Get("bandwidth")),
"keypair_name": utils.ValueIgnoreEmpty(d.Get("keypair_name")),
"availability_zone": utils.ValueIgnoreEmpty(d.Get("availability_zone")),
"ports": buildCreateCphServerRequestBodyApplicationPort(d.Get("ports")),
"phone_data_volume": buildCreateCphServerRequestBodyPhoneDataVolume(d.Get("phone_data_volume")),
"server_share_data_volume": buildCreateCphServerRequestBodyShareDataVolume(d.Get("server_share_data_volume")),
}

extendParam := map[string]interface{}{
Expand Down Expand Up @@ -517,6 +519,40 @@ func buildCreateCphServerRequestBodyApplicationPort(rawParams interface{}) []map
return nil
}

func buildCreateCphServerRequestBodyPhoneDataVolume(rawParams interface{}) map[string]interface{} {
if rawArray, ok := rawParams.([]interface{}); ok {
if len(rawArray) == 0 {
return nil
}

raw := rawArray[0].(map[string]interface{})
params := map[string]interface{}{
"volume_type": utils.ValueIgnoreEmpty(raw["volume_type"]),
"size": utils.ValueIgnoreEmpty(raw["volume_size"]),
}
return params
}

return nil
}

func buildCreateCphServerRequestBodyShareDataVolume(rawParams interface{}) map[string]interface{} {
if rawArray, ok := rawParams.([]interface{}); ok {
if len(rawArray) == 0 {
return nil
}

raw := rawArray[0].(map[string]interface{})
params := map[string]interface{}{
"volume_type": utils.ValueIgnoreEmpty(raw["volume_type"]),
"size": utils.ValueIgnoreEmpty(raw["size"]),
}
return params
}

return nil
}

func createCphServerWaitingForStateCompleted(ctx context.Context, d *schema.ResourceData, meta interface{}, t time.Duration) error {
stateConf := &resource.StateChangeConf{
Pending: []string{"PENDING"},
Expand Down

0 comments on commit 288a19f

Please sign in to comment.