Skip to content

Commit

Permalink
[Feat.] IMS: Add user input field hw_firmware_type (#2816)
Browse files Browse the repository at this point in the history
[Feat.] IMS: Add user input field hw_firmware_type

Summary of the Pull Request
resource/opentelekomcloud_images_image_v2
Users can now define the fields:

hw_firmware_type

datasource/opentelekomcloud_images_image_v2
If set during creation, users receive the above mentioned fields.
PR Checklist

 Refers to: #2799
 Tests added/passed.
 Documentation updated.
 Schema updated.
 Release notes added.

Acceptance Steps Performed
=== RUN   TestAccImagesImageV2_hwFirmwareType
--- PASS: TestAccImagesImageV2_hwFirmwareType (335.24s)
PASS
=== RUN   TestAccImagesV2ImageDataSource_basic
--- PASS: TestAccImagesV2ImageDataSource_basic (262.38s)
PASS

Reviewed-by: Anton Sidelnikov
  • Loading branch information
muneeb-jan authored Feb 7, 2025
1 parent a2db455 commit 3329063
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 41 deletions.
22 changes: 12 additions & 10 deletions docs/data-sources/images_image_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,27 @@ data "opentelekomcloud_images_image_v2" "latest-debian" {

## Argument Reference

* `most_recent` - (Optional) If more than one result is returned, use the most recent image.
* `most_recent` - (Optional, Boolean) If more than one result is returned, use the most recent image.

* `name` - (Optional) The name of the image.
* `name` - (Optional, String) The name of the image.

* `name_regex` - (Optional) A regex string to apply to the images list.
* `name_regex` - (Optional, String) A regex string to apply to the images list.
This allows more advanced filtering not supported from the OpenTelekomCloud API.
This filtering is done locally on what OpenTelekomCloud returns.

* `owner` - (Optional) The owner (UUID) of the image.
* `owner` - (Optional, String) The owner (UUID) of the image.

* `size_min` - (Optional) The minimum size (in bytes) of the image to return.
* `size_min` - (Optional, Integer) The minimum size (in bytes) of the image to return.

* `size_max` - (Optional) The maximum size (in bytes) of the image to return.
* `size_max` - (Optional, Integer) The maximum size (in bytes) of the image to return.

* `sort_direction` - (Optional) Order the results in either `asc` or `desc`.
* `sort_direction` - (Optional, String) Order the results in either `asc` or `desc`.

* `sort_key` - (Optional) Sort images based on a certain key. Defaults to `name`.
* `sort_key` - (Optional, String) Sort images based on a certain key. Defaults to `name`.

* `tag` - (Optional) Search for images with a specific tag.
* `tag` - (Optional, String) Search for images with a specific tag.

* `visibility` - (Optional) The visibility of the image. Must be one of
* `visibility` - (Optional, String) The visibility of the image. Must be one of
`public`, `private`, `community`, or `shared`. Defaults to `private`.

-> If more or less than a single match is returned by the search, Terraform will fail.
Expand Down Expand Up @@ -146,3 +146,5 @@ to choose the most recent one.
The value can be `FusionCompute`, `Ironic`, `DataImage`, or `IsoImage`.

* `updated_at` - The date the image was modified.

* `hw_firmware_type` - Specifies the boot mode. The value can be `bios` or `uefi` if set during image creation.
46 changes: 15 additions & 31 deletions docs/resources/images_image_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ resource "opentelekomcloud_images_image_v2" "rancheros" {
image_source_url = "https://releases.rancher.com/os/latest/rancheros-openstack.img"
container_format = "bare"
disk_format = "qcow2"
hw_firmware_type = "uefi"
tags = ["foo.bar", "tag.value"]
}
Expand All @@ -31,78 +32,65 @@ resource "opentelekomcloud_images_image_v2" "rancheros" {

The following arguments are supported:

* `container_format` - (Required) The container format. Must be one of
* `container_format` - (Required, String, ForceNew) The container format. Must be one of
`ami`, `ari`, `aki`, `bare`, `ovf`.

* `disk_format` - (Required) The disk format. Must be one of
* `disk_format` - (Required, String, ForceNew) The disk format. Must be one of
`ami`, `ari`, `aki`, `vhd`, `vmdk`, `raw`, `qcow2`, `vdi`, `iso`.

* `local_file_path` - (Optional) This is the filepath of the raw image file
* `local_file_path` - (Optional, String, ForceNew) This is the filepath of the raw image file
that will be uploaded to Glance. Conflicts with `image_source_url`.

* `image_cache_path` - (Optional) This is the directory where the images will
* `image_cache_path` - (Optional, String) This is the directory where the images will
be downloaded. Images will be stored with a filename corresponding to
the url's md5 hash. Defaults to "$HOME/.terraform/image_cache"

* `image_source_url` - (Optional) This is the url of the raw image that will
* `image_source_url` - (Optional, String, ForceNew) This is the url of the raw image that will
be downloaded in the `image_cache_path` before being uploaded to Glance.
Glance is able to download image from internet but the `gophercloud` library
does not yet provide a way to do so.
Conflicts with `local_file_path`.

* `min_disk_gb` - (Optional) Amount of disk space (in GB) required to boot image.
* `min_disk_gb` - (Optional, Integer, ForceNew) Amount of disk space (in GB) required to boot image.
Defaults to 0.

* `min_ram_mb` - (Optional) Amount of ram (in MB) required to boot image.
* `min_ram_mb` - (Optional, Integer, ForceNew) Amount of ram (in MB) required to boot image.
Defauts to 0.

* `name` - (Required) The name of the image.
* `name` - (Required, String) The name of the image.

* `protected` - (Optional) If true, image will not be deletable.
* `protected` - (Optional, Boolean, ForceNew) If true, image will not be deletable.
Defaults to false.

* `tags` - (Optional) The tags of the image. It must be a list of strings.
* `tags` - (Optional, List) The tags of the image. It must be a list of strings.
At this time, it is not possible to delete all tags of an image.

* `visibility` - (Optional) The visibility of the image. Must be one of
* `visibility` - (Optional, String) The visibility of the image. Must be one of
"public", "private", "community", or "shared". The ability to set the
visibility depends upon the configuration of the OpenTelekomCloud cloud.

* `hw_firmware_type` - (Optional, String) Specifies the boot mode. The value can be `bios` or `uefi`.

-> **Note:** The `properties` attribute handling in the gophercloud library is currently buggy
and needs to be fixed before being implemented in this resource.

## Attributes Reference

The following attributes are exported:
In additin to the arguments defined above, the following attributes are exported:

* `checksum` - The checksum of the data associated with the image.

* `container_format` - See Argument Reference above.

* `created_at` - The date the image was created.

* `disk_format` - See Argument Reference above.

* `file` - the trailing path after the glance
endpoint that represent the location of the image
or the path to retrieve it.

* `id` - A unique ID assigned by Glance.

* `metadata` - The metadata associated with the image.
Image metadata allow for meaningfully define the image properties
and tags. See http://docs.openstack.org/developer/glance/metadefs-concepts.html.

* `min_disk_gb` - See Argument Reference above.

* `min_ram_mb` - See Argument Reference above.

* `name` - See Argument Reference above.

* `owner` - The id of the opentelekomcloud user who owns the image.

* `protected` - See Argument Reference above.

* `schema` - The path to the JSON-schema that represent
the image or image

Expand All @@ -111,12 +99,8 @@ The following attributes are exported:
* `status` - The status of the image. It can be `queued`, `active`
or `saving`.

* `tags` - See Argument Reference above.

* `update_at` - The date the image was last updated.

* `visibility` - See Argument Reference above.

## Import

Images can be imported using the `id`, e.g.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestAccImagesV2ImageDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttr(dataSourceName, "min_ram", "0"),
resource.TestCheckResourceAttr(dataSourceName, "protected", "false"),
resource.TestCheckResourceAttr(dataSourceName, "visibility", "private"),
resource.TestCheckResourceAttrSet(dataSourceName, "hw_firmware_type"),
),
},
},
Expand Down Expand Up @@ -111,6 +112,7 @@ resource "opentelekomcloud_images_image_v2" "image_1" {
container_format = "bare"
disk_format = "qcow2"
image_source_url = "https://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img"
hw_firmware_type = "uefi"
tags = ["cirros-tf"]
}
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,37 @@ func TestAccImagesImageV2_visibility(t *testing.T) {
})
}

func TestAccImagesImageV2_hwFirmwareType(t *testing.T) {
var image ims.ImageInfo

resource.Test(t, resource.TestCase{
PreCheck: func() {
common.TestAccPreCheck(t)
common.TestAccPreCheckAdminOnly(t)
},
ProviderFactories: common.TestAccProviderFactories,
CheckDestroy: testAccCheckImagesImageV2Destroy,
Steps: []resource.TestStep{
{
Config: testAccImagesImageV2_hw_firmware_type_1,
Check: resource.ComposeTestCheckFunc(
testAccCheckImagesImageV2Exists("opentelekomcloud_images_image_v2.image_1", &image),
resource.TestCheckResourceAttr(
"opentelekomcloud_images_image_v2.image_1", "hw_firmware_type", "uefi"),
),
},
{
Config: testAccImagesImageV2_hw_firmware_type_2,
Check: resource.ComposeTestCheckFunc(
testAccCheckImagesImageV2Exists("opentelekomcloud_images_image_v2.image_1", &image),
resource.TestCheckResourceAttr(
"opentelekomcloud_images_image_v2.image_1", "hw_firmware_type", "bios"),
),
},
},
})
}

func TestAccImagesImageV2_timeout(t *testing.T) {
var image ims.ImageInfo

Expand Down Expand Up @@ -350,6 +381,24 @@ resource "opentelekomcloud_images_image_v2" "image_1" {
visibility = "public"
}`

var testAccImagesImageV2_hw_firmware_type_1 = `
resource "opentelekomcloud_images_image_v2" "image_1" {
name = "Rancher TerraformAccTest"
image_source_url = "https://releases.rancher.com/os/latest/rancheros-openstack.img"
container_format = "bare"
disk_format = "qcow2"
hw_firmware_type = "uefi"
}`

var testAccImagesImageV2_hw_firmware_type_2 = `
resource "opentelekomcloud_images_image_v2" "image_1" {
name = "Rancher TerraformAccTest"
image_source_url = "https://releases.rancher.com/os/latest/rancheros-openstack.img"
container_format = "bare"
disk_format = "qcow2"
hw_firmware_type = "bios"
}`

var testAccImagesImageV2_timeout = `
resource "opentelekomcloud_images_image_v2" "image_1" {
name = "Rancher TerraformAccTest"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ func DataSourceImagesImageV2() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"hw_firmware_type": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -331,6 +335,7 @@ func dataSourceImagesImageV2Read(_ context.Context, d *schema.ResourceData, meta
d.Set("support_xen", img.SupportXen),
d.Set("support_xen_gpu_type", img.SupportXenGpuType),
d.Set("support_xen_hana", img.SupportXenHana),
d.Set("hw_firmware_type", img.HwFirmwareType),
)

if mErr.ErrorOrNil() != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ func ResourceImagesImageV2() *schema.Resource {
ForceNew: false,
},

"hw_firmware_type": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"bios", "uefi",
}, true),
},
"owner": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -243,6 +250,23 @@ func resourceImagesImageV2Create(ctx context.Context, d *schema.ResourceData, me
return fmterr.Errorf("error waiting for Image: %s", err)
}

addonOpts := make([]ims.UpdateImageOpts, 0)
hwFirmwareType := d.Get("hw_firmware_type").(string)
if hwFirmwareType != "" {
addonOpts = append(addonOpts, ims.UpdateImageOpts{
Op: "add",
Path: "/hw_firmware_type",
Value: hwFirmwareType,
})
}

if len(addonOpts) > 0 {
_, err = images.Update(imageClient, d.Id(), addonOpts)
if err != nil {
return fmterr.Errorf("error updating image: %s", err)
}
}

d.Partial(false)

return resourceImagesImageV2Read(ctx, d, meta)
Expand Down Expand Up @@ -279,6 +303,7 @@ func resourceImagesImageV2Read(_ context.Context, d *schema.ResourceData, meta i
d.Set("min_ram_mb", img.MinRam),
d.Set("file", img.File),
d.Set("name", img.Name),
d.Set("hw_firmware_type", img.HwFirmwareType),
d.Set("protected", img.Protected),
d.Set("tags", img.Tags),
d.Set("visibility", img.Visibility),
Expand Down Expand Up @@ -317,6 +342,14 @@ func resourceImagesImageV2Update(ctx context.Context, d *schema.ResourceData, me
})
}

if d.HasChange("hw_firmware_type") {
updateOpts = append(updateOpts, ims.UpdateImageOpts{
Op: "replace",
Path: "/hw_firmware_type",
Value: d.Get("hw_firmware_type").(string),
})
}

if d.HasChange("tags") {
tags := d.Get("tags").(*schema.Set).List()
updateOpts = append(updateOpts, ims.UpdateImageOpts{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
features:
- |
**[IMS]** Added `hw_firmware_type` as argument in ``resource/opentelekomcloud_ims_image_v2`` and as attribute in ``datasource/opentelekomcloud_ims_image_v2`` (`#2816 <https://github.com/opentelekomcloud/terraform-provider-opentelekomcloud/pull/2816>`_)

0 comments on commit 3329063

Please sign in to comment.