diff --git a/docs/resources/cph_server.md b/docs/resources/cph_server.md index ce758d41620..1c71b1f7f69 100644 --- a/docs/resources/cph_server.md +++ b/docs/resources/cph_server.md @@ -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. diff --git a/huaweicloud/services/acceptance/cph/resource_huaweicloud_cph_server_test.go b/huaweicloud/services/acceptance/cph/resource_huaweicloud_cph_server_test.go index f499e54fa68..0fa72182e85 100644 --- a/huaweicloud/services/acceptance/cph/resource_huaweicloud_cph_server_test.go +++ b/huaweicloud/services/acceptance/cph/resource_huaweicloud_cph_server_test.go @@ -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"), @@ -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 @@ -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" @@ -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 @@ -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" diff --git a/huaweicloud/services/cph/resource_huaweicloud_cph_server.go b/huaweicloud/services/cph/resource_huaweicloud_cph_server.go index bbbf8ee90e1..8f082810310 100644 --- a/huaweicloud/services/cph/resource_huaweicloud_cph_server.go +++ b/huaweicloud/services/cph/resource_huaweicloud_cph_server.go @@ -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{}{ @@ -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"},