diff --git a/ibm/service/power/data_source_ibm_pi_image.go b/ibm/service/power/data_source_ibm_pi_image.go index c88a51a55e..cd883e3c01 100644 --- a/ibm/service/power/data_source_ibm_pi_image.go +++ b/ibm/service/power/data_source_ibm_pi_image.go @@ -6,65 +6,72 @@ package power import ( "context" - "github.com/IBM-Cloud/power-go-client/helpers" + "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - //"fmt" - "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) func DataSourceIBMPIImage() *schema.Resource { - return &schema.Resource{ ReadContext: dataSourceIBMPIImagesRead, Schema: map[string]*schema.Schema{ - - helpers.PIImageName: { - Type: schema.TypeString, + // Arguments + Arg_CloudInstanceID: { + Description: "The GUID of the service instance associated with an account.", Required: true, - Description: "Imagename Name to be used for pvminstances", + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - helpers.PICloudInstanceId: { - Type: schema.TypeString, + Arg_ImageName: { + Description: "The ID of the image.", Required: true, + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - "state": { - Type: schema.TypeString, - Computed: true, + // Attributes + Attr_Architecture: { + Computed: true, + Description: "The CPU architecture that the image is designed for. ", + Type: schema.TypeString, }, - "size": { - Type: schema.TypeInt, - Computed: true, + Attr_Hypervisor: { + Computed: true, + Description: "Hypervision Type.", + Type: schema.TypeString, }, - "architecture": { - Type: schema.TypeString, - Computed: true, + Attr_ImageType: { + Computed: true, + Description: "The identifier of this image type.", + Type: schema.TypeString, }, + // TODO: Relabel this one "operating_system" to match catalog images "operatingsystem": { - Type: schema.TypeString, - Computed: true, + Computed: true, + Description: "The operating system that is installed with the image.", + Type: schema.TypeString, }, - "hypervisor": { - Type: schema.TypeString, - Computed: true, + Attr_Size: { + Computed: true, + Description: "The size of the image in megabytes.", + Type: schema.TypeInt, }, - "storage_type": { - Type: schema.TypeString, - Computed: true, + Attr_State: { + Computed: true, + Description: "The state for this image. ", + Type: schema.TypeString, }, - "storage_pool": { - Type: schema.TypeString, - Computed: true, + Attr_StoragePool: { + Computed: true, + Description: "Storage pool where image resides.", + Type: schema.TypeString, }, - "image_type": { - Type: schema.TypeString, - Computed: true, + Attr_StorageType: { + Computed: true, + Description: "The storage type for this image.", + Type: schema.TypeString, }, }, } @@ -76,24 +83,23 @@ func dataSourceIBMPIImagesRead(ctx context.Context, d *schema.ResourceData, meta return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) imageC := instance.NewIBMPIImageClient(ctx, sess, cloudInstanceID) - imagedata, err := imageC.Get(d.Get(helpers.PIImageName).(string)) + imagedata, err := imageC.Get(d.Get(Arg_ImageName).(string)) if err != nil { return diag.FromErr(err) } d.SetId(*imagedata.ImageID) - d.Set("state", imagedata.State) - d.Set("size", imagedata.Size) - d.Set("architecture", imagedata.Specifications.Architecture) - d.Set("hypervisor", imagedata.Specifications.HypervisorType) + d.Set(Attr_Architecture, imagedata.Specifications.Architecture) + d.Set(Attr_Hypervisor, imagedata.Specifications.HypervisorType) + d.Set(Attr_ImageType, imagedata.Specifications.ImageType) d.Set("operatingsystem", imagedata.Specifications.OperatingSystem) - d.Set("storage_type", imagedata.StorageType) - d.Set("storage_pool", imagedata.StoragePool) - d.Set("image_type", imagedata.Specifications.ImageType) + d.Set(Attr_Size, imagedata.Size) + d.Set(Attr_State, imagedata.State) + d.Set(Attr_StoragePool, imagedata.StoragePool) + d.Set(Attr_StorageType, imagedata.StorageType) return nil - } diff --git a/ibm/service/power/data_source_ibm_pi_image_test.go b/ibm/service/power/data_source_ibm_pi_image_test.go index 539aa9950e..734d3b71b7 100644 --- a/ibm/service/power/data_source_ibm_pi_image_test.go +++ b/ibm/service/power/data_source_ibm_pi_image_test.go @@ -13,7 +13,6 @@ import ( ) func TestAccIBMPIImageDataSource_basic(t *testing.T) { - resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -30,9 +29,8 @@ func TestAccIBMPIImageDataSource_basic(t *testing.T) { func testAccCheckIBMPIImageDataSourceConfig() string { return fmt.Sprintf(` - data "ibm_pi_image" "testacc_ds_image" { - pi_image_name = "%s" - pi_cloud_instance_id = "%s" - }`, acc.Pi_image, acc.Pi_cloud_instance_id) - + data "ibm_pi_image" "testacc_ds_image" { + pi_image_name = "%s" + pi_cloud_instance_id = "%s" + }`, acc.Pi_image, acc.Pi_cloud_instance_id) } diff --git a/ibm/service/power/data_source_ibm_pi_images.go b/ibm/service/power/data_source_ibm_pi_images.go index 9b6782aa9f..e3a8936325 100644 --- a/ibm/service/power/data_source_ibm_pi_images.go +++ b/ibm/service/power/data_source_ibm_pi_images.go @@ -6,70 +6,72 @@ package power import ( "context" - "github.com/IBM-Cloud/power-go-client/helpers" + "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/IBM-Cloud/power-go-client/power/models" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - //"fmt" - "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) -/* -Datasource to get the list of images that are available when a power instance is created -*/ +// Datasource to list images that are available when a power instance is created func DataSourceIBMPIImages() *schema.Resource { - return &schema.Resource{ ReadContext: dataSourceIBMPIImagesAllRead, Schema: map[string]*schema.Schema{ - - helpers.PICloudInstanceId: { - Type: schema.TypeString, + // Arguments + Arg_CloudInstanceID: { + Description: "The GUID of the service instance associated with an account.", Required: true, + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - // Computed Attributes - - "image_info": { - Type: schema.TypeList, - Computed: true, + // Attributes + Attr_ImageInfo: { + Computed: true, + Description: "List of all supported images.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "id": { - Type: schema.TypeString, - Computed: true, + Attr_Href: { + Computed: true, + Description: "The hyper link of an image.", + Type: schema.TypeString, }, - "name": { - Type: schema.TypeString, - Computed: true, + Attr_ID: { + Computed: true, + Description: "The unique identifier of an image.", + Type: schema.TypeString, }, - "href": { - Type: schema.TypeString, - Computed: true, + Attr_ImageType: { + Computed: true, + Description: "The identifier of this image type.", + Type: schema.TypeString, }, - "state": { - Type: schema.TypeString, - Computed: true, + Attr_Name: { + Computed: true, + Description: "The name of an image.", + Type: schema.TypeString, }, - "storage_type": { - Type: schema.TypeString, - Computed: true, + Attr_State: { + Computed: true, + Description: "The state of an image.", + Type: schema.TypeString, }, - "storage_pool": { - Type: schema.TypeString, - Computed: true, + Attr_StoragePool: { + Computed: true, + Description: "Storage pool where image resides.", + Type: schema.TypeString, }, - "image_type": { - Type: schema.TypeString, - Computed: true, + Attr_StorageType: { + Computed: true, + Description: "The storage type of an image.", + Type: schema.TypeString, }, }, }, + Type: schema.TypeList, }, }, } @@ -81,7 +83,7 @@ func dataSourceIBMPIImagesAllRead(ctx context.Context, d *schema.ResourceData, m return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) imageC := instance.NewIBMPIImageClient(ctx, sess, cloudInstanceID) imagedata, err := imageC.GetAll() @@ -91,28 +93,24 @@ func dataSourceIBMPIImagesAllRead(ctx context.Context, d *schema.ResourceData, m var clientgenU, _ = uuid.GenerateUUID() d.SetId(clientgenU) - d.Set("image_info", flattenStockImages(imagedata.Images)) + d.Set(Attr_ImageInfo, flattenStockImages(imagedata.Images)) return nil - } func flattenStockImages(list []*models.ImageReference) []map[string]interface{} { result := make([]map[string]interface{}, 0, len(list)) for _, i := range list { - l := map[string]interface{}{ - "id": *i.ImageID, - "state": *i.State, - "href": *i.Href, - "name": *i.Name, - "storage_type": *i.StorageType, - "storage_pool": *i.StoragePool, - "image_type": i.Specifications.ImageType, + Attr_Href: *i.Href, + Attr_ID: *i.ImageID, + Attr_ImageType: i.Specifications.ImageType, + Attr_Name: *i.Name, + Attr_State: *i.State, + Attr_StoragePool: *i.StoragePool, + Attr_StorageType: *i.StorageType, } - result = append(result, l) - } return result } diff --git a/ibm/service/power/data_source_ibm_pi_images_test.go b/ibm/service/power/data_source_ibm_pi_images_test.go index 083de54094..ee670de149 100644 --- a/ibm/service/power/data_source_ibm_pi_images_test.go +++ b/ibm/service/power/data_source_ibm_pi_images_test.go @@ -13,7 +13,6 @@ import ( ) func TestAccIBMPIImagesDataSource_basic(t *testing.T) { - resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -30,8 +29,7 @@ func TestAccIBMPIImagesDataSource_basic(t *testing.T) { func testAccCheckIBMPIImagesDataSourceConfig() string { return fmt.Sprintf(` - data "ibm_pi_images" "testacc_ds_image" { - pi_cloud_instance_id = "%s" - }`, acc.Pi_cloud_instance_id) - + data "ibm_pi_images" "testacc_ds_image" { + pi_cloud_instance_id = "%s" + }`, acc.Pi_cloud_instance_id) } diff --git a/website/docs/d/pi_image.html.markdown b/website/docs/d/pi_image.html.markdown index fad9111aa0..6c129d73ec 100644 --- a/website/docs/d/pi_image.html.markdown +++ b/website/docs/d/pi_image.html.markdown @@ -11,7 +11,6 @@ description: |- Import the details of an existing IBM Power Virtual Server Cloud image as a read-only data source. For more information, about IBM power virtual server cloud, see [getting started with IBM Power Systems Virtual Servers](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-getting-started). ## Example usage - ```terraform data "ibm_pi_image" "ds_image" { pi_image_name = "7200-03-03" @@ -19,14 +18,13 @@ data "ibm_pi_image" "ds_image" { } ``` - **Notes** -* Please find [supported Regions](https://cloud.ibm.com/apidocs/power-cloud#endpoint) for endpoints. -* If a Power cloud instance is provisioned at `lon04`, The provider level attributes should be as follows: - * `region` - `lon` - * `zone` - `lon04` - - Example usage: +**Notes** +- Please find [supported Regions](https://cloud.ibm.com/apidocs/power-cloud#endpoint) for endpoints. +- If a Power cloud instance is provisioned at `lon04`, The provider level attributes should be as follows: + - `region` - `lon` + - `zone` - `lon04` +Example usage: ```terraform provider "ibm" { region = "lon" @@ -44,10 +42,11 @@ Review the argument references that you can specify for your data source. In addition to all argument reference list, you can access the following attribute references after your data source is created. - `architecture` - (String) The CPU architecture that the image is designed for. +- `hypervisor` - (String) Hypervisor type. - `id` - (String) The unique identifier of the image. +- `image_type` - (String) The identifier of this image type. - `operatingsystem` - (String) The operating system that is installed with the image. - `size` - (String) The size of the image in megabytes. - `state` - (String) The state for this image. - `storage_type` - (String) The storage type for this image. - `storage_pool` - (String) Storage pool where image resides. -- `image_type` - (String) The identifier of this image type. diff --git a/website/docs/d/pi_images.html.markdown b/website/docs/d/pi_images.html.markdown index 791e2df2bf..617207e159 100644 --- a/website/docs/d/pi_images.html.markdown +++ b/website/docs/d/pi_images.html.markdown @@ -18,14 +18,13 @@ data "ibm_pi_images" "ds_images" { } ``` - **Notes:** -* Please find [supported Regions](https://cloud.ibm.com/apidocs/power-cloud#endpoint) for endpoints. -* If a Power cloud instance is provisioned at `lon04`, The provider level attributes should be as follows: - * `region` - `lon` - * `zone` - `lon04` - - Example usage: +**Notes:** +- Please find [supported Regions](https://cloud.ibm.com/apidocs/power-cloud#endpoint) for endpoints. +- If a Power cloud instance is provisioned at `lon04`, The provider level attributes should be as follows: + - `region` - `lon` + - `zone` - `lon04` +Example usage: ```terraform provider "ibm" { region = "lon" @@ -41,13 +40,13 @@ Review the argument references that you can specify for your data source. ## Attribute reference In addition to all argument reference list, you can access the following attribute references after your data source is created. -- `image_info` - List of images - A list of all supported images. +- `image_info` - (List) List of all supported images. Nested scheme for `image_info`: - `href` - (String) The hyper link of an image. - `id` - (String) The unique identifier of an image. + - `image_type` - (String) The identifier of this image type. - `name`- (String) The name of an image. - `state` - (String) The state of an image. - `storage_pool` - (String) Storage pool where image resides. - `storage_type` - (String) The storage type of an image. - - `image_type` - (String) The identifier of this image type.