diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index b9ec88a7ff..915bd02991 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -23,6 +23,11 @@ const ( Arg_IBMiCSS = "pi_ibmi_css" Arg_IBMiPHA = "pi_ibmi_pha" Arg_IBMiRDSUsers = "pi_ibmi_rds_users" + Arg_ImageID = "pi_image_id" + Arg_ImageBucketName = "pi_image_bucket_name" + Arg_ImageBucketRegion = "pi_image_bucket_region" + Arg_ImageSecretKey = "pi_image_secret_key" + Arg_ImageAccessKey = "pi_image_access_key" Arg_ImageName = "pi_image_name" Arg_InstanceName = "pi_instance_name" Arg_KeyName = "pi_key_name" diff --git a/ibm/service/power/resource_ibm_pi_image_export.go b/ibm/service/power/resource_ibm_pi_image_export.go index ed3df33d6a..cd8ab4b342 100644 --- a/ibm/service/power/resource_ibm_pi_image_export.go +++ b/ibm/service/power/resource_ibm_pi_image_export.go @@ -11,9 +11,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - st "github.com/IBM-Cloud/power-go-client/clients/instance" - "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/IBM-Cloud/terraform-provider-ibm/ibm/flex" @@ -31,46 +31,51 @@ func ResourceIBMPIImageExport() *schema.Resource { }, Schema: map[string]*schema.Schema{ - //required attributes - helpers.PICloudInstanceId: { - Type: schema.TypeString, - Required: true, - Description: "PI cloud instance ID", - ForceNew: true, + // Arguments + Arg_CloudInstanceID: { + Description: "The GUID of the service instance associated with an account.", + ForceNew: true, + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, }, - helpers.PIImageId: { - Type: schema.TypeString, - Required: true, - Description: "Instance image id", - DiffSuppressFunc: flex.ApplyOnce, - ForceNew: true, + Arg_ImageAccessKey: { + Description: "Cloud Object Storage access key; required for buckets with private access", + ForceNew: true, + Required: true, + Sensitive: true, + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, }, - helpers.PIImageBucketName: { - Type: schema.TypeString, - Required: true, - Description: "Cloud Object Storage bucket name; bucket-name[/optional/folder]", - ForceNew: true, + Arg_ImageBucketName: { + Description: "Cloud Object Storage bucket name; bucket-name[/optional/folder]", + ForceNew: true, + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, }, - helpers.PIImageAccessKey: { - Type: schema.TypeString, - Required: true, - Description: "Cloud Object Storage access key; required for buckets with private access", - Sensitive: true, - ForceNew: true, + Arg_ImageBucketRegion: { + Description: "Cloud Object Storage region", + ForceNew: true, + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, }, - - helpers.PIImageSecretKey: { - Type: schema.TypeString, - Required: true, - Description: "Cloud Object Storage secret key; required for buckets with private access", - Sensitive: true, - ForceNew: true, + Arg_ImageID: { + Description: "Instance image id", + DiffSuppressFunc: flex.ApplyOnce, + ForceNew: true, + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, }, - helpers.PIImageBucketRegion: { - Type: schema.TypeString, - Description: "Cloud Object Storage region", - ForceNew: true, - Required: true, + Arg_ImageSecretKey: { + Description: "Cloud Object Storage secret key; required for buckets with private access", + ForceNew: true, + Required: true, + Sensitive: true, + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, }, }, } @@ -83,28 +88,28 @@ func resourceIBMPIImageExportCreate(ctx context.Context, d *schema.ResourceData, return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) - imageid := d.Get(helpers.PIImageId).(string) - bucketName := d.Get(helpers.PIImageBucketName).(string) - accessKey := d.Get(helpers.PIImageAccessKey).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) + imageid := d.Get(Arg_ImageID).(string) + bucketName := d.Get(Arg_ImageBucketName).(string) + accessKey := d.Get(Arg_ImageAccessKey).(string) - client := st.NewIBMPIImageClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPIImageClient(ctx, sess, cloudInstanceID) // image export var body = &models.ExportImage{ BucketName: &bucketName, AccessKey: &accessKey, - Region: d.Get(helpers.PIImageBucketRegion).(string), - SecretKey: d.Get(helpers.PIImageSecretKey).(string), + Region: d.Get(Arg_ImageBucketRegion).(string), + SecretKey: d.Get(Arg_ImageSecretKey).(string), } imageResponse, err := client.ExportImage(imageid, body) if err != nil { return diag.FromErr(err) } - d.SetId(fmt.Sprintf("%s/%s/%s", imageid, bucketName, d.Get(helpers.PIImageBucketRegion).(string))) + d.SetId(fmt.Sprintf("%s/%s/%s", imageid, bucketName, d.Get(Arg_ImageBucketRegion).(string))) - jobClient := st.NewIBMPIJobClient(ctx, sess, cloudInstanceID) + jobClient := instance.NewIBMPIJobClient(ctx, sess, cloudInstanceID) _, err = waitForIBMPIJobCompleted(ctx, jobClient, *imageResponse.ID, d.Timeout(schema.TimeoutCreate)) if err != nil { return diag.FromErr(err) diff --git a/website/docs/r/pi_image_export.html.markdown b/website/docs/r/pi_image_export.html.markdown index 1b1e71fe6e..297face0f8 100644 --- a/website/docs/r/pi_image_export.html.markdown +++ b/website/docs/r/pi_image_export.html.markdown @@ -8,9 +8,11 @@ description: |- --- # ibm_pi_image_export + Export an image to IBM Cloud Object Storage for Power Systems Virtual Server instance. 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 + The following example enables you to export an image: ```terraform @@ -24,7 +26,8 @@ resource "ibm_pi_image_export" "testacc_image_export"{ } ``` -**Note** +### Notes + * Ensure the exported file is cleaned up manually from the Cloud Object Storage when no longer needed. Power Systems Virtual Server does not support deleting the exported image. Updating any attribute will result in creating a new Export job. * 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: @@ -44,22 +47,21 @@ resource "ibm_pi_image_export" "testacc_image_export"{ The ibm_pi_image provides the following [timeouts](https://www.terraform.io/docs/language/resources/syntax.html) configuration options: -- **Create** The export image to IBM Cloud Object Storage bucket is considered failed if no response is received for 60 minutes. +* **create** - (Default 60 minutes) Used for exporting image to IBM Cloud Object Storage bucket. ## Argument reference -Review the argument references that you can specify for your resource. - -- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. -- `pi_image_id` - (Required, String) The Image ID of existing source image; required for image export. -- `pi_image_bucket_name` - (Required, String) The Cloud Object Storage bucket name; `bucket-name[/optional/folder]` -- `pi_image_access_key` - (Required, String, Sensitive) The Cloud Object Storage access key; required for buckets with private access. -- `pi_image_bucket_region` - (Required, String) The Cloud Object Storage region. Supported COS regions are:`au-syd`, `br-sao`, `ca-tor`, `eu-de`, `eu-es`, `eu-gb`, `jp-osa`, `jp-tok`, `us-east`, `us-south`. -- `pi_image_secret_key` - (Required, String, Sensitive) The Cloud Object Storage secret key; required for buckets with private access. +Review the argument references that you can specify for your resource. +* `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. +* `pi_image_access_key` - (Required, String, Sensitive) The Cloud Object Storage access key; required for buckets with private access. +* `pi_image_bucket_name` - (Required, String) The Cloud Object Storage bucket name; `bucket-name[/optional/folder]` +* `pi_image_bucket_region` - (Required, String) The Cloud Object Storage region. Supported COS regions are:`au-syd`, `br-sao`, `ca-tor`, `eu-de`, `eu-es`, `eu-gb`, `jp-osa`, `jp-tok`, `us-east`, `us-south`. +* `pi_image_id` - (Required, String) The Image ID of existing source image; required for image export. +* `pi_image_secret_key` - (Required, String, Sensitive) The Cloud Object Storage secret key; required for buckets with private access. ## Attribute reference -In addition to all argument reference list, you can access the following attribute reference after your resource is created. -- `id` - (String) The unique identifier of an image export resource. The ID is composed of `//`. +In addition to all argument reference list, you can access the following attribute reference after your resource is created. +* `id` - (String) The unique identifier of an image export resource. The ID is composed of `//`.