-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ims): support
evs_data_image
resource (#5443)
- Loading branch information
1 parent
3a17733
commit 436ad4d
Showing
9 changed files
with
497 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
--- | ||
subcategory: "Image Management Service (IMS)" | ||
layout: "huaweicloud" | ||
page_title: "HuaweiCloud: huaweicloud_ims_evs_data_image" | ||
description: |- | ||
Manages an IMS data image resource created from EVS volume within HuaweiCloud. | ||
--- | ||
|
||
# huaweicloud_ims_evs_data_image | ||
|
||
Manages an IMS data image resource created from EVS volume within HuaweiCloud. | ||
|
||
-> The volume must be bound to the ECS instance. | ||
|
||
## Example Usage | ||
|
||
### Creating an IMS data image from EVS volume | ||
|
||
```hcl | ||
variable "name" {} | ||
variable "volume_id" {} | ||
resource "huaweicloud_ims_evs_data_image" "test" { | ||
name = var.name | ||
volume_id = var.volume_id | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource. | ||
If omitted, the provider-level region will be used. Changing this parameter will create a new resource. | ||
|
||
* `name` - (Required, String) Specifies the name of the image. | ||
The valid length is limited from `1` to `128` characters. | ||
The first and last letters of the name cannot be spaces. | ||
The name can contain uppercase letters, lowercase letters, numbers, spaces, chinese, and special characters (-._). | ||
|
||
* `volume_id` - (Required, String, ForceNew) Specifies the EVS volume ID used to create the image. | ||
Changing this parameter will create a new resource. | ||
|
||
* `description` - (Optional, String) Specifies the description of the image. | ||
|
||
* `tags` - (Optional, Map) Specifies the key/value pairs to associate with the image. | ||
|
||
* `enterprise_project_id` - (Optional, String) Specifies the enterprise project ID to which the IMS image belongs. | ||
For enterprise users, if omitted, default enterprise project will be used. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The ID of the image. | ||
|
||
* `status` - The status of the image. The value can be **active**, **queued**, **saving**, **deleted**, or **killed*, | ||
only image with a status of **active** can be used. | ||
|
||
* `visibility` - Whether the image is visible to other tenants. | ||
|
||
* `image_size` - The size of the image file, in bytes unit. | ||
|
||
* `min_disk` - The minimum disk space required to run an image, in GB unit. | ||
+ When the operating system is Linux, the value ranges from `10` to `1,024`. | ||
+ When the operating system is Windows, the value ranges from `20` to `1,024`. | ||
|
||
* `os_type` - The operating system type. The value can be **Linux**, **Windows**, or **Other**. | ||
|
||
* `disk_format` - The image format. The value can be **zvhd2**, **vhd**, **zvhd**, **raw**, or **qcow2**. | ||
|
||
* `data_origin` - The image source. The format is **volume,volume_id**. | ||
|
||
* `active_at` - The time when the image status changes to active, in RFC3339 format. | ||
|
||
* `created_at` - The creation time of the image, in RFC3339 format. | ||
|
||
* `updated_at` - The last update time of the image, in RFC3339 format. | ||
|
||
## Timeouts | ||
|
||
This resource provides the following timeouts configuration options: | ||
|
||
* `create` - Default is 20 minutes. | ||
* `delete` - Default is 10 minutes. | ||
|
||
## Import | ||
|
||
The IMS EVS data image resource can be imported using the `id`, e.g. | ||
|
||
```bash | ||
$ terraform import huaweicloud_ims_evs_data_image.test <id> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
huaweicloud/services/acceptance/ims/resource_huaweicloud_ims_evs_data_image_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
package ims | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
"github.com/chnsz/golangsdk/openstack/ims/v2/cloudimages" | ||
|
||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" | ||
) | ||
|
||
func TestAccEvsDataImage_basic(t *testing.T) { | ||
var ( | ||
image cloudimages.Image | ||
rName = acceptance.RandomAccResourceName() | ||
rNameUpdate = rName + "-update" | ||
resourceName = "huaweicloud_ims_evs_data_image.test" | ||
defaultEpsId = "0" | ||
migrateEpsId = acceptance.HW_ENTERPRISE_PROJECT_ID_TEST | ||
) | ||
|
||
rc := acceptance.InitResourceCheck( | ||
resourceName, | ||
&image, | ||
getImsImageResourceFunc, | ||
) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acceptance.TestAccPreCheck(t) | ||
// This test case need setting a non default enterprise project ID. | ||
acceptance.TestAccPreCheckEpsID(t) | ||
}, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
CheckDestroy: rc.CheckResourceDestroy(), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccEvsDataImage_basic(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttr(resourceName, "name", rName), | ||
resource.TestCheckResourceAttr(resourceName, "description", "terraform description test"), | ||
resource.TestCheckResourceAttr(resourceName, "tags.foo", "bar"), | ||
resource.TestCheckResourceAttr(resourceName, "tags.key", "value"), | ||
resource.TestCheckResourceAttr(resourceName, "enterprise_project_id", defaultEpsId), | ||
resource.TestCheckResourceAttr(resourceName, "status", "active"), | ||
resource.TestCheckResourceAttrSet(resourceName, "visibility"), | ||
resource.TestCheckResourceAttrSet(resourceName, "image_size"), | ||
resource.TestCheckResourceAttrSet(resourceName, "min_disk"), | ||
resource.TestCheckResourceAttrSet(resourceName, "os_type"), | ||
resource.TestCheckResourceAttrSet(resourceName, "disk_format"), | ||
resource.TestCheckResourceAttrSet(resourceName, "data_origin"), | ||
resource.TestMatchResourceAttr(resourceName, "active_at", | ||
regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?(Z|([+-]\d{2}:\d{2}))$`)), | ||
resource.TestMatchResourceAttr(resourceName, "created_at", | ||
regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?(Z|([+-]\d{2}:\d{2}))$`)), | ||
resource.TestMatchResourceAttr(resourceName, "updated_at", | ||
regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?(Z|([+-]\d{2}:\d{2}))$`)), | ||
resource.TestCheckResourceAttrPair(resourceName, "volume_id", "huaweicloud_evs_volume.test", "id"), | ||
), | ||
}, | ||
{ | ||
Config: testAccEvsDataImage_update1(rName, rNameUpdate, migrateEpsId), | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttr(resourceName, "name", rNameUpdate), | ||
resource.TestCheckResourceAttr(resourceName, "description", ""), | ||
resource.TestCheckResourceAttr(resourceName, "tags.foo", "bar"), | ||
resource.TestCheckResourceAttr(resourceName, "tags.key", "value1"), | ||
resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), | ||
resource.TestCheckResourceAttr(resourceName, "enterprise_project_id", migrateEpsId), | ||
resource.TestCheckResourceAttr(resourceName, "status", "active"), | ||
), | ||
}, | ||
{ | ||
Config: testAccEvsDataImage_update2(rName, rNameUpdate, defaultEpsId), | ||
Check: resource.ComposeTestCheckFunc( | ||
rc.CheckResourceExists(), | ||
resource.TestCheckResourceAttr(resourceName, "name", rNameUpdate), | ||
resource.TestCheckResourceAttr(resourceName, "description", ""), | ||
resource.TestCheckResourceAttr(resourceName, "tags.foo", "bar"), | ||
resource.TestCheckResourceAttr(resourceName, "tags.key", "value1"), | ||
resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), | ||
resource.TestCheckResourceAttr(resourceName, "enterprise_project_id", defaultEpsId), | ||
resource.TestCheckResourceAttr(resourceName, "status", "active"), | ||
), | ||
}, | ||
{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccEvsDataImage_base(rName string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
resource "huaweicloud_evs_volume" "test" { | ||
name = "%[2]s" | ||
volume_type = "GPSSD" | ||
availability_zone = data.huaweicloud_availability_zones.test.names[0] | ||
server_id = huaweicloud_compute_instance.test.id | ||
size = 100 | ||
charging_mode = "postPaid" | ||
} | ||
`, testAccEcsSystemImage_base(rName), rName) | ||
} | ||
|
||
func testAccEvsDataImage_basic(rName string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
resource "huaweicloud_ims_evs_data_image" "test" { | ||
name = "%[2]s" | ||
volume_id = huaweicloud_evs_volume.test.id | ||
description = "terraform description test" | ||
tags = { | ||
foo = "bar" | ||
key = "value" | ||
} | ||
} | ||
`, testAccEvsDataImage_base(rName), rName) | ||
} | ||
|
||
func testAccEvsDataImage_update1(rName, rNameUpdate, migrateEpsId string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
resource "huaweicloud_ims_evs_data_image" "test" { | ||
name = "%[2]s" | ||
volume_id = huaweicloud_evs_volume.test.id | ||
enterprise_project_id = "%[3]s" | ||
tags = { | ||
foo = "bar" | ||
key = "value1" | ||
key2 = "value2" | ||
} | ||
} | ||
`, testAccEvsDataImage_base(rName), rNameUpdate, migrateEpsId) | ||
} | ||
|
||
func testAccEvsDataImage_update2(rName, rNameUpdate, defaultEpsId string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
resource "huaweicloud_ims_evs_data_image" "test" { | ||
name = "%[2]s" | ||
volume_id = huaweicloud_evs_volume.test.id | ||
enterprise_project_id = "%[3]s" | ||
tags = { | ||
foo = "bar" | ||
key = "value1" | ||
key2 = "value2" | ||
} | ||
} | ||
`, testAccEvsDataImage_base(rName), rNameUpdate, defaultEpsId) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.