Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions alicloud/resource_alicloud_image_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,23 @@ func resourceAliCloudImageImport() *schema.Resource {
},
},
},
"features": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"nvme_support": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ValidateFunc: StringInSlice([]string{"supported", "unsupported"}, false),
},
},
},
},
},
}
}
Expand Down Expand Up @@ -142,6 +159,17 @@ func resourceAliCloudImageImportCreate(d *schema.ResourceData, meta interface{})
request.Description = v.(string)
}

// Handle features including NVMe support
if v, ok := d.GetOk("features"); ok {
featuresList := v.([]interface{})
if len(featuresList) > 0 {
featuresMap := featuresList[0].(map[string]interface{})
if nvmeSupport, ok := featuresMap["nvme_support"]; ok && nvmeSupport.(string) != "" {
request.QueryParams["Features.NvmeSupport"] = nvmeSupport.(string)
}
}
}

diskDeviceMappings := d.Get("disk_device_mapping")
diskDeviceMappingsMaps := make([]ecs.ImportImageDiskDeviceMapping, 0)
for _, diskDeviceMappingsList := range diskDeviceMappings.([]interface{}) {
Expand Down Expand Up @@ -234,6 +262,15 @@ func resourceAliCloudImageImportRead(d *schema.ResourceData, meta interface{}) e

d.Set("disk_device_mapping", diskDeviceMappings)

// Set features
featuresMaps := make([]map[string]interface{}, 0)
featuresMap := make(map[string]interface{})
if object.Features.NvmeSupport != "" {
featuresMap["nvme_support"] = object.Features.NvmeSupport
featuresMaps = append(featuresMaps, featuresMap)
d.Set("features", featuresMaps)
}

return nil
}

Expand Down
71 changes: 71 additions & 0 deletions alicloud/resource_alicloud_image_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,77 @@ func TestAccAliCloudImageImport_basic0_twin(t *testing.T) {

}

func TestAccAliCloudImageImport_features(t *testing.T) {
var v map[string]interface{}
resourceId := "alicloud_image_import.default"
ra := resourceAttrInit(resourceId, AliCloudImageImportMap0)
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} {
return &EcsService{testAccProvider.Meta().(*connectivity.AliyunClient)}
}, "DescribeImageById")
rac := resourceAttrCheckInit(rc, ra)
testAccCheck := rac.resourceAttrMapUpdateSet()
rand := acctest.RandIntRange(1000, 9999)
name := fmt.Sprintf("tf-testacc%simageimport%d", defaultRegionToTest, rand)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, AliCloudImageImportBasicDependence0)
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
IDRefreshName: resourceId,
Providers: testAccProviders,
CheckDestroy: rac.checkResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccConfig(map[string]interface{}{
"image_name": name,
"features": []map[string]interface{}{
{
"nvme_support": "supported",
},
},
"disk_device_mapping": []map[string]interface{}{
{
"oss_bucket": "${alicloud_oss_bucket.default.id}",
"oss_object": "${alicloud_oss_bucket_object.default.id}",
},
},
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"image_name": name,
"features.#": "1",
"features.0.nvme_support": "supported",
"disk_device_mapping.#": "1",
}),
),
},
{
Config: testAccConfig(map[string]interface{}{
"image_name": name + "-update",
"features": []map[string]interface{}{
{
"nvme_support": "unsupported",
},
},
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"image_name": name + "-update",
"features.0.nvme_support": "unsupported",
}),
),
},
{
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"license_type"},
},
},
})

}

var AliCloudImageImportMap0 = map[string]string{
"platform": CHECKSET,
"boot_mode": CHECKSET,
Expand Down
12 changes: 12 additions & 0 deletions website/docs/r/image_import.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ resource "alicloud_image_import" "default" {
license_type = "Auto"
image_name = var.name
description = var.name
features {
nvme_support = "supported"
}
disk_device_mapping {
oss_bucket = alicloud_oss_bucket.default.id
oss_object = alicloud_oss_bucket_object.default.id
Expand All @@ -84,6 +87,7 @@ The following arguments are supported:
* `image_name` - (Optional) The name of the image. The `image_name` must be `2` to `128` characters in length. The `image_name` must start with a letter and cannot start with acs: or aliyun. The `image_name` cannot contain http:// or https://. The `image_name` can contain letters, digits, periods (.), colons (:), underscores (_), and hyphens (-).
* `description` - (Optional) The description of the image. The `description` must be 2 to 256 characters in length and cannot start with http:// or https://.
* `disk_device_mapping` - (Required, ForceNew, Set) The information about the custom image. See [`disk_device_mapping`](#disk_device_mapping) below.
* `features` - (Optional, Computed) Features for the image. See [`features`](#features) below.

### `disk_device_mapping`

Expand All @@ -95,6 +99,14 @@ The disk_device_mapping supports the following:
* `device` - (Optional, ForceNew) The device name of the disk.
* `disk_image_size` - (Optional, ForceNew, Int) The size of the disk. Default value: `5`.

### `features`

The features supports the following:

* `nvme_support` - (Optional, ForceNew, Computed) Specifies whether to support the Non-Volatile Memory Express (NVMe) protocol. Valid values:
- `supported`: The image supports NVMe. Instances created from this image also support NVMe.
- `unsupported`: The image does not support NVMe. Instances created from this image do not support NVMe.

## Attributes Reference

The following attributes are exported:
Expand Down