From d483180e705c446bb11b72886d6fcf29c4498684 Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Thu, 28 Dec 2023 00:04:42 +0530 Subject: [PATCH 01/16] Catalog-refactor images data source --- .../data_source_ibm_pi_catalog_images.go | 250 ++++++++++-------- .../data_source_ibm_pi_catalog_images_test.go | 36 ++- .../docs/d/pi_catalog_images.html.markdown | 24 +- 3 files changed, 162 insertions(+), 148 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_catalog_images.go b/ibm/service/power/data_source_ibm_pi_catalog_images.go index 62adf75a8e..e32f8d17ff 100644 --- a/ibm/service/power/data_source_ibm_pi_catalog_images.go +++ b/ibm/service/power/data_source_ibm_pi_catalog_images.go @@ -7,108 +7,125 @@ import ( "context" "time" + "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" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - - "github.com/IBM-Cloud/power-go-client/clients/instance" - "github.com/IBM-Cloud/power-go-client/helpers" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" ) -/* -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 DataSourceIBMPICatalogImages() *schema.Resource { - return &schema.Resource{ ReadContext: dataSourceIBMPICatalogImagesRead, 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, }, - "sap": { - Type: schema.TypeBool, - Optional: true, + Arg_SAP: { + Description: "Set true to include SAP images. The default value is false.", + Optional: true, + Type: schema.TypeBool, }, - "vtl": { - Type: schema.TypeBool, - Optional: true, + Arg_VTL: { + Description: "Set true to include VTL images. The default value is false.", + Optional: true, + Type: schema.TypeBool, }, - "images": { - Type: schema.TypeList, - Computed: true, + + // Attributes + Attr_Images: { + Computed: true, + Description: "Lists all the images in the IBM Power Virtual Server Cloud.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "image_id": { - Type: schema.TypeString, - Computed: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "state": { - Type: schema.TypeString, - Computed: true, - }, - "description": { - Type: schema.TypeString, - Computed: true, - }, - "storage_type": { - Type: schema.TypeString, - Computed: true, - }, - "storage_pool": { - Type: schema.TypeString, - Computed: true, - }, - "creation_date": { - Type: schema.TypeString, - Computed: true, - }, - "last_update_date": { - Type: schema.TypeString, - Computed: true, - }, - "image_type": { - Type: schema.TypeString, - Computed: true, - }, - "container_format": { - Type: schema.TypeString, - Computed: true, - }, - "disk_format": { - Type: schema.TypeString, - Computed: true, - }, - "operating_system": { - Type: schema.TypeString, - Computed: true, - }, - "hypervisor_type": { - Type: schema.TypeString, - Computed: true, - }, - "architecture": { - Type: schema.TypeString, - Computed: true, - }, - "endianness": { - Type: schema.TypeString, - Computed: true, - }, - "href": { - Type: schema.TypeString, - Computed: true, + Attr_Architecture: { + Computed: true, + Description: "The CPU architecture that the image is designed for.", + Type: schema.TypeString, + }, + Attr_ContainerFormat: { + Computed: true, + Description: "The container format.", + Type: schema.TypeString, + }, + Attr_CreationDate: { + Computed: true, + Description: "Date of image creation", + Type: schema.TypeString, + }, + Attr_Description: { + Computed: true, + Description: "The description of an image.", + Type: schema.TypeString, + }, + Attr_DiskFormat: { + Computed: true, + Description: "The disk format.", + Type: schema.TypeString, + }, + Attr_Endianness: { + Computed: true, + Description: "The Endianness order.", + Type: schema.TypeString, + }, + Attr_Href: { + Computed: true, + Description: "The href of an image.", + Type: schema.TypeString, + }, + Attr_HypervisorType: { + Computed: true, + Description: "Hypervisor type.", + Type: schema.TypeString, + }, + Attr_ImageID: { + Computed: true, + Description: "The unique identifier of an image.", + Type: schema.TypeString, + }, + Attr_ImageType: { + Computed: true, + Description: "The identifier of this image type.", + Type: schema.TypeString, + }, + Attr_LastUpdateDate: { + Computed: true, + Description: "The last updated date of an image.", + Type: schema.TypeString, + }, + Attr_Name: { + Computed: true, + Description: "The name of the image.", + Type: schema.TypeString, + }, + Attr_OperatingSystem: { + Computed: true, + Description: "Operating System.", + Type: schema.TypeString, + }, + Attr_State: { + Computed: true, + Description: "The state of an Operating System.", + Type: schema.TypeString, + }, + Attr_StoragePool: { + Computed: true, + Description: "Storage pool where image resides.", + Type: schema.TypeString, + }, + Attr_StorageType: { + Computed: true, + Description: "The storage type of an image.", + Type: schema.TypeString, }, }, }, + Type: schema.TypeList, }, }, } @@ -120,13 +137,13 @@ func dataSourceIBMPICatalogImagesRead(ctx context.Context, d *schema.ResourceDat return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) includeSAP := false - if s, ok := d.GetOk("sap"); ok { + if s, ok := d.GetOk(Arg_SAP); ok { includeSAP = s.(bool) } includeVTL := false - if v, ok := d.GetOk("vtl"); ok { + if v, ok := d.GetOk(Arg_VTL); ok { includeVTL = v.(bool) } imageC := instance.NewIBMPIImageClient(ctx, sess, cloudInstanceID) @@ -138,57 +155,58 @@ func dataSourceIBMPICatalogImagesRead(ctx context.Context, d *schema.ResourceDat images := make([]map[string]interface{}, 0) for _, i := range stockImages.Images { image := make(map[string]interface{}) - image["image_id"] = *i.ImageID - image["name"] = *i.Name - if i.State != nil { - image["state"] = *i.State - } + image[Attr_ImageID] = *i.ImageID + image[Attr_Name] = *i.Name + if i.Description != nil { - image["description"] = *i.Description - } - if i.StorageType != nil { - image["storage_type"] = *i.StorageType - } - if i.StoragePool != nil { - image["storage_pool"] = *i.StoragePool + image[Attr_Description] = *i.Description } if i.CreationDate != nil { - image["creation_date"] = i.CreationDate.String() - } - if i.LastUpdateDate != nil { - image["last_update_date"] = i.LastUpdateDate.String() + image[Attr_CreationDate] = i.CreationDate.String() } if i.Href != nil { - image["href"] = *i.Href + image[Attr_Href] = *i.Href + } + if i.LastUpdateDate != nil { + image[Attr_LastUpdateDate] = i.LastUpdateDate.String() } if i.Specifications != nil { s := i.Specifications - if s.ImageType != "" { - image["image_type"] = s.ImageType + if s.Architecture != "" { + image[Attr_Architecture] = s.Architecture } if s.ContainerFormat != "" { - image["container_format"] = s.ContainerFormat + image[Attr_ContainerFormat] = s.ContainerFormat } if s.DiskFormat != "" { - image["disk_format"] = s.DiskFormat + image[Attr_DiskFormat] = s.DiskFormat } - if s.OperatingSystem != "" { - image["operating_system"] = s.OperatingSystem + if s.Endianness != "" { + image[Attr_Endianness] = s.Endianness } if s.HypervisorType != "" { - image["hypervisor_type"] = s.HypervisorType + image[Attr_HypervisorType] = s.HypervisorType } - if s.Architecture != "" { - image["architecture"] = s.Architecture + if s.ImageType != "" { + image[Attr_ImageType] = s.ImageType } - if s.Endianness != "" { - image["endianness"] = s.Endianness + if s.OperatingSystem != "" { + image[Attr_OperatingSystem] = s.OperatingSystem } } + if i.State != nil { + image[Attr_State] = *i.State + } + if i.StoragePool != nil { + image[Attr_StoragePool] = *i.StoragePool + } + if i.StorageType != nil { + image[Attr_StorageType] = *i.StorageType + } images = append(images, image) } d.SetId(time.Now().UTC().String()) - d.Set("images", images) - return nil + d.Set(Attr_Images, images) + return nil } diff --git a/ibm/service/power/data_source_ibm_pi_catalog_images_test.go b/ibm/service/power/data_source_ibm_pi_catalog_images_test.go index a18020ff3d..f317397229 100644 --- a/ibm/service/power/data_source_ibm_pi_catalog_images_test.go +++ b/ibm/service/power/data_source_ibm_pi_catalog_images_test.go @@ -14,38 +14,34 @@ import ( func testAccCheckIBMPICatalogImagesDataSourceBasicConfig() string { return fmt.Sprintf(` - data "ibm_pi_catalog_images" "power_catalog_images_basic" { - pi_cloud_instance_id = "%s" - } - `, acc.Pi_cloud_instance_id) + data "ibm_pi_catalog_images" "power_catalog_images_basic" { + pi_cloud_instance_id = "%s" + }`, acc.Pi_cloud_instance_id) } func testAccCheckIBMPICatalogImagesDataSourceSAPConfig() string { return fmt.Sprintf(` - data "ibm_pi_catalog_images" "power_catalog_images_sap" { - pi_cloud_instance_id = "%s" - sap = "true" - } - `, acc.Pi_cloud_instance_id) + data "ibm_pi_catalog_images" "power_catalog_images_sap" { + pi_cloud_instance_id = "%s" + sap = "true" + }`, acc.Pi_cloud_instance_id) } func testAccCheckIBMPICatalogImagesDataSourceVTLConfig() string { return fmt.Sprintf(` - data "ibm_pi_catalog_images" "power_catalog_images_vtl" { - pi_cloud_instance_id = "%s" - vtl = "true" - } - `, acc.Pi_cloud_instance_id) + data "ibm_pi_catalog_images" "power_catalog_images_vtl" { + pi_cloud_instance_id = "%s" + vtl = "true" + }`, acc.Pi_cloud_instance_id) } func testAccCheckIBMPICatalogImagesDataSourceSAP_And_VTLConfig() string { return fmt.Sprintf(` - data "ibm_pi_catalog_images" "power_catalog_images_sap_and_vtl" { - pi_cloud_instance_id = "%s" - sap = "true" - vtl = "true" - } - `, acc.Pi_cloud_instance_id) + data "ibm_pi_catalog_images" "power_catalog_images_sap_and_vtl" { + pi_cloud_instance_id = "%s" + sap = "true" + vtl = "true" + }`, acc.Pi_cloud_instance_id) } func TestAccIBMPICatalogImagesDataSourceBasic(t *testing.T) { diff --git a/website/docs/d/pi_catalog_images.html.markdown b/website/docs/d/pi_catalog_images.html.markdown index 8693c9e211..a40655476a 100644 --- a/website/docs/d/pi_catalog_images.html.markdown +++ b/website/docs/d/pi_catalog_images.html.markdown @@ -10,7 +10,7 @@ description: |- Retrieve the details of an image that you can use in your Power Systems Virtual Server instance for copying into IBM Cloud instances. For more information, about catalog images, see [provisioning a virtual server instance from a third-party image](https://cloud.ibm.com/docs/virtual-servers?topic=virtual-servers-ordering-3P). ## Example usage -The following example shows how to retrieve information by using `ibm_pi_catalog_images`. +The following example shows how to retrieve information using `ibm_pi_catalog_images`. ```terraform data "ibm_pi_catalog_images" "ds_images" { @@ -19,13 +19,12 @@ data "ibm_pi_catalog_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: +- 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" @@ -46,18 +45,19 @@ In addition to the argument reference list, you can access the following attribu - `images`- (List) Lists all the images in the IBM Power Virtual Server Cloud. Nested scheme for `images`: - - `architecture` - (String) Architecture. - - `creation_date` - (String) The creation date of an image. + - `architecture` - (String) The CPU architecture that the image is designed for. + - `container_format` - (String) The container format. + - `creation_date` - (String) Date of image creation. - `description` - (String) The description of an image. - `disk_format` - (String) The disk format. - `endianness` - (String) The `Endianness` order. - - `hypervisor_type` - (String) Hypervisor type. - `href` - (String) The `href` of an image. + - `hypervisor_type` - (String) Hypervisor type. - `image_id` - (String) The unique identifier of an image. - - `image_type` - (String) The type of the format. + - `image_type` - (String) The identifier of this image type. - `last_update_date` - (String) The last updated date of an image. - `name` - (String) The name of the image. - `operating_system` - (String) Operating System. + - `state` - (String) The state of an Operating System. - `storage_pool` - (String) Storage pool where image resides. - `storage_type` - (String) The storage type of an image. - - `state` - (String) The state of an Operating System. From cc8022673c2934b2c456996a2db0f8768af6693b Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Thu, 28 Dec 2023 00:26:45 +0530 Subject: [PATCH 02/16] Catalog-refactor cloud connections data source documentations --- .../data_source_ibm_pi_cloud_connection.go | 175 +++++++++--------- ...ata_source_ibm_pi_cloud_connection_test.go | 9 +- .../data_source_ibm_pi_cloud_connections.go | 171 ++++++++--------- .../docs/d/pi_cloud_connection.html.markdown | 27 +-- .../docs/d/pi_cloud_connections.html.markdown | 23 +-- 5 files changed, 193 insertions(+), 212 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_cloud_connection.go b/ibm/service/power/data_source_ibm_pi_cloud_connection.go index 8e5bc59f83..f9a571aa19 100644 --- a/ibm/service/power/data_source_ibm_pi_cloud_connection.go +++ b/ibm/service/power/data_source_ibm_pi_cloud_connection.go @@ -7,129 +7,117 @@ import ( "context" "log" - "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" - "github.com/IBM-Cloud/power-go-client/clients/instance" - "github.com/IBM-Cloud/power-go-client/helpers" "github.com/IBM-Cloud/power-go-client/power/models" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" -) - -const ( - PICloudConnectionId = "cloud_connection_id" - PICloudConnectionName = "name" - PICloudConnectionSpeed = "speed" - PICloudConnectionGlobalRouting = "global_routing" - PICloudConnectionMetered = "metered" - PICloudConnectionStatus = "status" - PICloudConnectionClassicEnabled = "classic_enabled" - PICloudConnectionUserIPAddress = "user_ip_address" - PICloudConnectionIBMIPAddress = "ibm_ip_address" - PICloudConnectionPort = "port" - PICloudConnectionNetworks = "networks" - PICloudConnectionClassicGreDest = "gre_destination_address" - PICloudConnectionClassicGreSource = "gre_source_address" - PICloudConnectionVPCEnabled = "vpc_enabled" - PICloudConnectionVPCCRNs = "vpc_crns" - PICloudConnectionConnectionMode = "connection_mode" + "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" ) func DataSourceIBMPICloudConnection() *schema.Resource { return &schema.Resource{ - ReadContext: dataSourceIBMPICloudConnectionRead, + ReadContext: dataSourceIBMAttr_Read, 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, }, - helpers.PICloudConnectionName: { - Type: schema.TypeString, + Arg_CloudConnectionName: { + Description: "The cloud connection name to be used.", Required: true, - Description: "Cloud Connection Name to be used", + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - // Computed Attributes - PICloudConnectionSpeed: { - Type: schema.TypeInt, - Computed: true, + // Attributes + Attr_ClassicEnabled: { + Computed: true, + Description: "Enable classic endpoint destination.", + Type: schema.TypeBool, }, - PICloudConnectionGlobalRouting: { - Type: schema.TypeBool, - Computed: true, + Attr_ConnectionMode: { + Computed: true, + Description: "Type of service the gateway is attached to.", + Type: schema.TypeString, }, - PICloudConnectionMetered: { - Type: schema.TypeBool, - Computed: true, + Attr_GlobalRouting: { + Computed: true, + Description: "Enable global routing for this cloud connection.", + Type: schema.TypeBool, }, - PICloudConnectionStatus: { - Type: schema.TypeString, - Computed: true, + Attr_GreDestinationAddress: { + Computed: true, + Description: "GRE destination IP address.", + Type: schema.TypeString, }, - PICloudConnectionIBMIPAddress: { - Type: schema.TypeString, - Computed: true, + Attr_GreSourceAddress: { + Computed: true, + Description: "GRE auto-assigned source IP address.", + Type: schema.TypeString, }, - PICloudConnectionUserIPAddress: { - Type: schema.TypeString, - Computed: true, + Attr_IBMIPAddress: { + Computed: true, + Description: "The IBM IP address.", + Type: schema.TypeString, }, - PICloudConnectionPort: { - Type: schema.TypeString, - Computed: true, + Attr_Metered: { + Computed: true, + Description: "Enable metering for this cloud connection.", + Type: schema.TypeBool, }, - PICloudConnectionNetworks: { - Type: schema.TypeSet, + Attr_Networks: { Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, Description: "Set of Networks attached to this cloud connection", + Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeSet, }, - PICloudConnectionClassicEnabled: { - Type: schema.TypeBool, + Attr_Port: { Computed: true, - Description: "Enable classic endpoint destination", - }, - PICloudConnectionClassicGreDest: { + Description: "Port.", Type: schema.TypeString, + }, + Attr_Speed: { Computed: true, - Description: "GRE destination IP address", + Description: "Speed of the cloud connection (speed in megabits per second)", + Type: schema.TypeInt, }, - PICloudConnectionClassicGreSource: { - Type: schema.TypeString, + Attr_Status: { Computed: true, - Description: "GRE auto-assigned source IP address", + Description: "Link status.", + Type: schema.TypeString, }, - PICloudConnectionVPCEnabled: { - Type: schema.TypeBool, + Attr_UserIPAddress: { Computed: true, - Description: "Enable VPC for this cloud connection", + Description: "User IP address.", + Type: schema.TypeString, }, - PICloudConnectionVPCCRNs: { - Type: schema.TypeSet, + Attr_VPCCRNs: { Computed: true, + Description: "Set of VPCs attached to this cloud connection.", Elem: &schema.Schema{Type: schema.TypeString}, - Description: "Set of VPCs attached to this cloud connection", + Type: schema.TypeSet, }, - PICloudConnectionConnectionMode: { - Type: schema.TypeString, + Attr_VPCEnabled: { Computed: true, - Description: "Type of service the gateway is attached to", + Description: "Enable VPC for this cloud connection.", + Type: schema.TypeBool, }, }, } } -func dataSourceIBMPICloudConnectionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func dataSourceIBMAttr_Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { sess, err := meta.(conns.ClientSession).IBMPISession() if err != nil { return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) - cloudConnectionName := d.Get(helpers.PICloudConnectionName).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) + cloudConnectionName := d.Get(Attr_Name).(string) client := instance.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) // Get API does not work with name for Cloud Connection hence using GetAll (max 2) @@ -165,16 +153,18 @@ func dataSourceIBMPICloudConnectionRead(ctx context.Context, d *schema.ResourceD } d.SetId(*cloudConnection.CloudConnectionID) - d.Set(helpers.PICloudConnectionName, cloudConnection.Name) - d.Set(PICloudConnectionGlobalRouting, cloudConnection.GlobalRouting) - d.Set(PICloudConnectionMetered, cloudConnection.Metered) - d.Set(PICloudConnectionIBMIPAddress, cloudConnection.IbmIPAddress) - d.Set(PICloudConnectionUserIPAddress, cloudConnection.UserIPAddress) - d.Set(PICloudConnectionStatus, cloudConnection.LinkStatus) - d.Set(PICloudConnectionPort, cloudConnection.Port) - d.Set(PICloudConnectionSpeed, cloudConnection.Speed) - d.Set(helpers.PICloudInstanceId, cloudInstanceID) - d.Set(PICloudConnectionConnectionMode, cloudConnection.ConnectionMode) + + d.Set(Arg_CloudInstanceID, cloudInstanceID) + d.Set(Arg_CloudConnectionName, cloudConnection.Name) + + d.Set(Attr_GlobalRouting, cloudConnection.GlobalRouting) + d.Set(Attr_Metered, cloudConnection.Metered) + d.Set(Attr_IBMIPAddress, cloudConnection.IbmIPAddress) + d.Set(Attr_UserIPAddress, cloudConnection.UserIPAddress) + d.Set(Attr_Status, cloudConnection.LinkStatus) + d.Set(Attr_Port, cloudConnection.Port) + d.Set(Attr_Speed, cloudConnection.Speed) + d.Set(Attr_ConnectionMode, cloudConnection.ConnectionMode) if cloudConnection.Networks != nil { networks := make([]string, len(cloudConnection.Networks)) for i, ccNetwork := range cloudConnection.Networks { @@ -182,24 +172,25 @@ func dataSourceIBMPICloudConnectionRead(ctx context.Context, d *schema.ResourceD networks[i] = *ccNetwork.NetworkID } } - d.Set(PICloudConnectionNetworks, networks) + d.Set(Attr_Networks, networks) } if cloudConnection.Classic != nil { - d.Set(PICloudConnectionClassicEnabled, cloudConnection.Classic.Enabled) + d.Set(Attr_ClassicEnabled, cloudConnection.Classic.Enabled) if cloudConnection.Classic.Gre != nil { - d.Set(PICloudConnectionClassicGreDest, cloudConnection.Classic.Gre.DestIPAddress) - d.Set(PICloudConnectionClassicGreSource, cloudConnection.Classic.Gre.SourceIPAddress) + d.Set(Attr_GreDestinationAddress, cloudConnection.Classic.Gre.DestIPAddress) + d.Set(Attr_GreSourceAddress, cloudConnection.Classic.Gre.SourceIPAddress) } } if cloudConnection.Vpc != nil { - d.Set(PICloudConnectionVPCEnabled, cloudConnection.Vpc.Enabled) + d.Set(Attr_VPCEnabled, cloudConnection.Vpc.Enabled) if cloudConnection.Vpc.Vpcs != nil && len(cloudConnection.Vpc.Vpcs) > 0 { vpcCRNs := make([]string, len(cloudConnection.Vpc.Vpcs)) for i, vpc := range cloudConnection.Vpc.Vpcs { vpcCRNs[i] = *vpc.VpcID } - d.Set(PICloudConnectionVPCCRNs, vpcCRNs) + d.Set(Attr_VPCCRNs, vpcCRNs) } } + return nil } diff --git a/ibm/service/power/data_source_ibm_pi_cloud_connection_test.go b/ibm/service/power/data_source_ibm_pi_cloud_connection_test.go index 732b10ad1f..60eda0cb08 100644 --- a/ibm/service/power/data_source_ibm_pi_cloud_connection_test.go +++ b/ibm/service/power/data_source_ibm_pi_cloud_connection_test.go @@ -30,9 +30,8 @@ func TestAccIBMPICloudConnectionDataSource_basic(t *testing.T) { func testAccCheckIBMPICloudConnectionDataSourceConfig() string { return fmt.Sprintf(` - data "ibm_pi_cloud_connection" "example" { - pi_cloud_connection_name = "%s" - pi_cloud_instance_id = "%s" - } - `, acc.PiCloudConnectionName, acc.Pi_cloud_instance_id) + data "ibm_pi_cloud_connection" "example" { + pi_cloud_connection_name = "%s" + pi_cloud_instance_id = "%s" + }`, acc.PiCloudConnectionName, acc.Pi_cloud_instance_id) } diff --git a/ibm/service/power/data_source_ibm_pi_cloud_connections.go b/ibm/service/power/data_source_ibm_pi_cloud_connections.go index ad5a35e434..2e99b1ea97 100644 --- a/ibm/service/power/data_source_ibm_pi_cloud_connections.go +++ b/ibm/service/power/data_source_ibm_pi_cloud_connections.go @@ -7,113 +7,118 @@ import ( "context" "log" - 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/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" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) -/* -Datasource to get the list of Cloud Connections in a power instance -*/ - -const PICloudConnections = "connections" - +// Datasource to list Cloud Connections in a power instance func DataSourceIBMPICloudConnections() *schema.Resource { - return &schema.Resource{ ReadContext: dataSourceIBMPICloudConnectionsRead, 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 - PICloudConnections: { - Type: schema.TypeList, - Computed: true, + + // Attributes + Attr_Connections: { + Computed: true, + Description: "List of all the Cloud Connections.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - PICloudConnectionId: { - Type: schema.TypeString, - Computed: true, + Attr_ClassicEnabled: { + Computed: true, + Description: "Enable classic endpoint destination.", + Type: schema.TypeBool, }, - PICloudConnectionName: { - Type: schema.TypeString, - Computed: true, + Attr_CloudConnectionID: { + Computed: true, + Description: "The unique identifier of the cloud connection.", + Type: schema.TypeString, }, - PICloudConnectionSpeed: { - Type: schema.TypeInt, - Computed: true, + Attr_ConnectionMode: { + Computed: true, + Description: "Type of service the gateway is attached to.", + Type: schema.TypeString, }, - PICloudConnectionGlobalRouting: { - Type: schema.TypeBool, - Computed: true, + Attr_GlobalRouting: { + Computed: true, + Description: "Enable global routing for this cloud connection.", + Type: schema.TypeBool, }, - PICloudConnectionMetered: { - Type: schema.TypeBool, - Computed: true, + Attr_GreDestinationAddress: { + Computed: true, + Description: "GRE destination IP address.", + Type: schema.TypeString, }, - PICloudConnectionStatus: { - Type: schema.TypeString, - Computed: true, + Attr_GreSourceAddress: { + Computed: true, + Description: "GRE auto-assigned source IP address.", + Type: schema.TypeString, }, - PICloudConnectionIBMIPAddress: { - Type: schema.TypeString, - Computed: true, + Attr_IBMIPAddress: { + Computed: true, + Description: "IBM IP address.", + Type: schema.TypeString, }, - PICloudConnectionUserIPAddress: { - Type: schema.TypeString, - Computed: true, + Attr_Metered: { + Computed: true, + Description: "Enable metering for this cloud connection.", + Type: schema.TypeBool, }, - PICloudConnectionPort: { - Type: schema.TypeString, - Computed: true, + Attr_Name: { + Computed: true, + Description: "Name of the cloud connection.", + Type: schema.TypeString, }, - PICloudConnectionNetworks: { - Type: schema.TypeSet, + Attr_Networks: { Computed: true, + Description: "Set of Networks attached to this cloud connection.", Elem: &schema.Schema{Type: schema.TypeString}, - Description: "Set of Networks attached to this cloud connection", + Type: schema.TypeSet, }, - PICloudConnectionClassicEnabled: { - Type: schema.TypeBool, + Attr_Port: { Computed: true, - Description: "Enable classic endpoint destination", - }, - PICloudConnectionClassicGreDest: { + Description: "Port.", Type: schema.TypeString, + }, + Attr_Speed: { Computed: true, - Description: "GRE destination IP address", + Description: "Speed of the cloud connection (speed in megabits per second).", + Type: schema.TypeInt, }, - PICloudConnectionClassicGreSource: { - Type: schema.TypeString, + Attr_Status: { Computed: true, - Description: "GRE auto-assigned source IP address", + Description: "Link status.", + Type: schema.TypeString, }, - PICloudConnectionVPCEnabled: { - Type: schema.TypeBool, + Attr_UserIPAddress: { Computed: true, - Description: "Enable VPC for this cloud connection", + Description: "User IP address.", + Type: schema.TypeString, }, - PICloudConnectionVPCCRNs: { - Type: schema.TypeSet, + Attr_VPCCRNs: { Computed: true, + Description: "Set of VPCs attached to this cloud connection.", Elem: &schema.Schema{Type: schema.TypeString}, - Description: "Set of VPCs attached to this cloud connection", + Type: schema.TypeSet, }, - PICloudConnectionConnectionMode: { - Type: schema.TypeString, + Attr_VPCEnabled: { Computed: true, - Description: "Type of service the gateway is attached to", + Description: "Enable VPC for this cloud connection.", + Type: schema.TypeBool, }, }, }, + Type: schema.TypeList, }, }, } @@ -125,8 +130,8 @@ func dataSourceIBMPICloudConnectionsRead(ctx context.Context, d *schema.Resource return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) - client := st.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) + client := instance.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) cloudConnections, err := client.GetAll() if err != nil { @@ -137,16 +142,16 @@ func dataSourceIBMPICloudConnectionsRead(ctx context.Context, d *schema.Resource result := make([]map[string]interface{}, 0, len(cloudConnections.CloudConnections)) for _, cloudConnection := range cloudConnections.CloudConnections { cc := map[string]interface{}{ - PICloudConnectionId: *cloudConnection.CloudConnectionID, - PICloudConnectionName: *cloudConnection.Name, - PICloudConnectionGlobalRouting: *cloudConnection.GlobalRouting, - PICloudConnectionMetered: *cloudConnection.Metered, - PICloudConnectionIBMIPAddress: *cloudConnection.IbmIPAddress, - PICloudConnectionUserIPAddress: *cloudConnection.UserIPAddress, - PICloudConnectionStatus: *cloudConnection.LinkStatus, - PICloudConnectionPort: *cloudConnection.Port, - PICloudConnectionSpeed: *cloudConnection.Speed, - PICloudConnectionConnectionMode: cloudConnection.ConnectionMode, + Attr_CloudConnectionID: *cloudConnection.CloudConnectionID, + Attr_ConnectionMode: cloudConnection.ConnectionMode, + Attr_GlobalRouting: *cloudConnection.GlobalRouting, + Attr_IBMIPAddress: *cloudConnection.IbmIPAddress, + Attr_Metered: *cloudConnection.Metered, + Attr_Name: *cloudConnection.Name, + Attr_Port: *cloudConnection.Port, + Attr_Speed: *cloudConnection.Speed, + Attr_Status: *cloudConnection.LinkStatus, + Attr_UserIPAddress: *cloudConnection.UserIPAddress, } if cloudConnection.Networks != nil { @@ -156,23 +161,23 @@ func dataSourceIBMPICloudConnectionsRead(ctx context.Context, d *schema.Resource networks[i] = *ccNetwork.NetworkID } } - cc[PICloudConnectionNetworks] = networks + cc[Attr_Networks] = networks } if cloudConnection.Classic != nil { - cc[PICloudConnectionClassicEnabled] = cloudConnection.Classic.Enabled + cc[Attr_ClassicEnabled] = cloudConnection.Classic.Enabled if cloudConnection.Classic.Gre != nil { - cc[PICloudConnectionClassicGreDest] = cloudConnection.Classic.Gre.DestIPAddress - cc[PICloudConnectionClassicGreSource] = cloudConnection.Classic.Gre.SourceIPAddress + cc[Attr_GreDestinationAddress] = cloudConnection.Classic.Gre.DestIPAddress + cc[Attr_GreSourceAddress] = cloudConnection.Classic.Gre.SourceIPAddress } } if cloudConnection.Vpc != nil { - cc[PICloudConnectionVPCEnabled] = cloudConnection.Vpc.Enabled + cc[Attr_VPCEnabled] = cloudConnection.Vpc.Enabled if cloudConnection.Vpc.Vpcs != nil && len(cloudConnection.Vpc.Vpcs) > 0 { vpcCRNs := make([]string, len(cloudConnection.Vpc.Vpcs)) for i, vpc := range cloudConnection.Vpc.Vpcs { vpcCRNs[i] = *vpc.VpcID } - cc[PICloudConnectionVPCCRNs] = vpcCRNs + cc[Attr_VPCCRNs] = vpcCRNs } } @@ -181,7 +186,7 @@ func dataSourceIBMPICloudConnectionsRead(ctx context.Context, d *schema.Resource var genID, _ = uuid.GenerateUUID() d.SetId(genID) - d.Set(PICloudConnections, result) + d.Set(Attr_Connections, result) return nil } diff --git a/website/docs/d/pi_cloud_connection.html.markdown b/website/docs/d/pi_cloud_connection.html.markdown index ca42eb4117..c700064074 100644 --- a/website/docs/d/pi_cloud_connection.html.markdown +++ b/website/docs/d/pi_cloud_connection.html.markdown @@ -7,11 +7,9 @@ description: |- --- # ibm_pi_cloud_connection - Retrieve information about an existing IBM Cloud Power Virtual Server Cloud cloud connection. 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_cloud_connection" "example" { pi_cloud_connection_name = "test_cloud_connection" @@ -20,15 +18,12 @@ data "ibm_pi_cloud_connection" "example" { ``` **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: - +Example usage: ```terraform provider "ibm" { region = "lon" @@ -37,28 +32,26 @@ data "ibm_pi_cloud_connection" "example" { ``` ## Argument reference - Review the argument references that you can specify for your data source. - `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. - `pi_cloud_connection_name` - (Required, String) The cloud connection name to be used. ## Attribute reference - In addition to all argument reference list, you can access the following attribute references after your data source is created. -- `id` - (String) The unique identifier of the cloud connection. -- `classic_enabled` - (Bool) Is classic endpoint destination enabled? +- `classic_enabled` - (Bool) Enable classic endpoint destination. - `connection_mode` - (String) Type of service the gateway is attached to. -- `global_routing` - (String) Is global routing enabled for this cloud connection. -- `gre_destination_address` - (String) The GRE destination IP address. -- `gre_source_address` - (String) The GRE auto-assigned source IP address. +- `global_routing` - (String) Enable global routing for this cloud connection. +- `gre_destination_address` - (String) GRE destination IP address. +- `gre_source_address` - (String) GRE auto-assigned source IP address. +- `id` - (String) The unique identifier of the cloud connection. - `ibm_ip_address` - (String) The IBM IP address. -- `metered` - (String) Is metered enabled for this cloud connection. -- `networks` - (Set of String) Set of Networks attached to this cloud connection. +- `metered` - (String) Enable metering for this cloud connection. +- `networks` - (Set) Set of Networks attached to this cloud connection. - `port` - (String) Port. - `speed` - (Integer) Speed of the cloud connection (speed in megabits per second). - `status` - (String) Link status. - `user_ip_address` - (String) User IP address. -- `vpc_crns` - (Set of String) Set of VPCs attached to this cloud connection. -- `vpc_enabled` - (Bool) Is VPC enabled for this cloud connection? +- `vpc_crns` - (Set) Set of VPCs attached to this cloud connection. +- `vpc_enabled` - (Bool) Enable VPC for this cloud connection. diff --git a/website/docs/d/pi_cloud_connections.html.markdown b/website/docs/d/pi_cloud_connections.html.markdown index 8925fd81e6..67dfe0e0ef 100644 --- a/website/docs/d/pi_cloud_connections.html.markdown +++ b/website/docs/d/pi_cloud_connections.html.markdown @@ -7,11 +7,9 @@ description: |- --- # ibm_pi_cloud_connections - Retrieve information about all cloud connections 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_cloud_connections" "example" { pi_cloud_instance_id = "" @@ -19,15 +17,13 @@ data "ibm_pi_cloud_connections" "example" { ``` **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: - +Example usage: ```terraform provider "ibm" { region = "lon" @@ -36,32 +32,29 @@ data "ibm_pi_cloud_connections" "example" { ``` ## Argument reference - Review the argument references that you can specify for your data source. - `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. ## Attribute reference - In addition to all argument reference list, you can access the following attribute references after your data source is created. - `connections` - (List) List of all the Cloud Connections. Nested scheme for `connections`: - - - `classic_enabled` - (Bool) Is Classic endpoint destination enabled. + - `classic_enabled` - (Bool) Enable classic endpoint destination. - `cloud_connection_id` - (String) The unique identifier of the cloud connection. - - `global_routing` - (String) Is global routing enabled for this cloud connection. + - `connection_mode` - (String) Type of service the gateway is attached to. + - `global_routing` - (String) Enable global routing for this cloud connection. - `gre_destination_address` - (String) GRE destination IP address. - `gre_source_address` - (String) GRE auto-assigned source IP address. - `ibm_ip_address` - (String) IBM IP address. - - `metered` - (String) Is metered enabled for this cloud connection. + - `metered` - (String) Enable metering for this cloud connection. - `name` - (String) Name of the cloud connection. - - `networks` - (Set of String) Set of Networks attached to this cloud connection. + - `networks` - (Set) Set of Networks attached to this cloud connection. - `port` - (String) Port. - `speed` - (Integer) Speed of the cloud connection (speed in megabits per second). - `status` - (String) Link status. - `user_ip_address` - (String) User IP address. - - `vpc_crns` - (Set of String) Set of VPCs attached to this cloud connection. - - `vpc_enabled` - (Bool) Is VPC enabled for this cloud connection. - - `connection_mode` - (String) Type of service the gateway is attached to. + - `vpc_crns` - (Set) Set of VPCs attached to this cloud connection. + - `vpc_enabled` - (Bool) Enable VPC for this cloud connection. From 198fc8a23cb9d036e769e3b53e40da5c7ca63321 Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Thu, 28 Dec 2023 01:33:10 +0530 Subject: [PATCH 03/16] Catalog-refactor datacenter data source and documentation --- .../power/data_source_ibm_pi_datacenter.go | 42 +++++++++---------- .../data_source_ibm_pi_datacenter_test.go | 6 +-- .../power/data_source_ibm_pi_datacenters.go | 36 +++++++--------- .../data_source_ibm_pi_datacenters_test.go | 3 +- website/docs/d/pi_datacenter.html.markdown | 20 ++++----- website/docs/d/pi_datacenters.html.markdown | 23 ++++------ 6 files changed, 55 insertions(+), 75 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_datacenter.go b/ibm/service/power/data_source_ibm_pi_datacenter.go index 2404570273..1dd2643f27 100644 --- a/ibm/service/power/data_source_ibm_pi_datacenter.go +++ b/ibm/service/power/data_source_ibm_pi_datacenter.go @@ -15,54 +15,52 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) -const ( - DatacenterRegion = "region" - DatacenterType = "type" - DatacenterUrl = "url" -) - func DataSourceIBMPIDatacenter() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceIBMPIDatacenterRead, Schema: map[string]*schema.Schema{ + // Arguments Arg_DatacenterZone: { - Type: schema.TypeString, + Description: "Datacenter zone you want to retrieve.", Optional: true, + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, + + // Attributes Attr_DatacenterCapabilities: { - Type: schema.TypeMap, Computed: true, - Description: "Datacenter Capabilities", + Description: "Datacenter Capabilities.", Elem: &schema.Schema{ Type: schema.TypeBool, }, + Type: schema.TypeMap, }, Attr_DatacenterHref: { - Type: schema.TypeString, Computed: true, - Description: "Datacenter href", + Description: "Datacenter href.", + Type: schema.TypeString, }, Attr_DatacenterLocation: { - Type: schema.TypeMap, Computed: true, - Description: "Datacenter location", + Description: "Datacenter location.", + Type: schema.TypeMap, }, Attr_DatacenterStatus: { - Type: schema.TypeString, Computed: true, - Description: "Datacenter status", + Description: "Datacenter status, active,maintenance or down.", + Type: schema.TypeString, }, Attr_DatacenterType: { - Type: schema.TypeString, Computed: true, - Description: "Datacenter type", + Description: "Datacenter type, off-premises or on-premises.", + Type: schema.TypeString, }, }, } } + func dataSourceIBMPIDatacenterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - // session sess, err := meta.(conns.ClientSession).IBMPISession() if err != nil { return diag.FromErr(err) @@ -81,14 +79,14 @@ func dataSourceIBMPIDatacenterRead(ctx context.Context, d *schema.ResourceData, d.SetId(genID) d.Set(Attr_DatacenterCapabilities, dcData.Capabilities) dclocation := map[string]interface{}{ - DatacenterRegion: *dcData.Location.Region, - DatacenterType: *dcData.Location.Type, - DatacenterUrl: *dcData.Location.URL, + Attr_Region: *dcData.Location.Region, + Attr_Type: *dcData.Location.Type, + Attr_URL: *dcData.Location.URL, } + d.Set(Attr_DatacenterHref, dcData.Href) d.Set(Attr_DatacenterLocation, flex.Flatten(dclocation)) d.Set(Attr_DatacenterStatus, dcData.Status) d.Set(Attr_DatacenterType, dcData.Type) - d.Set(Attr_DatacenterHref, dcData.Href) return nil } diff --git a/ibm/service/power/data_source_ibm_pi_datacenter_test.go b/ibm/service/power/data_source_ibm_pi_datacenter_test.go index cc289ca32d..0a7490c750 100644 --- a/ibm/service/power/data_source_ibm_pi_datacenter_test.go +++ b/ibm/service/power/data_source_ibm_pi_datacenter_test.go @@ -4,7 +4,6 @@ package power_test import ( - "fmt" "testing" acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" @@ -27,9 +26,8 @@ func TestAccIBMPIDatacenterDataSourceBasic(t *testing.T) { } func testAccCheckIBMPIDatacenterDataSourceConfig() string { - return fmt.Sprintf(` + return ` data "ibm_pi_datacenter" "test" { pi_datacenter_zone = "dal12" - } - `) + }` } diff --git a/ibm/service/power/data_source_ibm_pi_datacenters.go b/ibm/service/power/data_source_ibm_pi_datacenters.go index 949ba4741a..08059004df 100644 --- a/ibm/service/power/data_source_ibm_pi_datacenters.go +++ b/ibm/service/power/data_source_ibm_pi_datacenters.go @@ -13,47 +13,44 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -const ( - Datacenters = "datacenters" -) - func DataSourceIBMPIDatacenters() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceIBMPIDatacentersRead, Schema: map[string]*schema.Schema{ - Datacenters: { - Type: schema.TypeList, - Computed: true, + // Attributes + Attr_Datacenters: { + Type: schema.TypeList, + Computed: true, + Description: "List of Datacenters", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - Attr_DatacenterCapabilities: { - Type: schema.TypeMap, Computed: true, Description: "Datacenter Capabilities", Elem: &schema.Schema{ Type: schema.TypeBool, }, + Type: schema.TypeMap, }, Attr_DatacenterHref: { - Type: schema.TypeString, Computed: true, Description: "Datacenter href", + Type: schema.TypeString, }, Attr_DatacenterLocation: { - Type: schema.TypeMap, Computed: true, Description: "Datacenter location", + Type: schema.TypeMap, }, Attr_DatacenterStatus: { - Type: schema.TypeString, Computed: true, Description: "Datacenter status", + Type: schema.TypeString, }, Attr_DatacenterType: { - Type: schema.TypeString, Computed: true, Description: "Datacenter type", + Type: schema.TypeString, }, }, }, @@ -61,8 +58,8 @@ func DataSourceIBMPIDatacenters() *schema.Resource { }, } } + func dataSourceIBMPIDatacentersRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - // session sess, err := meta.(conns.ClientSession).IBMPISession() if err != nil { return diag.FromErr(err) @@ -77,21 +74,20 @@ func dataSourceIBMPIDatacentersRead(ctx context.Context, d *schema.ResourceData, if datacenter != nil { dc := map[string]interface{}{ Attr_DatacenterCapabilities: datacenter.Capabilities, + Attr_DatacenterHref: datacenter.Href, Attr_DatacenterLocation: map[string]interface{}{ - DatacenterRegion: datacenter.Location.Region, - DatacenterType: datacenter.Location.Type, - DatacenterUrl: datacenter.Location.URL, + Attr_Region: datacenter.Location.Region, + Attr_Type: datacenter.Location.Type, + Attr_URL: datacenter.Location.URL, }, Attr_DatacenterStatus: datacenter.Status, Attr_DatacenterType: datacenter.Type, - Attr_DatacenterHref: datacenter.Href, } datacenters = append(datacenters, dc) } - } var clientgenU, _ = uuid.GenerateUUID() d.SetId(clientgenU) - d.Set(Datacenters, datacenters) + d.Set(Attr_Datacenters, datacenters) return nil } diff --git a/ibm/service/power/data_source_ibm_pi_datacenters_test.go b/ibm/service/power/data_source_ibm_pi_datacenters_test.go index 21271d7d54..83ba01a68e 100644 --- a/ibm/service/power/data_source_ibm_pi_datacenters_test.go +++ b/ibm/service/power/data_source_ibm_pi_datacenters_test.go @@ -4,7 +4,6 @@ package power_test import ( - "fmt" "testing" acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" @@ -27,5 +26,5 @@ func TestAccIBMPIDatacentersDataSourceBasic(t *testing.T) { } func testAccCheckIBMPIDatacentersDataSourceConfig() string { - return fmt.Sprintf(`data "ibm_pi_datacenters" "test" {}`) + return `data "ibm_pi_datacenters" "test" {}` } diff --git a/website/docs/d/pi_datacenter.html.markdown b/website/docs/d/pi_datacenter.html.markdown index 8076d2188f..9ce0e5a12a 100644 --- a/website/docs/d/pi_datacenter.html.markdown +++ b/website/docs/d/pi_datacenter.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_datacenter" @@ -8,26 +7,22 @@ description: |- --- # ibm_pi_datacenter - Retrieve information about a Power Systems Datacenter. ## Example usage - ```terraform data "ibm_pi_datacenter" "datacenter" { pi_datacenter_zone= "dal12" } ``` -## Notes - +**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" @@ -36,13 +31,11 @@ Example usage: ``` ## Argument reference - Review the argument references that you can specify for your data source. - `pi_datacenter_zone` - (Optional, String) Datacenter zone you want to retrieve. If no value is supplied, the `zone` configured within the IBM provider will be utilized. ## Attribute reference - In addition to all argument reference list, you can access the following attribute references after your data source is created. - `pi_datacenter_capabilities` - (Map) Datacenter Capabilities. Capabilities are `true` or `false`. @@ -50,11 +43,12 @@ In addition to all argument reference list, you can access the following attribu Some of `pi_datacenter_capabilities` are: - `cloud-connections`, `disaster-recovery-site`, `metrics`, `power-edge-router`, `power-vpn-connections` +- `pi_datacenter_href` - (String) Datacenter href. - `pi_datacenter_location` - (Map) Datacenter location. Nested schema for `pi_datacenter_location`: - - `region` - (String) The Datacenter location region zone. - - `type` - (String) The Datacenter location region type. - - `url`- (String) The Datacenter location region url. -- `pi_datacenter_status` - (String) The Datacenter status, `active`,`maintenance` or `down`. -- `pi_datacenter_type` - (String) The Datacenter type, `off-premises` or `on-premises`. + - `region` - (String) Datacenter location region zone. + - `type` - (String) Datacenter location region type. + - `url`- (String) Datacenter location region url. +- `pi_datacenter_status` - (String) Datacenter status, `active`,`maintenance` or `down`. +- `pi_datacenter_type` - (String) Datacenter type, `off-premises` or `on-premises`. diff --git a/website/docs/d/pi_datacenters.html.markdown b/website/docs/d/pi_datacenters.html.markdown index 812b0a75f3..6efbda05e9 100644 --- a/website/docs/d/pi_datacenters.html.markdown +++ b/website/docs/d/pi_datacenters.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_datacenters" @@ -8,26 +7,22 @@ description: |- --- # ibm_pi_datacenters - Retrieve information about Power Systems Datacenters. ## Example usage - The following example retrieves information about Power Systems Datacenters. ```terraform data "ibm_pi_datacenters" "datacenters" {} ``` -## Notes - +**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" @@ -36,22 +31,22 @@ Example usage: ``` ## Attribute reference - In addition to all argument reference list, you can access the following attribute references after your data source is created. -- `datacenters` - List of Datacenters +- `datacenters` - (List) List of Datacenters Nested schema for `datacenters` - `pi_datacenter_capabilities` - (Map) Datacenter Capabilities. Capabilities are `true` or `false`. Some of `pi_datacenter_capabilities` are: - `cloud-connections`, `disaster-recovery-site`, `metrics`, `power-edge-router`, `power-vpn-connections` - + + - `pi_datacenter_href` - (String) Datacenter href. - `pi_datacenter_location` - (Map) Datacenter location. Nested schema for `pi_datacenter_location`: - - `region` - (String) The Datacenter location region zone. - - `type` - (String) The Datacenter location region type. - - `url`- (String) The Datacenter location region url. - - `pi_datacenter_status` - (String) The Datacenter status, `active`,`maintenance` or `down`. - - `pi_datacenter_type` - (String) The Datacenter type, `off-premises` or `on-premises`. + - `region` - (String) Datacenter location region zone. + - `type` - (String) Datacenter location region type. + - `url`- (String) Datacenter location region url. + - `pi_datacenter_status` - (String) Datacenter status, `active`,`maintenance` or `down`. + - `pi_datacenter_type` - (String) Datacenter type, `off-premises` or `on-premises`. From 87cfb7c23930e8dc1911e32c1e290fc23f458215 Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Thu, 28 Dec 2023 15:21:34 +0530 Subject: [PATCH 04/16] Catalog-refactor dhcps data source and documentation --- ibm/service/power/data_source_ibm_pi_dhcp.go | 73 ++++++++----------- .../power/data_source_ibm_pi_dhcp_test.go | 1 - ibm/service/power/data_source_ibm_pi_dhcps.go | 63 +++++++--------- .../power/data_source_ibm_pi_dhcps_test.go | 1 - website/docs/d/pi_dhcp.html.markdown | 53 ++++++-------- website/docs/d/pi_dhcps.html.markdown | 49 ++++++------- 6 files changed, 101 insertions(+), 139 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_dhcp.go b/ibm/service/power/data_source_ibm_pi_dhcp.go index c6e716c020..9b5de8f4ef 100644 --- a/ibm/service/power/data_source_ibm_pi_dhcp.go +++ b/ibm/service/power/data_source_ibm_pi_dhcp.go @@ -6,15 +6,12 @@ package power import ( "context" "fmt" - "log" - st "github.com/IBM-Cloud/power-go-client/clients/instance" + "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" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) @@ -22,103 +19,95 @@ func DataSourceIBMPIDhcp() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceIBMPIDhcpRead, Schema: map[string]*schema.Schema{ - - // Required Arguments + // Arguments Arg_CloudInstanceID: { - Type: schema.TypeString, + Description: "The GUID of the service instance associated with an account.", Required: true, + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, Arg_DhcpID: { - Type: schema.TypeString, + Description: "ID of the DHCP Server.", Required: true, - Description: "The ID of the DHCP Server", + Type: schema.TypeString, }, // Attributes Attr_DhcpID: { - Type: schema.TypeString, Computed: true, - Description: "The ID of the DHCP Server", + Description: "ID of the DHCP Server.", + Type: schema.TypeString, }, - Attr_DhcpLeases: { - Type: schema.TypeList, + Attr_Leases: { Computed: true, - Description: "The list of DHCP Server PVM Instance leases", + Description: "List of DHCP Server PVM Instance leases.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ Attr_DhcpLeaseInstanceIP: { - Type: schema.TypeString, Computed: true, - Description: "The IP of the PVM Instance", + Description: "IP of the PVM Instance.", + Type: schema.TypeString, }, Attr_DhcpLeaseInstanceMac: { - Type: schema.TypeString, Computed: true, - Description: "The MAC Address of the PVM Instance", + Description: "MAC Address of the PVM Instance.", + Type: schema.TypeString, }, }, }, + Type: schema.TypeList, }, Attr_DhcpNetworkDeprecated: { - Type: schema.TypeString, Computed: true, - Description: "The ID of the DHCP Server private network (deprecated - replaced by network_id)", - }, - Attr_DhcpNetworkID: { + Description: "ID of the DHCP Server private network (deprecated - replaced by network_id)", Type: schema.TypeString, - Computed: true, - Description: "The ID of the DHCP Server private network", }, - Attr_DhcpNetworkName: { - Type: schema.TypeString, + Attr_NetworkID: { Computed: true, - Description: "The name of the DHCP Server private network", + Description: "ID of the DHCP Server private network.", + Type: schema.TypeString, }, - Attr_DhcpStatus: { + Attr_NetworkName: { + Computed: true, + Description: "Name of the DHCP Server private network.", Type: schema.TypeString, + }, + Attr_Status: { Computed: true, - Description: "The status of the DHCP Server", + Description: "Status of the DHCP Server.", + Type: schema.TypeString, }, }, } } func dataSourceIBMPIDhcpRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - - // session sess, err := meta.(conns.ClientSession).IBMPISession() if err != nil { return diag.FromErr(err) } - // arguments cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) dhcpID := d.Get(Arg_DhcpID).(string) - - // client - client := st.NewIBMPIDhcpClient(ctx, sess, cloudInstanceID) - - // get dhcp + client := instance.NewIBMPIDhcpClient(ctx, sess, cloudInstanceID) dhcpServer, err := client.Get(dhcpID) if err != nil { log.Printf("[DEBUG] get DHCP failed %v", err) return diag.FromErr(err) } - // set attributes d.SetId(fmt.Sprintf("%s/%s", cloudInstanceID, *dhcpServer.ID)) d.Set(Attr_DhcpID, *dhcpServer.ID) - d.Set(Attr_DhcpStatus, *dhcpServer.Status) + d.Set(Attr_Status, *dhcpServer.Status) if dhcpServer.Network != nil { dhcpNetwork := dhcpServer.Network if dhcpNetwork.ID != nil { d.Set(Attr_DhcpNetworkDeprecated, *dhcpNetwork.ID) - d.Set(Attr_DhcpNetworkID, *dhcpNetwork.ID) + d.Set(Attr_NetworkID, *dhcpNetwork.ID) } if dhcpNetwork.Name != nil { - d.Set(Attr_DhcpNetworkName, *dhcpNetwork.Name) + d.Set(Attr_NetworkName, *dhcpNetwork.Name) } } @@ -130,7 +119,7 @@ func dataSourceIBMPIDhcpRead(ctx context.Context, d *schema.ResourceData, meta i Attr_DhcpLeaseInstanceMac: *lease.InstanceMacAddress, } } - d.Set(Attr_DhcpLeases, leaseList) + d.Set(Attr_Leases, leaseList) } return nil diff --git a/ibm/service/power/data_source_ibm_pi_dhcp_test.go b/ibm/service/power/data_source_ibm_pi_dhcp_test.go index 8db9170a35..76eecbe42f 100644 --- a/ibm/service/power/data_source_ibm_pi_dhcp_test.go +++ b/ibm/service/power/data_source_ibm_pi_dhcp_test.go @@ -13,7 +13,6 @@ import ( ) func TestAccIBMPIDhcpDataSourceBasic(t *testing.T) { - resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, diff --git a/ibm/service/power/data_source_ibm_pi_dhcps.go b/ibm/service/power/data_source_ibm_pi_dhcps.go index a95f1935b5..ef52be36da 100644 --- a/ibm/service/power/data_source_ibm_pi_dhcps.go +++ b/ibm/service/power/data_source_ibm_pi_dhcps.go @@ -7,107 +7,94 @@ import ( "context" "log" - st "github.com/IBM-Cloud/power-go-client/clients/instance" + "github.com/IBM-Cloud/power-go-client/clients/instance" "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" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) -/* -Datasource to get the list of dhcp servers in a power instance -*/ - +// Datasource to list dhcp servers in a power instance func DataSourceIBMPIDhcps() *schema.Resource { - return &schema.Resource{ ReadContext: dataSourceIBMPIDhcpServersRead, Schema: map[string]*schema.Schema{ - - // Required Arguments + // Arguments Arg_CloudInstanceID: { - Type: schema.TypeString, + Description: "The GUID of the service instance associated with an account.", Required: true, + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, // Attributes Attr_DhcpServers: { - Type: schema.TypeList, Computed: true, - Description: "The list of all the DHCP Servers", + Description: "List of all the DHCP Servers.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ Attr_DhcpID: { - Type: schema.TypeString, Computed: true, - Description: "The ID of the DHCP Server", + Description: "ID of the DHCP Server.", + Type: schema.TypeString, }, Attr_DhcpNetworkDeprecated: { - Type: schema.TypeString, Computed: true, - Description: "The ID of the DHCP Server private network (deprecated - replaced by network_id)", - }, - Attr_DhcpNetworkID: { + Description: "ID of the DHCP Server private network (deprecated - replaced by network_id)", Type: schema.TypeString, - Computed: true, - Description: "The ID of the DHCP Server private network", }, - Attr_DhcpNetworkName: { - Type: schema.TypeString, + Attr_NetworkID: { Computed: true, - Description: "The name of the DHCP Server private network", + Description: "ID of the DHCP Server private network.", + Type: schema.TypeString, }, - Attr_DhcpStatus: { + Attr_NetworkName: { + Computed: true, + Description: "Name of the DHCP Server private network.", Type: schema.TypeString, + }, + Attr_Status: { Computed: true, - Description: "The status of the DHCP Server", + Description: "Status of the DHCP Server.", + Type: schema.TypeString, }, }, }, + Type: schema.TypeList, }, }, } } func dataSourceIBMPIDhcpServersRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - - // session and client sess, err := meta.(conns.ClientSession).IBMPISession() if err != nil { return diag.FromErr(err) } - // arguments cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) - - // client - client := st.NewIBMPIDhcpClient(ctx, sess, cloudInstanceID) - - // get all dhcp + client := instance.NewIBMPIDhcpClient(ctx, sess, cloudInstanceID) dhcpServers, err := client.GetAll() if err != nil { log.Printf("[DEBUG] get all DHCP failed %v", err) return diag.FromErr(err) } - // set attributes servers := make([]map[string]interface{}, 0, len(dhcpServers)) for _, dhcpServer := range dhcpServers { server := map[string]interface{}{ - Attr_DhcpID: *dhcpServer.ID, - Attr_DhcpStatus: *dhcpServer.Status, + Attr_DhcpID: *dhcpServer.ID, + Attr_Status: *dhcpServer.Status, } if dhcpServer.Network != nil { dhcpNetwork := dhcpServer.Network if dhcpNetwork.ID != nil { d.Set(Attr_DhcpNetworkDeprecated, *dhcpNetwork.ID) - d.Set(Attr_DhcpNetworkID, *dhcpNetwork.ID) + d.Set(Attr_NetworkID, *dhcpNetwork.ID) } if dhcpNetwork.Name != nil { - d.Set(Attr_DhcpNetworkName, *dhcpNetwork.Name) + d.Set(Attr_NetworkName, *dhcpNetwork.Name) } } servers = append(servers, server) diff --git a/ibm/service/power/data_source_ibm_pi_dhcps_test.go b/ibm/service/power/data_source_ibm_pi_dhcps_test.go index 84645bae3c..ec787992ea 100644 --- a/ibm/service/power/data_source_ibm_pi_dhcps_test.go +++ b/ibm/service/power/data_source_ibm_pi_dhcps_test.go @@ -13,7 +13,6 @@ import ( ) func TestAccIBMPIDhcpServersDataSourceBasic(t *testing.T) { - resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, diff --git a/website/docs/d/pi_dhcp.html.markdown b/website/docs/d/pi_dhcp.html.markdown index cf6f1221d5..89c3534cd0 100644 --- a/website/docs/d/pi_dhcp.html.markdown +++ b/website/docs/d/pi_dhcp.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_dhcp" @@ -8,11 +7,9 @@ description: |- --- # ibm_pi_dhcp - Retrieve information about a DHCP Server. For more information, 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_dhcp" "example" { pi_cloud_instance_id = "" @@ -20,37 +17,35 @@ data "ibm_pi_dhcp" "example" { } ``` +**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" + zone = "lon04" + } + ``` + ## Argument reference Review the argument references that you can specify for your data source. -- `pi_cloud_instance_id` - (Required, String) Cloud Instance ID of a PCloud Instance. -- `pi_dhcp_id` - (Required, String) The ID of the DHCP Server. +- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. +- `pi_dhcp_id` - (Required, String) ID of the DHCP Server. ## Attribute reference In addition to all argument reference list, you can access the following attribute references after your data source is created. -- `id` - (String) The ID of the DHCP Server. -- `leases` - (List) The list of DHCP Server PVM Instance leases. +- `dhcp_id` - (String) ID of the DHCP Server. +- `leases` - (List) List of DHCP Server PVM Instance leases. Nested scheme for `leases`: - - `instance_ip` - (String) The IP of the PVM Instance. - - `instance_mac` - (String) The MAC Address of the PVM Instance. -- `network` - (String) The ID of the DHCP Server private network (deprecated - replaced by `network_id`). -- `network_id`- (String) The ID of the DHCP Server private network. -- `network_name` - The name of the DHCP Server private network. -- `status` - (String) The status of the DHCP Server. - -**Note** - -* 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" - zone = "lon04" - } - ``` \ No newline at end of file + - `instance_ip` - (String) IP of the PVM Instance. + - `instance_mac` - (String) MAC Address of the PVM Instance. +- `network` - (String) ID of the DHCP Server private network (deprecated - replaced by `network_id`). +- `network_id`- (String) ID of the DHCP Server private network. +- `network_name` - (String) Name of the DHCP Server private network. +- `status` - (String) Status of the DHCP Server. diff --git a/website/docs/d/pi_dhcps.html.markdown b/website/docs/d/pi_dhcps.html.markdown index edc89f2dd5..eeb180a553 100644 --- a/website/docs/d/pi_dhcps.html.markdown +++ b/website/docs/d/pi_dhcps.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_dhcps" @@ -8,48 +7,42 @@ description: |- --- # ibm_pi_dhcps - Retrieve information about all DHCP Servers. For more information, 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_dhcps" "example" { pi_cloud_instance_id = "" } ``` -## Argument reference +**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" + zone = "lon04" + } + ``` + +## Argument reference Review the argument references that you can specify for your data source. -- `pi_cloud_instance_id` - (Required, String) Cloud Instance ID of a PCloud Instance. +- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. ## Attribute reference - In addition to all argument reference list, you can access the following attribute references after your data source is created. -- `servers` - (List) The list of all the DHCP Servers. +- `servers` - (List) List of all the DHCP Servers. Nested scheme for `servers`: - - `dhcp_id` - (String) The ID of the DHCP Server. - - `network` - (String) The ID of the DHCP Server private network (deprecated - replaced by `network_id`). - - `network_id`- (String) The ID of the DHCP Server private network. - - `network_name` - The name of the DHCP Server private network. - - `status` - (String) The status of the DHCP Server. - -**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" - zone = "lon04" - } - ``` \ No newline at end of file + - `dhcp_id` - (String) ID of the DHCP Server. + - `network` - (String) ID of the DHCP Server private network (deprecated - replaced by `network_id`). + - `network_id`- (String) ID of the DHCP Server private network. + - `network_name` - (String) Name of the DHCP Server private network. + - `status` - (String) Status of the DHCP Server. From d113b02d2bc58f79926c8e8cfd7e0f900e6f1a45 Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Thu, 28 Dec 2023 15:34:19 +0530 Subject: [PATCH 05/16] Catalog-refactor disaster recovery location data source and documentation --- ...ource_ibm_pi_disaster_recovery_location.go | 51 ++++++++++--------- ..._ibm_pi_disaster_recovery_location_test.go | 7 ++- ...urce_ibm_pi_disaster_recovery_locations.go | 47 ++++++++--------- ...ibm_pi_disaster_recovery_locations_test.go | 2 +- ...i_disaster_recovery_location.html.markdown | 20 ++++---- ..._disaster_recovery_locations.html.markdown | 18 +++---- 6 files changed, 74 insertions(+), 71 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_disaster_recovery_location.go b/ibm/service/power/data_source_ibm_pi_disaster_recovery_location.go index f7f2f3e85c..4c839ab37f 100644 --- a/ibm/service/power/data_source_ibm_pi_disaster_recovery_location.go +++ b/ibm/service/power/data_source_ibm_pi_disaster_recovery_location.go @@ -6,47 +6,50 @@ package power import ( "context" + "github.com/IBM-Cloud/power-go-client/clients/instance" + "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" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - - "github.com/IBM-Cloud/power-go-client/clients/instance" - "github.com/IBM-Cloud/power-go-client/helpers" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" ) func DataSourceIBMPIDisasterRecoveryLocation() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceIBMPIDisasterRecoveryLocation, 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 - PIDRLocation: { - Type: schema.TypeString, + // Attributes + Attr_Location: { Computed: true, - Description: "RegionZone of a site", + Description: "The region zone of a site.", + Type: schema.TypeString, }, - "replication_sites": { - Type: schema.TypeList, - Computed: true, + Attr_ReplicationSites: { + Computed: true, + Description: "List of replication sites.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "is_active": { - Type: schema.TypeBool, - Computed: true, + Attr_IsActive: { + Computed: true, + Description: "Indicates the location is active or not, true if location is active , otherwise it is false.", + Type: schema.TypeBool, }, - PIDRLocation: { - Type: schema.TypeString, - Computed: true, + Attr_Location: { + Computed: true, + Description: "The region zone of the location.", + Type: schema.TypeString, }, }, }, + Type: schema.TypeList, }, }, } @@ -58,7 +61,7 @@ func dataSourceIBMPIDisasterRecoveryLocation(ctx context.Context, d *schema.Reso return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) drClient := instance.NewIBMPIDisasterRecoveryLocationClient(ctx, sess, cloudInstanceID) drLocationSite, err := drClient.Get() if err != nil { @@ -69,8 +72,8 @@ func dataSourceIBMPIDisasterRecoveryLocation(ctx context.Context, d *schema.Reso for _, i := range drLocationSite.ReplicationSites { if i != nil { l := map[string]interface{}{ - "is_active": i.IsActive, - PIDRLocation: i.Location, + Attr_IsActive: i.IsActive, + Attr_Location: i.Location, } result = append(result, l) } @@ -78,8 +81,8 @@ func dataSourceIBMPIDisasterRecoveryLocation(ctx context.Context, d *schema.Reso var clientgenU, _ = uuid.GenerateUUID() d.SetId(clientgenU) - d.Set(PIDRLocation, drLocationSite.Location) - d.Set("replication_sites", result) + d.Set(Attr_Location, drLocationSite.Location) + d.Set(Attr_ReplicationSites, result) return nil } diff --git a/ibm/service/power/data_source_ibm_pi_disaster_recovery_location_test.go b/ibm/service/power/data_source_ibm_pi_disaster_recovery_location_test.go index 561a451c2a..ef7f68307e 100644 --- a/ibm/service/power/data_source_ibm_pi_disaster_recovery_location_test.go +++ b/ibm/service/power/data_source_ibm_pi_disaster_recovery_location_test.go @@ -30,8 +30,7 @@ func TestAccIBMPIDisasterRecoveryLocationDataSourceBasic(t *testing.T) { func testAccCheckIBMPIDisasterRecoveryLocationDataSourceConfig() string { return fmt.Sprintf(` -data "ibm_pi_disaster_recovery_location" "testacc_disaster_recovery_location" { - pi_cloud_instance_id = "%s" -}`, acc.Pi_cloud_instance_id) - + data "ibm_pi_disaster_recovery_location" "testacc_disaster_recovery_location" { + pi_cloud_instance_id = "%s" + }`, acc.Pi_cloud_instance_id) } diff --git a/ibm/service/power/data_source_ibm_pi_disaster_recovery_locations.go b/ibm/service/power/data_source_ibm_pi_disaster_recovery_locations.go index 49d77fe170..c838348000 100644 --- a/ibm/service/power/data_source_ibm_pi_disaster_recovery_locations.go +++ b/ibm/service/power/data_source_ibm_pi_disaster_recovery_locations.go @@ -6,45 +6,46 @@ package power import ( "context" + "github.com/IBM-Cloud/power-go-client/clients/instance" + "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" - - "github.com/IBM-Cloud/power-go-client/clients/instance" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" ) func DataSourceIBMPIDisasterRecoveryLocations() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceIBMPIDisasterRecoveryLocations, Schema: map[string]*schema.Schema{ - - // Computed Attributes - "disaster_recovery_locations": { + // Attributes + Attr_DisasterRecoveryLocations: { Type: schema.TypeList, Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - PIDRLocation: { - Type: schema.TypeString, + Attr_Location: { Computed: true, - Description: "RegionZone of a site", + Description: "The region zone of a site.", + Type: schema.TypeString, }, - "replication_sites": { - Type: schema.TypeList, - Computed: true, + Attr_ReplicationSites: { + Computed: true, + Description: "List of Replication Sites.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "is_active": { - Type: schema.TypeBool, - Computed: true, + Attr_IsActive: { + Computed: true, + Description: "Indicates the location is active or not, true if location is active, otherwise it is false.", + Type: schema.TypeBool, }, - PIDRLocation: { - Type: schema.TypeString, - Computed: true, + Attr_Location: { + Computed: true, + Description: "The region zone of the location.", + Type: schema.TypeString, }, }, }, + Type: schema.TypeList, }, }, }, @@ -72,15 +73,15 @@ func dataSourceIBMPIDisasterRecoveryLocations(ctx context.Context, d *schema.Res for _, j := range i.ReplicationSites { if j != nil { r := map[string]interface{}{ - "is_active": j.IsActive, - PIDRLocation: j.Location, + Attr_IsActive: j.IsActive, + Attr_Location: j.Location, } replicationSites = append(replicationSites, r) } } l := map[string]interface{}{ - "location": i.Location, - "replication_sites": replicationSites, + Attr_Location: i.Location, + Attr_ReplicationSites: replicationSites, } results = append(results, l) } @@ -88,7 +89,7 @@ func dataSourceIBMPIDisasterRecoveryLocations(ctx context.Context, d *schema.Res var clientgenU, _ = uuid.GenerateUUID() d.SetId(clientgenU) - d.Set("disaster_recovery_locations", results) + d.Set(Attr_DisasterRecoveryLocations, results) return nil } diff --git a/ibm/service/power/data_source_ibm_pi_disaster_recovery_locations_test.go b/ibm/service/power/data_source_ibm_pi_disaster_recovery_locations_test.go index 6320f451b3..49b3e3b47f 100644 --- a/ibm/service/power/data_source_ibm_pi_disaster_recovery_locations_test.go +++ b/ibm/service/power/data_source_ibm_pi_disaster_recovery_locations_test.go @@ -27,5 +27,5 @@ func TestAccIBMPIDisasterRecoveryLocationsDataSourceBasic(t *testing.T) { } func testAccCheckIBMPIDisasterRecoveryLocationsDataSourceConfig() string { - return "data \"ibm_pi_disaster_recovery_locations\" \"testacc_disaster_recovery_locations\" {}" + return `data "ibm_pi_disaster_recovery_locations" "testacc_disaster_recovery_locations" {}` } diff --git a/website/docs/d/pi_disaster_recovery_location.html.markdown b/website/docs/d/pi_disaster_recovery_location.html.markdown index 171b827268..300c4c1591 100644 --- a/website/docs/d/pi_disaster_recovery_location.html.markdown +++ b/website/docs/d/pi_disaster_recovery_location.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_disaster_recovery_location" @@ -18,20 +17,21 @@ data "ibm_pi_disaster_recovery_location" "ds_disaster_recovery_location" { pi_cloud_instance_id = "49fba6c9-23f8-40bc-9899-aca322ee7d5b" } ``` + **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` +- 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: +Example usage: ```terraform provider "ibm" { region = "lon" zone = "lon04" } ``` - + ## Argument reference Review the argument references that you can specify for your data source. @@ -41,8 +41,8 @@ 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. - `location` - (String) The region zone of a site. -- `replication_sites` - List of replication sites. +- `replication_sites` - (List) List of replication sites. Nested scheme for `replication_sites`: - - `is_active` - (Boolean) Indicates the location is active or not, `true` if location is active , otherwise it is `false`. - - `location` - (String) The region zone of the location. \ No newline at end of file + - `is_active` - (Bool) Indicates the location is active or not, `true` if location is active , otherwise it is `false`. + - `location` - (String) The region zone of the location. diff --git a/website/docs/d/pi_disaster_recovery_locations.html.markdown b/website/docs/d/pi_disaster_recovery_locations.html.markdown index 412e73a193..4cb52f6ea8 100644 --- a/website/docs/d/pi_disaster_recovery_locations.html.markdown +++ b/website/docs/d/pi_disaster_recovery_locations.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_disaster_recovery_locations" @@ -16,13 +15,14 @@ The following example retrieves information about the disaster recovery location ```terraform data "ibm_pi_disaster_recovery_locations" "ds_disaster_recovery_locations" {} ``` + **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` +- 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: +Example usage: ```terraform provider "ibm" { region = "lon" @@ -39,6 +39,6 @@ In addition to all argument reference list, you can access the following attribu - `location` - (String) The region zone of a site. - `replication_sites` - List of Replication Sites. - Nested scheme for `replication_sites`: - - `is_active` - (Boolean) Indicates the location is active or not, `true` if location is active, otherwise it is `false`. - - `location` - (String) The region zone of the location. \ No newline at end of file + Nested scheme for `replication_sites`: + - `is_active` - (Bool) Indicates the location is active or not, `true` if location is active, otherwise it is `false`. + - `location` - (String) The region zone of the location. From 422e5d0f55c103252773929c9c4b20eeb1121b52 Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Thu, 28 Dec 2023 15:39:38 +0530 Subject: [PATCH 06/16] Catalog-refactor image data source and documentation --- ibm/service/power/data_source_ibm_pi_image.go | 94 +++++++++--------- .../power/data_source_ibm_pi_image_test.go | 10 +- .../power/data_source_ibm_pi_images.go | 98 +++++++++---------- .../power/data_source_ibm_pi_images_test.go | 8 +- website/docs/d/pi_image.html.markdown | 17 ++-- website/docs/d/pi_images.html.markdown | 17 ++-- 6 files changed, 121 insertions(+), 123 deletions(-) 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. From 68d44be4b78f48ec1945c46361e37f3da8eac8bd Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Thu, 28 Dec 2023 15:45:20 +0530 Subject: [PATCH 07/16] Catalog-refactor instance data source and documentation --- .../power/data_source_ibm_pi_instance.go | 373 ++++++++++-------- .../power/data_source_ibm_pi_instance_test.go | 11 +- .../power/data_source_ibm_pi_instances.go | 304 +++++++------- .../data_source_ibm_pi_instances_test.go | 9 +- website/docs/d/pi_instance.html.markdown | 38 +- website/docs/d/pi_instances.html.markdown | 39 +- 6 files changed, 403 insertions(+), 371 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_instance.go b/ibm/service/power/data_source_ibm_pi_instance.go index 354cfe951b..9c52d410bf 100644 --- a/ibm/service/power/data_source_ibm_pi_instance.go +++ b/ibm/service/power/data_source_ibm_pi_instance.go @@ -6,260 +6,285 @@ package power import ( "context" + "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" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - - "github.com/IBM-Cloud/power-go-client/clients/instance" - "github.com/IBM-Cloud/power-go-client/helpers" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" ) func DataSourceIBMPIInstance() *schema.Resource { - return &schema.Resource{ ReadContext: dataSourceIBMPIInstancesRead, Schema: map[string]*schema.Schema{ - - helpers.PIInstanceName: { - Type: schema.TypeString, + // Arguments + Arg_CloudInstanceID: { + Description: "The GUID of the service instance associated with an account.", Required: true, - Description: "Server Name to be used for pvminstances", + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - - helpers.PICloudInstanceId: { - Type: schema.TypeString, + Arg_InstanceName: { + Description: "The unique identifier or name of the instance.", Required: true, + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - // Computed Attributes - "volumes": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "memory": { - Type: schema.TypeFloat, - Computed: true, - }, - "processors": { - Type: schema.TypeFloat, - Computed: true, - }, - "health_status": { - Type: schema.TypeString, - Computed: true, - }, - "addresses": { - Type: schema.TypeList, - Computed: true, - Deprecated: "This field is deprecated, use networks instead", + // Attributes + Attr_Addresses: { + Computed: true, + Description: "The address associated with this instance.", + Deprecated: "This field is deprecated, use networks instead", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "ip": { - Type: schema.TypeString, - Computed: true, + Attr_ExternalIP: { + Computed: true, + Description: "The external IP address of the instance.", + Type: schema.TypeString, }, - "macaddress": { - Type: schema.TypeString, - Computed: true, + Attr_IP: { + Computed: true, + Description: "The IP address of the instance.", + Type: schema.TypeString, }, - "network_id": { - Type: schema.TypeString, - Computed: true, + Attr_MacAddress: { + Computed: true, + Description: "The MAC address of the instance.", + Type: schema.TypeString, }, - "network_name": { - Type: schema.TypeString, - Computed: true, + Attr_NetworkID: { + Computed: true, + Description: "The network ID of the instance.", + Type: schema.TypeString, }, - "type": { - Type: schema.TypeString, - Computed: true, + Attr_NetworkName: { + Computed: true, + Description: "The network name of the instance.", + Type: schema.TypeString, }, - "external_ip": { - Type: schema.TypeString, - Computed: true, + Attr_Type: { + Computed: true, + Description: "The type of the network.", + Type: schema.TypeString, }, }, }, + Type: schema.TypeList, + }, + Attr_DeploymentType: { + Computed: true, + Description: "The custom deployment type.", + Type: schema.TypeString, + }, + Attr_HealthStatus: { + Computed: true, + Description: "The health of the instance.", + Type: schema.TypeString, + }, + Attr_LicenseRepositoryCapacity: { + Computed: true, + Description: "The VTL license repository capacity TB value.", + Type: schema.TypeInt, }, - "networks": { - Type: schema.TypeList, - Computed: true, + Attr_MaxMem: { + Computed: true, + Description: "The maximum amount of memory that can be allocated to the instance without shutting down or rebooting the LPAR.", + Type: schema.TypeFloat, + }, + Attr_MaxProc: { + Computed: true, + Description: "The maximum number of processors that can be allocated to the instance without shutting down or rebooting the LPAR.", + Type: schema.TypeFloat, + }, + Attr_MaxVirtualCores: { + Computed: true, + Description: "The maximum number of virtual cores that can be assigned without rebooting the instance.", + Type: schema.TypeInt, + }, + Attr_Memory: { + Computed: true, + Description: "The amount of memory that is allocated to the instance.", + Type: schema.TypeFloat, + }, + Attr_MinMem: { + Computed: true, + Description: "The minimum amount of memory that must be allocated to the instance.", + Type: schema.TypeFloat, + }, + Attr_MinProc: { + Computed: true, + Description: "The minimum number of processors that must be allocated to the instance.", + Type: schema.TypeFloat, + }, + Attr_MinVirtualCores: { + Computed: true, + Description: "The minimum number of virtual cores that can be assigned without rebooting the instance.", + Type: schema.TypeInt, + }, + Attr_Networks: { + Computed: true, + Description: "List of networks associated with this instance.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "ip": { - Type: schema.TypeString, - Computed: true, + Attr_ExternalIP: { + Computed: true, + Description: "The external IP address of the instance.", + Type: schema.TypeString, }, - "macaddress": { - Type: schema.TypeString, - Computed: true, + Attr_IP: { + Computed: true, + Description: "The IP address of the instance.", + Type: schema.TypeString, }, - "network_id": { - Type: schema.TypeString, - Computed: true, + Attr_MacAddress: { + Computed: true, + Description: "The MAC address of the instance.", + Type: schema.TypeString, }, - "network_name": { - Type: schema.TypeString, - Computed: true, + Attr_NetworkID: { + Computed: true, + Description: "The network ID of the instance.", + Type: schema.TypeString, }, - "type": { - Type: schema.TypeString, - Computed: true, + Attr_NetworkName: { + Computed: true, + Description: "The network name of the instance.", + Type: schema.TypeString, }, - "external_ip": { - Type: schema.TypeString, - Computed: true, + Attr_Type: { + Computed: true, + Description: "The type of the network.", + Type: schema.TypeString, }, - /*"version": { - Type: schema.TypeFloat, - Computed: true, - },*/ }, }, + Type: schema.TypeList, }, - "proctype": { - Type: schema.TypeString, - Computed: true, + Attr_PinPolicy: { + Computed: true, + Description: "The pinning policy of the instance.", + Type: schema.TypeString, }, - - "status": { - Type: schema.TypeString, - Computed: true, - }, - - "minproc": { - Type: schema.TypeFloat, - Computed: true, + Attr_PlacementGroupID: { + Computed: true, + Description: "The ID of the placement group that the instance is a member.", + Type: schema.TypeString, }, - "minmem": { - Type: schema.TypeFloat, - Computed: true, + Attr_Processors: { + Computed: true, + Description: "The number of processors that are allocated to the instance.", + Type: schema.TypeFloat, }, - "maxproc": { - Type: schema.TypeFloat, - Computed: true, + Attr_ProcType: { + Computed: true, + Description: "The procurement type of the instance. Supported values are shared and dedicated.", + Type: schema.TypeString, }, - "maxmem": { - Type: schema.TypeFloat, - Computed: true, + Attr_SharedProcessorPool: { + Computed: true, + Description: "The name of the shared processor pool for the instance.", + Type: schema.TypeString, }, - "pin_policy": { - Type: schema.TypeString, - Computed: true, + Attr_SharedProcessorPoolID: { + Computed: true, + Description: "The ID of the shared processor pool for the instance.", + Type: schema.TypeString, }, - "virtual_cores_assigned": { - Type: schema.TypeInt, - Computed: true, + Attr_Status: { + Computed: true, + Description: "The status of the instance.", + Type: schema.TypeString, }, - "max_virtual_cores": { - Type: schema.TypeInt, - Computed: true, + Attr_StoragePool: { + Computed: true, + Description: "The storage Pool where server is deployed.", + Type: schema.TypeString, }, - "min_virtual_cores": { - Type: schema.TypeInt, - Computed: true, + Attr_StoragePoolAffinity: { + Computed: true, + Description: "Indicates if all volumes attached to the server must reside in the same storage pool.", + Type: schema.TypeBool, }, - "storage_type": { - Type: schema.TypeString, - Computed: true, + Attr_StorageType: { + Computed: true, + Description: "The storage type where server is deployed.", + Type: schema.TypeString, }, - "storage_pool": { - Type: schema.TypeString, - Computed: true, + Attr_VirtualCoresAssigned: { + Computed: true, + Description: "The virtual cores that are assigned to the instance.", + Type: schema.TypeInt, }, - "storage_pool_affinity": { - Type: schema.TypeBool, - Computed: true, - }, - "license_repository_capacity": { - Type: schema.TypeInt, - Computed: true, - }, - PIPlacementGroupID: { - Type: schema.TypeString, - Computed: true, - }, - "deployment_type": { - Type: schema.TypeString, - Computed: true, - }, - Attr_PIInstanceSharedProcessorPool: { - Type: schema.TypeString, - Computed: true, - }, - Attr_PIInstanceSharedProcessorPoolID: { - Type: schema.TypeString, - Computed: true, + Attr_Volumes: { + Computed: true, + Description: "List of volume IDs that are attached to the instance.", + Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeList, }, }, } } func dataSourceIBMPIInstancesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - sess, err := meta.(conns.ClientSession).IBMPISession() - if err != nil { return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) powerC := instance.NewIBMPIInstanceClient(ctx, sess, cloudInstanceID) - powervmdata, err := powerC.Get(d.Get(helpers.PIInstanceName).(string)) - + powervmdata, err := powerC.Get(d.Get(Arg_InstanceName).(string)) if err != nil { return diag.FromErr(err) } pvminstanceid := *powervmdata.PvmInstanceID d.SetId(pvminstanceid) - d.Set("memory", powervmdata.Memory) - d.Set("processors", powervmdata.Processors) - d.Set("status", powervmdata.Status) - d.Set("proctype", powervmdata.ProcType) - d.Set("volumes", powervmdata.VolumeIDs) - d.Set("minproc", powervmdata.Minproc) - d.Set("minmem", powervmdata.Minmem) - d.Set("maxproc", powervmdata.Maxproc) - d.Set("maxmem", powervmdata.Maxmem) - d.Set("pin_policy", powervmdata.PinPolicy) - d.Set("virtual_cores_assigned", powervmdata.VirtualCores.Assigned) - d.Set("max_virtual_cores", powervmdata.VirtualCores.Max) - d.Set("min_virtual_cores", powervmdata.VirtualCores.Min) - d.Set("storage_type", powervmdata.StorageType) - d.Set("storage_pool", powervmdata.StoragePool) - d.Set("storage_pool_affinity", powervmdata.StoragePoolAffinity) - d.Set("license_repository_capacity", powervmdata.LicenseRepositoryCapacity) - d.Set("networks", flattenPvmInstanceNetworks(powervmdata.Networks)) - d.Set("deployment_type", powervmdata.DeploymentType) + d.Set(Attr_DeploymentType, powervmdata.DeploymentType) + d.Set(Attr_LicenseRepositoryCapacity, powervmdata.LicenseRepositoryCapacity) + d.Set(Attr_MaxMem, powervmdata.Maxmem) + d.Set(Attr_MaxProc, powervmdata.Maxproc) + d.Set(Attr_MaxVirtualCores, powervmdata.VirtualCores.Max) + d.Set(Attr_Memory, powervmdata.Memory) + d.Set(Attr_MinMem, powervmdata.Minmem) + d.Set(Attr_MinProc, powervmdata.Minproc) + d.Set(Attr_MinVirtualCores, powervmdata.VirtualCores.Min) + d.Set(Attr_Networks, flattenPvmInstanceNetworks(powervmdata.Networks)) + d.Set(Attr_PinPolicy, powervmdata.PinPolicy) + d.Set(Attr_Processors, powervmdata.Processors) + d.Set(Attr_ProcType, powervmdata.ProcType) + d.Set(Attr_SharedProcessorPool, powervmdata.SharedProcessorPool) + d.Set(Attr_SharedProcessorPoolID, powervmdata.SharedProcessorPoolID) + d.Set(Attr_Status, powervmdata.Status) + d.Set(Attr_StorageType, powervmdata.StorageType) + d.Set(Attr_StoragePool, powervmdata.StoragePool) + d.Set(Attr_StoragePoolAffinity, powervmdata.StoragePoolAffinity) + d.Set(Attr_Volumes, powervmdata.VolumeIDs) + d.Set(Attr_VirtualCoresAssigned, powervmdata.VirtualCores.Assigned) + if *powervmdata.PlacementGroup != "none" { - d.Set(PIPlacementGroupID, powervmdata.PlacementGroup) + d.Set(Attr_PlacementGroupID, powervmdata.PlacementGroup) } - d.Set(Attr_PIInstanceSharedProcessorPool, powervmdata.SharedProcessorPool) - d.Set(Attr_PIInstanceSharedProcessorPoolID, powervmdata.SharedProcessorPoolID) if powervmdata.Addresses != nil { pvmaddress := make([]map[string]interface{}, len(powervmdata.Addresses)) for i, pvmip := range powervmdata.Addresses { p := make(map[string]interface{}) - p["ip"] = pvmip.IPAddress - p["network_name"] = pvmip.NetworkName - p["network_id"] = pvmip.NetworkID - p["macaddress"] = pvmip.MacAddress - p["type"] = pvmip.Type - p["external_ip"] = pvmip.ExternalIP + p[Attr_ExternalIP] = pvmip.ExternalIP + p[Attr_IP] = pvmip.IPAddress + p[Attr_MacAddress] = pvmip.MacAddress + p[Attr_NetworkID] = pvmip.NetworkID + p[Attr_NetworkName] = pvmip.NetworkName + p[Attr_Type] = pvmip.Type pvmaddress[i] = p } - d.Set("addresses", pvmaddress) + d.Set(Attr_Addresses, pvmaddress) } if powervmdata.Health != nil { - d.Set("health_status", powervmdata.Health.Status) + d.Set(Attr_HealthStatus, powervmdata.Health.Status) } return nil diff --git a/ibm/service/power/data_source_ibm_pi_instance_test.go b/ibm/service/power/data_source_ibm_pi_instance_test.go index daf3590105..1c352395a6 100644 --- a/ibm/service/power/data_source_ibm_pi_instance_test.go +++ b/ibm/service/power/data_source_ibm_pi_instance_test.go @@ -13,7 +13,6 @@ import ( ) func TestAccIBMPIInstanceDataSource_basic(t *testing.T) { - resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -30,10 +29,8 @@ func TestAccIBMPIInstanceDataSource_basic(t *testing.T) { func testAccCheckIBMPIInstanceDataSourceConfig() string { return fmt.Sprintf(` - -data "ibm_pi_instance" "testacc_ds_instance" { - pi_instance_name="%s" - pi_cloud_instance_id = "%s" -}`, acc.Pi_instance_name, acc.Pi_cloud_instance_id) - + data "ibm_pi_instance" "testacc_ds_instance" { + pi_instance_name="%s" + pi_cloud_instance_id = "%s" + }`, acc.Pi_instance_name, acc.Pi_cloud_instance_id) } diff --git a/ibm/service/power/data_source_ibm_pi_instances.go b/ibm/service/power/data_source_ibm_pi_instances.go index a266d9c110..8e1c1f16ba 100644 --- a/ibm/service/power/data_source_ibm_pi_instances.go +++ b/ibm/service/power/data_source_ibm_pi_instances.go @@ -6,160 +6,182 @@ package power import ( "context" + "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" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - - "github.com/IBM-Cloud/power-go-client/clients/instance" - "github.com/IBM-Cloud/power-go-client/helpers" - "github.com/IBM-Cloud/power-go-client/power/models" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" ) func DataSourceIBMPIInstances() *schema.Resource { - return &schema.Resource{ ReadContext: dataSourceIBMPIInstancesAllRead, 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 - "pvm_instances": { - Type: schema.TypeList, - Computed: true, + // Attributes + Attr_PVMInstances: { + Computed: true, + Description: "List of power virtual server instances for the respective cloud instance.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "pvm_instance_id": { - Type: schema.TypeString, - Computed: true, - }, - "memory": { - Type: schema.TypeFloat, - Computed: true, - }, - "processors": { - Type: schema.TypeFloat, - Computed: true, - }, - "health_status": { - Type: schema.TypeString, - Computed: true, - }, - "networks": { - Type: schema.TypeList, + Attr_HealthStatus: { + Computed: true, + Description: "The health of the instance.", + Type: schema.TypeString, + }, + Attr_LicenseRepositoryCapacity: { + Computed: true, + Description: "The VTL license repository capacity TB value.", + Type: schema.TypeInt, + }, + Attr_MaxMem: { + Computed: true, + Description: "The maximum amount of memory that can be allocated to the instance without shutting down or rebooting the LPAR.", + Type: schema.TypeFloat, + }, + Attr_MaxProc: { + Computed: true, + Description: "The maximum number of processors that can be allocated to the instance without shutting down or rebooting the LPAR.", + Type: schema.TypeFloat, + }, + Attr_MaxVirtualCores: { + Computed: true, + Description: "The maximum number of virtual cores that can be assigned without rebooting the instance.", + Type: schema.TypeInt, + }, + Attr_Memory: { + Computed: true, + Description: "The amount of memory that is allocated to the instance.", + Type: schema.TypeFloat, + }, + Attr_MinMem: { + Computed: true, + Description: "The minimum amount of memory that must be allocated to the instance.", + Type: schema.TypeFloat, + }, + Attr_MinProc: { + Computed: true, + Description: "The minimum number of processors that must be allocated to the instance. ", + Type: schema.TypeFloat, + }, + Attr_MinVirtualCores: { + Computed: true, + Description: "The minimum number of virtual cores that can be assigned without rebooting the instance.", + Type: schema.TypeInt, + }, + Attr_Networks: { Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "ip": { - Type: schema.TypeString, - Computed: true, + Attr_ExternalIP: { + Computed: true, + Description: "The external IP address of the instance.", + Type: schema.TypeString, }, - "macaddress": { - Type: schema.TypeString, - Computed: true, + Attr_IP: { + Computed: true, + Description: "The IP address of the instance.", + Type: schema.TypeString, }, - "network_id": { - Type: schema.TypeString, - Computed: true, + Attr_MacAddress: { + Computed: true, + Description: "The MAC address of the instance.", + Type: schema.TypeString, }, - "network_name": { - Type: schema.TypeString, - Computed: true, + Attr_NetworkID: { + Computed: true, + Description: "The network ID of the instance.", + Type: schema.TypeString, }, - "type": { - Type: schema.TypeString, - Computed: true, + Attr_NetworkName: { + Computed: true, + Description: "The network name of the instance.", + Type: schema.TypeString, }, - "external_ip": { - Type: schema.TypeString, - Computed: true, + Attr_Type: { + Computed: true, + Description: "The type of the network.", + Type: schema.TypeString, }, }, }, - }, - "proctype": { - Type: schema.TypeString, - Computed: true, - }, - - "status": { - Type: schema.TypeString, - Computed: true, - }, - - "minproc": { - Type: schema.TypeFloat, - Computed: true, - }, - "minmem": { - Type: schema.TypeFloat, - Computed: true, - }, - "maxproc": { - Type: schema.TypeFloat, - Computed: true, - }, - "maxmem": { - Type: schema.TypeFloat, - Computed: true, - }, - "pin_policy": { - Type: schema.TypeString, - Computed: true, - }, - "virtual_cores_assigned": { - Type: schema.TypeInt, - Computed: true, - }, - "max_virtual_cores": { - Type: schema.TypeInt, - Computed: true, - }, - "min_virtual_cores": { - Type: schema.TypeInt, - Computed: true, - }, - "storage_type": { - Type: schema.TypeString, - Computed: true, - }, - "storage_pool": { - Type: schema.TypeString, - Computed: true, - }, - "storage_pool_affinity": { - Type: schema.TypeBool, - Computed: true, - }, - "license_repository_capacity": { - Type: schema.TypeInt, - Computed: true, - }, - PIPlacementGroupID: { - Type: schema.TypeString, - Computed: true, + Type: schema.TypeList, + }, + Attr_PinPolicy: { + Computed: true, + Description: "The pinning policy of the instance.", + Type: schema.TypeString, + }, + Attr_PlacementGroupID: { + Computed: true, + Description: "The ID of the placement group that the instance is a member.", + Type: schema.TypeString, + }, + Attr_Processors: { + Computed: true, + Description: "The number of processors that are allocated to the instance.", + Type: schema.TypeFloat, + }, + Attr_ProcType: { + Computed: true, + Description: "The procurement type of the instance. Supported values are shared and dedicated.", + Type: schema.TypeString, + }, + Attr_PVMInstanceID: { + Computed: true, + Description: "The unique identifier of the instance.", + Type: schema.TypeString, + }, + Attr_Status: { + Computed: true, + Description: "The status of the instance.", + Type: schema.TypeString, + }, + Attr_StoragePool: { + Computed: true, + Description: "The storage Pool where server is deployed.", + Type: schema.TypeString, + }, + Attr_StoragePoolAffinity: { + Computed: true, + Description: "Indicates if all volumes attached to the server must reside in the same storage pool.", + Type: schema.TypeBool, + }, + Attr_StorageType: { + Computed: true, + Description: "The storage type where server is deployed.", + Type: schema.TypeString, + }, + Attr_VirtualCoresAssigned: { + Computed: true, + Description: "The virtual cores that are assigned to the instance.", + Type: schema.TypeInt, }, }, }, + Type: schema.TypeList, }, }, } } func dataSourceIBMPIInstancesAllRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - sess, err := meta.(conns.ClientSession).IBMPISession() if err != nil { return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) powerC := instance.NewIBMPIInstanceClient(ctx, sess, cloudInstanceID) powervmdata, err := powerC.GetAll() @@ -170,7 +192,7 @@ func dataSourceIBMPIInstancesAllRead(ctx context.Context, d *schema.ResourceData var clientgenU, _ = uuid.GenerateUUID() d.SetId(clientgenU) - d.Set("pvm_instances", flattenPvmInstances(powervmdata.PvmInstances)) + d.Set(Attr_PVMInstances, flattenPvmInstances(powervmdata.PvmInstances)) return nil } @@ -178,51 +200,49 @@ func dataSourceIBMPIInstancesAllRead(ctx context.Context, d *schema.ResourceData func flattenPvmInstances(list []*models.PVMInstanceReference) []map[string]interface{} { result := make([]map[string]interface{}, 0, len(list)) for _, i := range list { - l := map[string]interface{}{ - "pvm_instance_id": *i.PvmInstanceID, - "memory": *i.Memory, - "processors": *i.Processors, - "proctype": *i.ProcType, - "status": *i.Status, - "minproc": i.Minproc, - "minmem": i.Minmem, - "maxproc": i.Maxproc, - "maxmem": i.Maxmem, - "pin_policy": i.PinPolicy, - "virtual_cores_assigned": i.VirtualCores.Assigned, - "max_virtual_cores": i.VirtualCores.Max, - "min_virtual_cores": i.VirtualCores.Min, - "storage_type": i.StorageType, - "storage_pool": i.StoragePool, - "storage_pool_affinity": i.StoragePoolAffinity, - "license_repository_capacity": i.LicenseRepositoryCapacity, - PIPlacementGroupID: i.PlacementGroup, - "networks": flattenPvmInstanceNetworks(i.Networks), + Attr_LicenseRepositoryCapacity: i.LicenseRepositoryCapacity, + Attr_MaxMem: i.Maxmem, + Attr_MaxProc: i.Maxproc, + Attr_MaxVirtualCores: i.VirtualCores.Max, + Attr_Memory: *i.Memory, + Attr_MinMem: i.Minmem, + Attr_MinProc: i.Minproc, + Attr_MinVirtualCores: i.VirtualCores.Min, + Attr_Networks: flattenPvmInstanceNetworks(i.Networks), + Attr_PinPolicy: i.PinPolicy, + Attr_PlacementGroupID: i.PlacementGroup, + Attr_Processors: *i.Processors, + Attr_ProcType: *i.ProcType, + Attr_PVMInstanceID: *i.PvmInstanceID, + Attr_Status: *i.Status, + Attr_StoragePool: i.StoragePool, + Attr_StoragePoolAffinity: i.StoragePoolAffinity, + Attr_StorageType: i.StorageType, + Attr_VirtualCoresAssigned: i.VirtualCores.Assigned, } if i.Health != nil { - l["health_status"] = i.Health.Status + l[Attr_HealthStatus] = i.Health.Status } result = append(result, l) - } return result } +// TODO: REVIEW THIS ONE func flattenPvmInstanceNetworks(list []*models.PVMInstanceNetwork) (networks []map[string]interface{}) { if list != nil { networks = make([]map[string]interface{}, len(list)) for i, pvmip := range list { - p := make(map[string]interface{}) - p["ip"] = pvmip.IPAddress - p["network_name"] = pvmip.NetworkName - p["network_id"] = pvmip.NetworkID - p["macaddress"] = pvmip.MacAddress - p["type"] = pvmip.Type - p["external_ip"] = pvmip.ExternalIP + p[Attr_ExternalIP] = pvmip.ExternalIP + p[Attr_IP] = pvmip.IPAddress + p[Attr_MacAddress] = pvmip.MacAddress + p[Attr_NetworkID] = pvmip.NetworkID + p[Attr_NetworkName] = pvmip.NetworkName + p[Attr_Type] = pvmip.Type networks[i] = p } return networks diff --git a/ibm/service/power/data_source_ibm_pi_instances_test.go b/ibm/service/power/data_source_ibm_pi_instances_test.go index 7dc19f1e19..f707581ef2 100644 --- a/ibm/service/power/data_source_ibm_pi_instances_test.go +++ b/ibm/service/power/data_source_ibm_pi_instances_test.go @@ -13,7 +13,6 @@ import ( ) func TestAccIBMPIInstancesDataSource_basic(t *testing.T) { - resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -30,9 +29,7 @@ func TestAccIBMPIInstancesDataSource_basic(t *testing.T) { func testAccCheckIBMPIInstancesDataSourceConfig() string { return fmt.Sprintf(` - - data "ibm_pi_instances" "testacc_ds_instance" { - pi_cloud_instance_id = "%s" - }`, acc.Pi_cloud_instance_id) - + data "ibm_pi_instances" "testacc_ds_instance" { + pi_cloud_instance_id = "%s" + }`, acc.Pi_cloud_instance_id) } diff --git a/website/docs/d/pi_instance.html.markdown b/website/docs/d/pi_instance.html.markdown index 75fecd8d53..c3c7c1ad4c 100644 --- a/website/docs/d/pi_instance.html.markdown +++ b/website/docs/d/pi_instance.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_instance" @@ -11,7 +10,6 @@ description: |- Retrieve information about a Power Systems Virtual Server instance. For more information, about Power Virtual Server instance, 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_instance" "ds_instance" { pi_instance_name = "terraform-test-instance" @@ -20,26 +18,24 @@ data "ibm_pi_instance" "ds_instance" { ``` **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: +- 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" zone = "lon04" } ``` - ## Argument reference Review the argument references that you can specify for your data source. - `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. -- `pi_instance_name` - (Required, String) The name of the instance. +- `pi_instance_name` - (Required, String) The unique identifier or name of the instance. ## Attribute reference In addition to all argument reference list, you can access the following attribute references after your data source is created. @@ -47,8 +43,8 @@ In addition to all argument reference list, you can access the following attribu - `addresses` - (Deprecated, List of objects) - The address associated with this instance. Nested scheme for `addresses`: - - `ip` - (String) The IP address of the instance. - `external_ip` - (String) The external IP address of the instance. + - `ip` - (String) The IP address of the instance. - `macaddress` - (String) The MAC address of the instance. - `network_id` - (String) The network ID of the instance. - `network_name` - (String) The network name of the instance. @@ -56,23 +52,25 @@ In addition to all argument reference list, you can access the following attribu - `deployment_type` - (String) The custom deployment type. - `health_status` - (String) The health of the instance. - `id` - (String) The unique identifier of the instance. -- `license_repository_capacity` - The VTL license repository capacity TB value. Only available with VTL instances. -- `memory` - (Float) The amount of memory that is allocated to the instance. -- `minproc`- (Float) The minimum number of processors that must be allocated to the instance. +- `license_repository_capacity` - (Integer) The VTL license repository capacity TB value. Only available with VTL instances. +- `maxmem`- (Float) The maximum amount of memory that can be allocated to the instance without shutting down or rebooting the `LPAR`. - `maxproc`- (Float) The maximum number of processors that can be allocated to the instance without shutting down or rebooting the `LPAR`. -- `max_virtual_cores` - (Integer) The maximum value that you increase without a reboot. +- `max_virtual_cores` - (Integer) The maximum number of virtual cores that can be assigned without rebooting the instance. +- `memory` - (Float) The amount of memory that is allocated to the instance. - `minmem`- (Float) The minimum amount of memory that must be allocated to the instance. -- `maxmem`- (Float) The maximum amount of memory that can be allocated to the instance without shutting down or rebooting the `LPAR`. -- `min_virtual_cores` - (Integer) The minimum cores assigned to an instance. -- `networks` - List of objects - The network associated with this instance. +- `minproc`- (Float) The minimum number of processors that must be allocated to the instance. +- `min_virtual_cores` - (Integer) The minimum number of virtual cores that can be assigned without rebooting the instance. +- `networks` - (List) List of networks associated with this instance. Nested scheme for `networks`: - - `ip` - (String) The IP address of the instance. - `external_ip` - (String) The external IP address of the instance. + - `ip` - (String) The IP address of the instance. - `macaddress` - (String) The MAC address of the instance. - `network_id` - (String) The network ID of the instance. - `network_name` - (String) The network name of the instance. - `type` - (String) The type of the network. + +- `pin_policy` - (String) The pinning policy of the instance. - `placement_group_id`- (String) The ID of the placement group that the instance is a member. - `processors` - (Float) The number of processors that are allocated to the instance. - `proctype` - (String) The procurement type of the instance. Supported values are `shared` and `dedicated`. @@ -83,4 +81,4 @@ In addition to all argument reference list, you can access the following attribu - `storage_pool_affinity` - (Bool) Indicates if all volumes attached to the server must reside in the same storage pool. - `storage_type` - (String) The storage type where server is deployed. - `virtual_cores_assigned` - (Integer) The virtual cores that are assigned to the instance. -- `volumes` - (List of strings) The list of volume IDs that are attached to the instance. +- `volumes` - (List) List of volume IDs that are attached to the instance. diff --git a/website/docs/d/pi_instances.html.markdown b/website/docs/d/pi_instances.html.markdown index ccd79cee46..e0a856b173 100644 --- a/website/docs/d/pi_instances.html.markdown +++ b/website/docs/d/pi_instances.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_instances" @@ -11,7 +10,6 @@ description: |- Retrieve information about all Power Systems Virtual Server instances for the given cloud instance. For more information, about Power Virtual Server instances, 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_instances" "ds_instance" { pi_cloud_instance_id = "49fba6c9-23f8-40bc-9899-aca322ee7d5b" @@ -19,20 +17,18 @@ data "ibm_pi_instances" "ds_instance" { ``` **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: +- 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" zone = "lon04" } ``` - ## Argument reference Review the argument references that you can specify for your data source. @@ -42,7 +38,7 @@ 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. -- `pvm_instances` - List of power virtual server instances for respective cloud instance. +- `pvm_instances` - (List) List of power virtual server instances for the respective cloud instance. Nested scheme for `pvm_instances`: - `health_status` - (String) The health of the instance. @@ -50,26 +46,25 @@ In addition to all argument reference list, you can access the following attribu - `memory` - (Float) The amount of memory that is allocated to the instance. - `minproc`- (Float) The minimum number of processors that must be allocated to the instance. - `maxproc`- (Float) The maximum number of processors that can be allocated to the instance without shutting down or rebooting the `LPAR`. - - `max_virtual_cores` - (Integer) The maximum value that you increase without a reboot. + - `max_virtual_cores` - (Integer) The maximum number of virtual cores that can be assigned without rebooting the instance. - `minmem`- (Float) The minimum amount of memory that must be allocated to the instance. - `maxmem`- (Float) The maximum amount of memory that can be allocated to the instance without shutting down or rebooting the `LPAR`. - - `min_virtual_cores` - (Integer) The minimum cores assigned to an instance. - - `networks` - List of objects - The network associated with this instance. + - `min_virtual_cores` - (Integer) The minimum number of virtual cores that can be assigned without rebooting the instance. + - `networks` - (List) List of networks associated with this instance. - Nested scheme for `networks`: - - `ip` - (String) The IP address of the instance. - - `external_ip` - (String) The external IP address of the instance. - - `macaddress` - (String) The MAC address of the instance. - - `network_id` - (String) The network ID of the instance. - - `network_name` - (String) The network name of the instance. - - `type` - (String) The type of the network. + Nested scheme for `networks`: + - `external_ip` - (String) The external IP address of the instance. + - `ip` - (String) The IP address of the instance. + - `macaddress` - (String) The MAC address of the instance. + - `network_id` - (String) The network ID of the instance. + - `network_name` - (String) The network name of the instance. + - `type` - (String) The type of the network. + - `pin_policy` - (String) The pinning policy of the instance. - `placement_group_id`- (String) The ID of the placement group that the instance is a member. - `processors` - (Float) The number of processors that are allocated to the instance. - `proctype` - (String) The procurement type of the instance. Supported values are `shared` and `dedicated`. - `pvm_instance_id` - (String) The unique identifier of the instance. - - `shared_processor_pool`- (String) The name of the shared processor pool for the instance. - - `shared_processor_pool_id` - (String) The ID of the shared processor pool for the instance. - `status` - (String) The status of the instance. - `storage_pool` - (String) The storage Pool where server is deployed. - `storage_pool_affinity` - (Bool) Indicates if all volumes attached to the server must reside in the same storage pool. From fdd61e0e9500a35a52f9e9adf9614157d91766d6 Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Thu, 28 Dec 2023 18:41:25 +0530 Subject: [PATCH 08/16] Catalog-refactor instance console-ip-volumes data source and documentation --- ...ource_ibm_pi_instance_console_languages.go | 57 ++++---- ..._ibm_pi_instance_console_languages_test.go | 8 +- .../power/data_source_ibm_pi_instance_ip.go | 80 +++++------ .../data_source_ibm_pi_instance_ip_test.go | 11 +- .../data_source_ibm_pi_instance_volumes.go | 124 ++++++++++-------- ...ata_source_ibm_pi_instance_volumes_test.go | 9 +- .../docs/d/pi_console_languages.html.markdown | 15 +-- website/docs/d/pi_instance_ip.html.markdown | 16 +-- .../docs/d/pi_instance_volumes.html.markdown | 22 ++-- 9 files changed, 169 insertions(+), 173 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_instance_console_languages.go b/ibm/service/power/data_source_ibm_pi_instance_console_languages.go index e5cb5b344d..d34dad28fb 100644 --- a/ibm/service/power/data_source_ibm_pi_instance_console_languages.go +++ b/ibm/service/power/data_source_ibm_pi_instance_console_languages.go @@ -6,59 +6,52 @@ 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/go-uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) -const ( - ConsoleLanguages = "console_languages" - ConsoleLanguageCode = "code" - ConsoleLanguageDesc = "language" -) - -/* -Datasource to get the list of available console languages for an instance -*/ +// Datasource to list available console languages for an instance func DataSourceIBMPIInstanceConsoleLanguages() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceIBMPIInstanceConsoleLanguagesRead, 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, }, - helpers.PIInstanceName: { - Type: schema.TypeString, + Arg_InstanceName: { + Description: "The unique identifier or name of the instance.", Required: true, - Description: "The unique identifier or name of the instance", + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - // Computed Attributes - ConsoleLanguages: { - Type: schema.TypeList, - Computed: true, + // Attributes + Attr_ConsoleLanguages: { + Computed: true, + Description: "List of all the Console Languages.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - ConsoleLanguageCode: { - Type: schema.TypeString, + Attr_Code: { Computed: true, - Description: "language code", - }, - ConsoleLanguageDesc: { + Description: "Language code.", Type: schema.TypeString, + }, + Attr_Language: { Computed: true, - Description: "language description", + Description: "Language description.", + Type: schema.TypeString, }, }, }, + Type: schema.TypeList, }, }, } @@ -70,8 +63,8 @@ func dataSourceIBMPIInstanceConsoleLanguagesRead(ctx context.Context, d *schema. return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) - instanceName := d.Get(helpers.PIInstanceName).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) + instanceName := d.Get(Arg_InstanceName).(string) client := instance.NewIBMPIInstanceClient(ctx, sess, cloudInstanceID) languages, err := client.GetConsoleLanguages(instanceName) @@ -86,12 +79,12 @@ func dataSourceIBMPIInstanceConsoleLanguagesRead(ctx context.Context, d *schema. result := make([]map[string]interface{}, 0, len(languages.ConsoleLanguages)) for _, language := range languages.ConsoleLanguages { l := map[string]interface{}{ - ConsoleLanguageCode: *language.Code, - ConsoleLanguageDesc: language.Language, + Attr_Code: *language.Code, + Attr_Language: language.Language, } result = append(result, l) } - d.Set(ConsoleLanguages, result) + d.Set(Attr_ConsoleLanguages, result) } return nil diff --git a/ibm/service/power/data_source_ibm_pi_instance_console_languages_test.go b/ibm/service/power/data_source_ibm_pi_instance_console_languages_test.go index acadb056e0..9d52aa963f 100644 --- a/ibm/service/power/data_source_ibm_pi_instance_console_languages_test.go +++ b/ibm/service/power/data_source_ibm_pi_instance_console_languages_test.go @@ -30,8 +30,8 @@ func TestAccIBMPIInstanceConsoleLanguages(t *testing.T) { func testAccCheckIBMPIInstanceConsoleLanguagesConfig() string { return fmt.Sprintf(` - data "ibm_pi_console_languages" "example" { - pi_cloud_instance_id = "%s" - pi_instance_name = "%s" - }`, acc.Pi_cloud_instance_id, acc.Pi_instance_name) + data "ibm_pi_console_languages" "example" { + pi_cloud_instance_id = "%s" + pi_instance_name = "%s" + }`, acc.Pi_cloud_instance_id, acc.Pi_instance_name) } diff --git a/ibm/service/power/data_source_ibm_pi_instance_ip.go b/ibm/service/power/data_source_ibm_pi_instance_ip.go index 4d57021d36..60cac39d42 100644 --- a/ibm/service/power/data_source_ibm_pi_instance_ip.go +++ b/ibm/service/power/data_source_ibm_pi_instance_ip.go @@ -10,7 +10,6 @@ import ( "strconv" "github.com/IBM-Cloud/power-go-client/clients/instance" - "github.com/IBM-Cloud/power-go-client/helpers" "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" @@ -18,51 +17,59 @@ import ( ) func DataSourceIBMPIInstanceIP() *schema.Resource { - return &schema.Resource{ ReadContext: dataSourceIBMPIInstancesIPRead, Schema: map[string]*schema.Schema{ - helpers.PIInstanceName: { - Type: schema.TypeString, + // Arguments + Arg_CloudInstanceID: { + Description: "The GUID of the service instance associated with an account.", Required: true, - Description: "Server Name to be used for pvminstances", + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - helpers.PICloudInstanceId: { - Type: schema.TypeString, + Arg_InstanceName: { + Description: "The unique identifier or name of the instance.", Required: true, + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - helpers.PINetworkName: { + Arg_NetworkName: { + Description: "The subnet that the instance belongs to.", Type: schema.TypeString, Required: true, ValidateFunc: validation.NoZeroValues, }, - // Computed attributes - "ip": { - Type: schema.TypeString, - Computed: true, + // Attributes + Attr_ExternalIP: { + Computed: true, + Description: "The external IP of the network that is attached to this instance.", + Type: schema.TypeString, }, - "ipoctet": { - Type: schema.TypeString, - Computed: true, + Attr_IP: { + Computed: true, + Description: "The IP address that is attached to this instance from the subnet.", + Type: schema.TypeString, }, - "macaddress": { - Type: schema.TypeString, - Computed: true, + Attr_IPOctet: { + Computed: true, + Description: "The IP octet of the network that is attached to this instance.", + Type: schema.TypeString, }, - "network_id": { - Type: schema.TypeString, - Computed: true, + Attr_MacAddress: { + Computed: true, + Description: "The MAC address of the network that is attached to this instance.", + Type: schema.TypeString, }, - "type": { - Type: schema.TypeString, - Computed: true, + Attr_NetworkID: { + Computed: true, + Description: "ID of the network.", + Type: schema.TypeString, }, - "external_ip": { - Type: schema.TypeString, - Computed: true, + Attr_Type: { + Computed: true, + Description: "The type of the network that is attached to this instance.", + Type: schema.TypeString, }, }, } @@ -74,11 +81,11 @@ func dataSourceIBMPIInstancesIPRead(ctx context.Context, d *schema.ResourceData, return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) - networkName := d.Get(helpers.PINetworkName).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) + networkName := d.Get(Arg_NetworkName).(string) powerC := instance.NewIBMPIInstanceClient(ctx, sess, cloudInstanceID) - powervmdata, err := powerC.Get(d.Get(helpers.PIInstanceName).(string)) + powervmdata, err := powerC.Get(d.Get(Arg_InstanceName).(string)) if err != nil { return diag.FromErr(err) } @@ -87,17 +94,16 @@ func dataSourceIBMPIInstancesIPRead(ctx context.Context, d *schema.ResourceData, if network.NetworkName == networkName { log.Printf("Printing the ip %s", network.IPAddress) d.SetId(network.NetworkID) - d.Set("ip", network.IPAddress) - d.Set("network_id", network.NetworkID) - d.Set("macaddress", network.MacAddress) - d.Set("external_ip", network.ExternalIP) - d.Set("type", network.Type) + d.Set(Attr_ExternalIP, network.ExternalIP) + d.Set(Attr_IP, network.IPAddress) + d.Set(Attr_MacAddress, network.MacAddress) + d.Set(Attr_NetworkID, network.NetworkID) + d.Set(Attr_Type, network.Type) IPObject := net.ParseIP(network.IPAddress).To4() if len(IPObject) > 0 { - d.Set("ipoctet", strconv.Itoa(int(IPObject[3]))) + d.Set(Attr_IPOctet, strconv.Itoa(int(IPObject[3]))) } - return nil } } diff --git a/ibm/service/power/data_source_ibm_pi_instance_ip_test.go b/ibm/service/power/data_source_ibm_pi_instance_ip_test.go index 36362776a8..b8963ee639 100644 --- a/ibm/service/power/data_source_ibm_pi_instance_ip_test.go +++ b/ibm/service/power/data_source_ibm_pi_instance_ip_test.go @@ -29,10 +29,9 @@ func TestAccIBMPIInstanceIPDataSource_basic(t *testing.T) { func testAccCheckIBMPIInstanceIPDataSourceConfig() string { return fmt.Sprintf(` - data "ibm_pi_instance_ip" "testacc_ds_instance_ip" { - pi_network_name = "%[1]s" - pi_instance_name = "%[2]s" - pi_cloud_instance_id = "%[3]s" - } - `, acc.Pi_network_name, acc.Pi_instance_name, acc.Pi_cloud_instance_id) + data "ibm_pi_instance_ip" "testacc_ds_instance_ip" { + pi_network_name = "%[1]s" + pi_instance_name = "%[2]s" + pi_cloud_instance_id = "%[3]s" + }`, acc.Pi_network_name, acc.Pi_instance_name, acc.Pi_cloud_instance_id) } diff --git a/ibm/service/power/data_source_ibm_pi_instance_volumes.go b/ibm/service/power/data_source_ibm_pi_instance_volumes.go index 611ef5cf62..0bd9b2a09e 100644 --- a/ibm/service/power/data_source_ibm_pi_instance_volumes.go +++ b/ibm/service/power/data_source_ibm_pi_instance_volumes.go @@ -6,82 +6,92 @@ 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" - - "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) func DataSourceIBMPIInstanceVolumes() *schema.Resource { - return &schema.Resource{ ReadContext: dataSourceIBMPIInstanceVolumesRead, Schema: map[string]*schema.Schema{ - helpers.PIInstanceName: { - Type: schema.TypeString, + // Arguments + Arg_CloudInstanceID: { + Description: "The GUID of the service instance associated with an account.", Required: true, - Description: "Instance Name to be used for pvminstances", + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - helpers.PICloudInstanceId: { - Type: schema.TypeString, + Arg_InstanceName: { + Description: "The unique identifier or name of the instance.", Required: true, + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - //Computed Attributes - "boot_volume_id": { - Type: schema.TypeString, - Computed: true, + // Attribute + Attr_BootVolumeID: { + Computed: true, + Description: "The unique identifier of the boot volume.", + Type: schema.TypeString, }, - "instance_volumes": { - Type: schema.TypeList, - Computed: true, + Attr_InstanceVolumes: { + Computed: true, + Description: "List of volumes attached to instance.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "id": { - Type: schema.TypeString, - Computed: true, + Attr_Bootable: { + Computed: true, + Description: "Indicates if the volume is boot capable.", + Type: schema.TypeBool, }, - "size": { - Type: schema.TypeFloat, - Computed: true, + Attr_Href: { + Computed: true, + Description: "The hyper link of the volume.", + Type: schema.TypeString, }, - "href": { - Type: schema.TypeString, - Computed: true, + Attr_ID: { + Computed: true, + Description: "The unique identifier of the volume.", + Type: schema.TypeString, }, - "name": { - Type: schema.TypeString, - Computed: true, + Attr_Name: { + Computed: true, + Description: "The name of the volume.", + Type: schema.TypeString, }, - "state": { - Type: schema.TypeString, - Computed: true, + Attr_Pool: { + Computed: true, + Description: "Volume pool, name of storage pool where the volume is located.", + Type: schema.TypeString, }, - "type": { - Type: schema.TypeString, - Computed: true, + Attr_Shareable: { + Computed: true, + Description: "Indicates if the volume is shareable between VMs.", + Type: schema.TypeBool, }, - "pool": { - Type: schema.TypeString, - Computed: true, + Attr_Size: { + Computed: true, + Description: "The size of this volume in gigabytes.", + Type: schema.TypeFloat, }, - "shareable": { - Type: schema.TypeBool, - Computed: true, + Attr_State: { + Computed: true, + Description: "The state of the volume.", + Type: schema.TypeString, }, - "bootable": { - Type: schema.TypeBool, - Computed: true, + Attr_Type: { + Computed: true, + Description: "The disk type that is used for this volume.", + Type: schema.TypeString, }, }, }, + Type: schema.TypeList, }, }, } @@ -93,38 +103,36 @@ func dataSourceIBMPIInstanceVolumesRead(ctx context.Context, d *schema.ResourceD return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) volumeC := instance.NewIBMPIVolumeClient(ctx, sess, cloudInstanceID) - volumedata, err := volumeC.GetAllInstanceVolumes(d.Get(helpers.PIInstanceName).(string)) + volumedata, err := volumeC.GetAllInstanceVolumes(d.Get(Arg_InstanceName).(string)) if err != nil { return diag.FromErr(err) } var clientgenU, _ = uuid.GenerateUUID() d.SetId(clientgenU) - d.Set("boot_volume_id", *volumedata.Volumes[0].VolumeID) - d.Set("instance_volumes", flattenVolumesInstances(volumedata.Volumes)) + d.Set(Attr_BootVolumeID, *volumedata.Volumes[0].VolumeID) + d.Set(Attr_InstanceVolumes, flattenVolumesInstances(volumedata.Volumes)) return nil - } func flattenVolumesInstances(list []*models.VolumeReference) []map[string]interface{} { result := make([]map[string]interface{}, 0, len(list)) for _, i := range list { l := map[string]interface{}{ - "id": *i.VolumeID, - "state": *i.State, - "href": *i.Href, - "name": *i.Name, - "size": *i.Size, - "type": *i.DiskType, - "pool": i.VolumePool, - "shareable": *i.Shareable, - "bootable": *i.Bootable, + Attr_Bootable: *i.Bootable, + Attr_Href: *i.Href, + Attr_ID: *i.VolumeID, + Attr_Name: *i.Name, + Attr_Pool: i.VolumePool, + Attr_Shareable: *i.Shareable, + Attr_Size: *i.Size, + Attr_State: *i.State, + Attr_Type: *i.DiskType, } - result = append(result, l) } return result diff --git a/ibm/service/power/data_source_ibm_pi_instance_volumes_test.go b/ibm/service/power/data_source_ibm_pi_instance_volumes_test.go index 211c17b9e7..10543c5a66 100644 --- a/ibm/service/power/data_source_ibm_pi_instance_volumes_test.go +++ b/ibm/service/power/data_source_ibm_pi_instance_volumes_test.go @@ -31,9 +31,8 @@ func TestAccIBMPIVolumesDataSource_basic(t *testing.T) { func testAccCheckIBMPIVolumesDataSourceConfig(name string) string { return fmt.Sprintf(` -data "ibm_pi_instance_volumes" "testacc_ds_volumes" { - pi_instance_name = "%s" - pi_cloud_instance_id = "%s" -}`, acc.Pi_instance_name, acc.Pi_cloud_instance_id) - + data "ibm_pi_instance_volumes" "testacc_ds_volumes" { + pi_instance_name = "%s" + pi_cloud_instance_id = "%s" + }`, acc.Pi_instance_name, acc.Pi_cloud_instance_id) } diff --git a/website/docs/d/pi_console_languages.html.markdown b/website/docs/d/pi_console_languages.html.markdown index d5f7f36afd..e679fedd62 100644 --- a/website/docs/d/pi_console_languages.html.markdown +++ b/website/docs/d/pi_console_languages.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_console_languages" @@ -8,11 +7,9 @@ description: |- --- # ibm_pi_console_languages - Retrieve information about all the available Console Languages for an Instance. For more information, 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_console_languages" "example" { pi_cloud_instance_id = "" @@ -21,14 +18,12 @@ data "ibm_pi_console_languages" "example" { ``` **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` +- 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" @@ -37,14 +32,12 @@ Example usage: ``` ## Argument reference - Review the argument references that you can specify for your data source. - `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. - `pi_instance_name` - (Required, String) The unique identifier or name of the instance. ## Attribute reference - In addition to all argument reference list, you can access the following attribute references after your data source is created. - `console_languages` - (List) List of all the Console Languages. diff --git a/website/docs/d/pi_instance_ip.html.markdown b/website/docs/d/pi_instance_ip.html.markdown index 541891d09c..8f1942cc83 100644 --- a/website/docs/d/pi_instance_ip.html.markdown +++ b/website/docs/d/pi_instance_ip.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_instance_ip" @@ -11,7 +10,6 @@ description: |- Retrieve information about a Power Systems Virtual Server instance IP address. For more information, about Power Systems Virtual Server instance IP address, see [configuring and adding a private network subnet](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-configuring-subnet). ## Example usage - ```terraform data "ibm_pi_instance_ip" "ds_instance_ip" { pi_instance_name = "terraform-test-instance" @@ -19,12 +17,14 @@ data "ibm_pi_instance_ip" "ds_instance_ip" { pi_cloud_instance_id = "49fba6c9-23f8-40bc-9899-aca322ee7d5b" } ``` + **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: +- 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" @@ -36,7 +36,7 @@ data "ibm_pi_instance_ip" "ds_instance_ip" { Review the argument references that you can specify for your data source. - `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. -- `pi_instance_name` - (Required, String) The name of the instance. +- `pi_instance_name` - (Required, String) The unique identifier or name of the instance. - `pi_network_name` - (Required, String) The subnet that the instance belongs to. diff --git a/website/docs/d/pi_instance_volumes.html.markdown b/website/docs/d/pi_instance_volumes.html.markdown index 1fc2583b2b..10e9f81722 100644 --- a/website/docs/d/pi_instance_volumes.html.markdown +++ b/website/docs/d/pi_instance_volumes.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_instance_volumes" @@ -8,26 +7,25 @@ description: |- --- # ibm_pi_instance_volumes -Retrieves information about a persistent storage volume that is mounted to a Power Systems Virtual Server instance. For more information, about power instance volume, see [snapshotting, cloning, and restoring](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-volume-snapshot-clone). +Retrieves information about the persistent storage volumes that are mounted to a Power Systems Virtual Server instance. For more information, about power instance volume, see [snapshotting, cloning, and restoring](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-volume-snapshot-clone). ## Example usage -The following example retrieves information about the `volume_1` volume that is mounted to the Power Systems Virtual Server instance with the ID. +The following example retrieves information about the volumes attached to the `terraform-test-instance` instance. ```terraform data "ibm_pi_instance_volumes" "ds_volumes" { - pi_instance_name = "volume_1" + pi_instance_name = "terraform-test-instance" pi_cloud_instance_id = "49fba6c9-23f8-40bc-9899-aca322ee7d5b" } ``` **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: +- 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" @@ -39,13 +37,13 @@ data "ibm_pi_instance_volumes" "ds_volumes" { Review the argument references that you can specify for your data source. - `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. -- `pi_volume_name` - (Required, String) The name of the volume for which you want to retrieve detailed information. +- `pi_instance_name` - (Required, String) The unique identifier or name of the instance. ## Attribute reference In addition to all argument reference list, you can access the following attribute references after your data source is created. - `boot_volume_id` - (String) The unique identifier of the boot volume. -- `instance_volumes` - List of volumes - List of volumes attached to instance. +- `instance_volumes` - (List) List of volumes attached to instance. Nested scheme for `instance_volumes`: - `bootable`- (Bool) Indicates if the volume is boot capable. From 68947d5a8daa90273983b68538b4feb191ff20de Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Thu, 28 Dec 2023 18:48:44 +0530 Subject: [PATCH 09/16] Catalog-refactor ssh keys data source and documentation --- ibm/service/power/data_source_ibm_pi_key.go | 52 +++++++------------ .../power/data_source_ibm_pi_key_test.go | 10 ++-- ibm/service/power/data_source_ibm_pi_keys.go | 39 ++++++-------- .../power/data_source_ibm_pi_keys_test.go | 3 +- website/docs/d/pi_key.html.markdown | 40 +++++++------- website/docs/d/pi_keys.html.markdown | 38 ++++++-------- 6 files changed, 75 insertions(+), 107 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_key.go b/ibm/service/power/data_source_ibm_pi_key.go index 70ab96ba7c..b7f928828f 100644 --- a/ibm/service/power/data_source_ibm_pi_key.go +++ b/ibm/service/power/data_source_ibm_pi_key.go @@ -6,79 +6,65 @@ package power import ( "context" - "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" - "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/IBM-Cloud/power-go-client/helpers" "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" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) func DataSourceIBMPIKey() *schema.Resource { - return &schema.Resource{ ReadContext: dataSourceIBMPIKeyRead, Schema: map[string]*schema.Schema{ - // Arguments - Arg_KeyName: { - Type: schema.TypeString, + Arg_CloudInstanceID: { + Description: "The GUID of the service instance associated with an account.", Required: true, - Description: "SSH key name for a pcloud tenant", + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - Arg_CloudInstanceID: { - Type: schema.TypeString, + Arg_KeyName: { Required: true, + Description: "User defined name for the SSH key.", ValidateFunc: validation.NoZeroValues, + Type: schema.TypeString, }, // Attributes - Attr_KeyCreationDate: { - Type: schema.TypeString, + Attr_CreationDate: { Computed: true, - Description: "Date of sshkey creation", - }, - Attr_Key: { + Description: "Date of SSH Key creation.", Type: schema.TypeString, - Sensitive: true, - Computed: true, - Description: "SSH RSA key", }, - "sshkey": { - Type: schema.TypeString, - Sensitive: true, - Computed: true, - Deprecated: "This field is deprecated, use ssh_key instead", + Attr_SSHKey: { + Computed: true, + Description: "SSH RSA key.", + Sensitive: true, + Type: schema.TypeString, }, }, } } func dataSourceIBMPIKeyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - - // session sess, err := meta.(conns.ClientSession).IBMPISession() if err != nil { return diag.FromErr(err) } - // arguments - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) - // get key sshkeyC := instance.NewIBMPIKeyClient(ctx, sess, cloudInstanceID) sshkeydata, err := sshkeyC.Get(d.Get(helpers.PIKeyName).(string)) if err != nil { return diag.FromErr(err) } - // set attributes d.SetId(*sshkeydata.Name) - d.Set(Attr_KeyCreationDate, sshkeydata.CreationDate.String()) - d.Set(Attr_Key, sshkeydata.SSHKey) - d.Set("sshkey", sshkeydata.SSHKey) // TODO: deprecated, to remove + d.Set(Attr_CreationDate, sshkeydata.CreationDate.String()) + d.Set(Attr_SSHKey, sshkeydata.SSHKey) return nil } diff --git a/ibm/service/power/data_source_ibm_pi_key_test.go b/ibm/service/power/data_source_ibm_pi_key_test.go index 184b74a0ec..a4fb373339 100644 --- a/ibm/service/power/data_source_ibm_pi_key_test.go +++ b/ibm/service/power/data_source_ibm_pi_key_test.go @@ -13,7 +13,6 @@ import ( ) func TestAccIBMPIKeyDataSource_basic(t *testing.T) { - resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -30,9 +29,8 @@ func TestAccIBMPIKeyDataSource_basic(t *testing.T) { func testAccCheckIBMPIKeyDataSourceConfig() string { return fmt.Sprintf(` -data "ibm_pi_key" "testacc_ds_key" { - pi_key_name = "%s" - pi_cloud_instance_id = "%s" -}`, acc.Pi_key_name, acc.Pi_cloud_instance_id) - + data "ibm_pi_key" "testacc_ds_key" { + pi_key_name = "%s" + pi_cloud_instance_id = "%s" + }`, acc.Pi_key_name, acc.Pi_cloud_instance_id) } diff --git a/ibm/service/power/data_source_ibm_pi_keys.go b/ibm/service/power/data_source_ibm_pi_keys.go index 0f78a9ab4e..f4c6822091 100644 --- a/ibm/service/power/data_source_ibm_pi_keys.go +++ b/ibm/service/power/data_source_ibm_pi_keys.go @@ -13,7 +13,6 @@ import ( "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/terraform-provider-ibm/ibm/conns" ) @@ -21,56 +20,51 @@ func DataSourceIBMPIKeys() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceIBMPIKeysRead, Schema: map[string]*schema.Schema{ - // Arguments Arg_CloudInstanceID: { - Type: schema.TypeString, + Description: "The GUID of the service instance associated with an account.", Required: true, - Description: "PI cloud instance ID", + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, // Attributes Attr_Keys: { - Type: schema.TypeList, Computed: true, - Description: "SSH Keys", + Description: "List of all the SSH keys.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - Attr_KeyName: { - Type: schema.TypeString, + Attr_KeyCreationDate: { Computed: true, - Description: "User defined name for the SSH key", - }, - Attr_Key: { + Description: "Date of SSH key creation.", Type: schema.TypeString, - Computed: true, - Description: "SSH RSA key", }, - Attr_KeyCreationDate: { + Attr_Name: { + Computed: true, + Description: "User defined name for the SSH key.", Type: schema.TypeString, + }, + Attr_SSHKey: { Computed: true, - Description: "Date of SSH key creation", + Description: "SSH RSA key.", + Type: schema.TypeString, }, }, }, + Type: schema.TypeList, }, }, } } func dataSourceIBMPIKeysRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - - // session sess, err := meta.(conns.ClientSession).IBMPISession() if err != nil { return diag.FromErr(err) } - // arguments - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) - // get keys client := st.NewIBMPIKeyClient(ctx, sess, cloudInstanceID) sshKeys, err := client.GetAll() if err != nil { @@ -78,13 +72,12 @@ func dataSourceIBMPIKeysRead(ctx context.Context, d *schema.ResourceData, meta i return diag.FromErr(err) } - // set attributes result := make([]map[string]interface{}, 0, len(sshKeys.SSHKeys)) for _, sshKey := range sshKeys.SSHKeys { key := map[string]interface{}{ - Attr_KeyName: sshKey.Name, - Attr_Key: sshKey.SSHKey, Attr_KeyCreationDate: sshKey.CreationDate.String(), + Attr_Name: sshKey.Name, + Attr_SSHKey: sshKey.SSHKey, } result = append(result, key) } diff --git a/ibm/service/power/data_source_ibm_pi_keys_test.go b/ibm/service/power/data_source_ibm_pi_keys_test.go index f45dfc7fce..e7b135bb1c 100644 --- a/ibm/service/power/data_source_ibm_pi_keys_test.go +++ b/ibm/service/power/data_source_ibm_pi_keys_test.go @@ -31,6 +31,5 @@ func testAccCheckIBMPIKeysDataSourceConfig() string { return fmt.Sprintf(` data "ibm_pi_keys" "test" { pi_cloud_instance_id = "%s" - } - `, acc.Pi_cloud_instance_id) + } `, acc.Pi_cloud_instance_id) } diff --git a/website/docs/d/pi_key.html.markdown b/website/docs/d/pi_key.html.markdown index 19b824e44c..69eda7ca5b 100644 --- a/website/docs/d/pi_key.html.markdown +++ b/website/docs/d/pi_key.html.markdown @@ -1,28 +1,40 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_key" description: |- - Manages an key in the Power Virtual Server cloud. + Manages an SSH key in the Power Virtual Server cloud. --- # ibm_pi_key -Retrieve information about the SSH key that is used for your Power Systems Virtual Server instance. The SSH key is used to access the instance after it is created. For more information, about [configuring your IBM virtual machine (VM)](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-creating-ssh-key). +Retrieve information about the SSH key that is used for your Power Systems Virtual Server instance. The SSH key is used to access the instance after it is created. For more information, about [generating and using SSH Keys](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-creating-ssh-key). ## Example usage - ```terraform data "ibm_pi_key" "ds_instance" { pi_key_name = "terraform-test-key" pi_cloud_instance_id = "49fba6c9-23f8-40bc-9899-aca322ee7d5b" } ``` - + +**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" + zone = "lon04" + } + ``` + ## Argument reference Review the argument references that you can specify for your data source. -- `pi_cloud_instance_id` - (Required, String) Cloud Instance ID of a PCloud Instance. +- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. - `pi_key_name` - (Required, String) User defined name for the SSH key. ## Attribute reference @@ -31,19 +43,3 @@ In addition to all argument reference list, you can access the following attribu - `id` - (String) User defined name for the SSH key - `creation_date` - (String) Date of SSH Key creation. - `ssh_key` - (String) SSH RSA key. - -**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" - zone = "lon04" - } - ``` \ No newline at end of file diff --git a/website/docs/d/pi_keys.html.markdown b/website/docs/d/pi_keys.html.markdown index 305c0f4a9d..dd5dac4d13 100644 --- a/website/docs/d/pi_keys.html.markdown +++ b/website/docs/d/pi_keys.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_keys" @@ -8,20 +7,33 @@ description: |- --- # ibm_pi_keys -Retrieve information about all SSH keys. For more information, see [getting started with IBM Power Systems Virtual Servers](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-getting-started). +Retrieve information about all SSH keys. For more information, about [generating and using SSH Keys](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-creating-ssh-key). ## Example usage - ```terraform data "ibm_pi_keys" "example" { pi_cloud_instance_id = "" } ``` - + +**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" + zone = "lon04" + } + ``` + ## Argument reference Review the argument references that you can specify for your data source. -- `pi_cloud_instance_id` - (Required, String) Cloud Instance ID of a PCloud Instance. +- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. ## Attribute reference In addition to all argument reference list, you can access the following attribute references after your data source is created. @@ -32,19 +44,3 @@ In addition to all argument reference list, you can access the following attribu - `name` - (String) User defined name for the SSH key - `creation_date` - (String) Date of SSH Key creation. - `ssh_key` - (String) SSH RSA key. - -**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" - zone = "lon04" - } - ``` \ No newline at end of file From 839f9abb80da64c74f81f19ed0f6700602758e75 Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Thu, 28 Dec 2023 18:51:37 +0530 Subject: [PATCH 10/16] Catalog-refactor network- port data source and documentation --- .../power/data_source_ibm_pi_network.go | 152 ++++++++++-------- .../power/data_source_ibm_pi_network_port.go | 93 ++++++----- .../data_source_ibm_pi_network_port_test.go | 36 +++++ .../power/data_source_ibm_pi_network_test.go | 9 +- website/docs/d/pi_network.html.markdown | 24 ++- website/docs/d/pi_network_port.html.markdown | 52 ++++++ 6 files changed, 232 insertions(+), 134 deletions(-) create mode 100644 ibm/service/power/data_source_ibm_pi_network_port_test.go create mode 100644 website/docs/d/pi_network_port.html.markdown diff --git a/ibm/service/power/data_source_ibm_pi_network.go b/ibm/service/power/data_source_ibm_pi_network.go index 3a04453ca7..2835514f90 100644 --- a/ibm/service/power/data_source_ibm_pi_network.go +++ b/ibm/service/power/data_source_ibm_pi_network.go @@ -4,86 +4,97 @@ package power import ( - //"fmt" - "context" - "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" - "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/IBM-Cloud/power-go-client/helpers" "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" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) func DataSourceIBMPINetwork() *schema.Resource { - return &schema.Resource{ ReadContext: dataSourceIBMPINetworkRead, Schema: map[string]*schema.Schema{ - helpers.PINetworkName: { - Type: schema.TypeString, + // Arguments + Arg_CloudInstanceID: { + Description: "The GUID of the service instance associated with an account.", Required: true, - Description: "Network Name to be used for pvminstances", + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - helpers.PICloudInstanceId: { - Type: schema.TypeString, + Arg_NetworkName: { + Description: "The unique identifier or name of a network.", Required: true, + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - // Computed Attributes - "cidr": { - Type: schema.TypeString, - Computed: true, + // Attributes + Attr_AccessConfig: { + Computed: true, + Description: "The network communication configuration option of the network (for satellite locations only).", + Type: schema.TypeString, }, - "type": { - Type: schema.TypeString, - Computed: true, + Attr_AvailableIPCount: { + Computed: true, + Description: "The total number of IP addresses that you have in your network.", + Type: schema.TypeFloat, }, - "vlan_id": { - Type: schema.TypeInt, - Computed: true, + Attr_CIDR: { + Computed: true, + Description: "The CIDR of the network.", + Type: schema.TypeString, }, - "gateway": { - Type: schema.TypeString, - Computed: true, + Attr_DNS: { + Computed: true, + Description: "The DNS Servers for the network.", + Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeSet, }, - "available_ip_count": { - Type: schema.TypeFloat, - Computed: true, + Attr_Gateway: { + Computed: true, + Description: "The network gateway that is attached to your network.", + Type: schema.TypeString, }, - "used_ip_count": { - Type: schema.TypeFloat, - Computed: true, + Attr_Jumbo: { + Computed: true, + Deprecated: "This field is deprecated, use mtu instead.", + Description: "MTU Jumbo option of the network (for multi-zone locations only).", + Type: schema.TypeBool, }, - "used_ip_percent": { - Type: schema.TypeFloat, - Computed: true, + Attr_MTU: { + Computed: true, + Description: "Maximum Transmission Unit option of the network.", + Type: schema.TypeInt, }, - "name": { - Type: schema.TypeString, - Computed: true, - Deprecated: "This value is deprecated in favor of" + helpers.PINetworkName, + Attr_Name: { + Computed: true, + Deprecated: "This field is deprecated, use pi_network_name instead.", + Description: "The unique identifier or name of a network.", + Type: schema.TypeString, }, - "dns": { - Type: schema.TypeSet, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, + Attr_Type: { + Computed: true, + Description: "The type of network.", + Type: schema.TypeString, }, - "jumbo": { - Type: schema.TypeBool, - Computed: true, + Attr_UsedIPCount: { + Computed: true, + Description: "The number of used IP addresses.", + Type: schema.TypeFloat, }, - "mtu": { - Type: schema.TypeInt, - Computed: true, + Attr_UsedIPPercent: { + Computed: true, + Description: "The percentage of IP addresses used.", + Type: schema.TypeFloat, }, - "access_config": { - Type: schema.TypeString, - Computed: true, + Attr_VLanID: { + Computed: true, + Description: "The VLAN ID that the network is connected to.", + Type: schema.TypeInt, }, }, } @@ -95,7 +106,7 @@ func dataSourceIBMPINetworkRead(ctx context.Context, d *schema.ResourceData, met return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) networkC := instance.NewIBMPINetworkClient(ctx, sess, cloudInstanceID) networkdata, err := networkC.Get(d.Get(helpers.PINetworkName).(string)) @@ -104,35 +115,34 @@ func dataSourceIBMPINetworkRead(ctx context.Context, d *schema.ResourceData, met } d.SetId(*networkdata.NetworkID) + d.Set(Attr_AccessConfig, networkdata.AccessConfig) + if networkdata.IPAddressMetrics.Available != nil { + d.Set(Attr_AvailableIPCount, networkdata.IPAddressMetrics.Available) + } if networkdata.Cidr != nil { - d.Set("cidr", networkdata.Cidr) + d.Set(Attr_CIDR, networkdata.Cidr) } - if networkdata.Type != nil { - d.Set("type", networkdata.Type) + if len(networkdata.DNSServers) > 0 { + d.Set(Attr_DNS, networkdata.DNSServers) } - d.Set("gateway", networkdata.Gateway) - if networkdata.VlanID != nil { - d.Set("vlan_id", networkdata.VlanID) + d.Set(Attr_Gateway, networkdata.Gateway) + d.Set(Attr_Jumbo, networkdata.Jumbo) + d.Set(Attr_MTU, networkdata.Mtu) + if networkdata.Name != nil { + d.Set(Attr_Name, networkdata.Name) } - if networkdata.IPAddressMetrics.Available != nil { - d.Set("available_ip_count", networkdata.IPAddressMetrics.Available) + if networkdata.Type != nil { + d.Set(Attr_Type, networkdata.Type) } if networkdata.IPAddressMetrics.Used != nil { - d.Set("used_ip_count", networkdata.IPAddressMetrics.Used) + d.Set(Attr_UsedIPCount, networkdata.IPAddressMetrics.Used) } if networkdata.IPAddressMetrics.Utilization != nil { - d.Set("used_ip_percent", networkdata.IPAddressMetrics.Utilization) - } - if networkdata.Name != nil { - d.Set("name", networkdata.Name) + d.Set(Attr_UsedIPPercent, networkdata.IPAddressMetrics.Utilization) } - if len(networkdata.DNSServers) > 0 { - d.Set("dns", networkdata.DNSServers) + if networkdata.VlanID != nil { + d.Set(Attr_VLanID, networkdata.VlanID) } - d.Set("jumbo", networkdata.Jumbo) - d.Set("mtu", networkdata.Mtu) - d.Set("access_config", networkdata.AccessConfig) return nil - } diff --git a/ibm/service/power/data_source_ibm_pi_network_port.go b/ibm/service/power/data_source_ibm_pi_network_port.go index e98a9c3b1b..5fef77e7af 100644 --- a/ibm/service/power/data_source_ibm_pi_network_port.go +++ b/ibm/service/power/data_source_ibm_pi_network_port.go @@ -7,69 +7,74 @@ import ( "context" "log" + "github.com/IBM-Cloud/power-go-client/clients/instance" + "github.com/IBM-Cloud/power-go-client/helpers" "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/IBM-Cloud/power-go-client/helpers" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) func DataSourceIBMPINetworkPort() *schema.Resource { - return &schema.Resource{ ReadContext: dataSourceIBMPINetworkPortsRead, Schema: map[string]*schema.Schema{ - helpers.PINetworkName: { - Type: schema.TypeString, + // Arguments + Arg_CloudInstanceID: { + Description: "The GUID of the service instance associated with an account.", Required: true, - Description: "Network Name to be used for pvminstances", + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - helpers.PICloudInstanceId: { - Type: schema.TypeString, + Arg_NetworkName: { + Description: "The unique identifier or name of a network.", Required: true, + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - // Computed Attributes - "network_ports": { + // Attributes + Attr_NetworkPorts: { Type: schema.TypeList, Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "ipaddress": { - Type: schema.TypeString, - Optional: true, - Computed: true, + Attr_Description: { + Computed: true, + Description: "The description for the network port.", + Type: schema.TypeString, }, - "macaddress": { - Type: schema.TypeString, - Computed: true, + Attr_Href: { + Computed: true, + Description: "Network port href.", + Type: schema.TypeString, }, - "portid": { - Type: schema.TypeString, - Computed: true, + Attr_IPAddress: { + Computed: true, + Description: "The IP address of the port.", + Type: schema.TypeString, }, - "status": { - Type: schema.TypeString, - Computed: true, + Attr_MacAddress: { + Computed: true, + Description: "The MAC address of the port.", + Type: schema.TypeString, }, - "href": { - Type: schema.TypeString, - Computed: true, + Attr_PortID: { + Computed: true, + Description: "The ID of the port.", + Type: schema.TypeString, }, - "description": { - Type: schema.TypeString, - Required: true, + Attr_PublicIP: { + Computed: true, + Description: "The public IP associated with the port.", + Type: schema.TypeString, }, - "public_ip": { - Type: schema.TypeString, - Computed: true, + Attr_Status: { + Computed: true, + Description: "The status of the port.", + Type: schema.TypeString, }, }, }, @@ -84,7 +89,8 @@ func dataSourceIBMPINetworkPortsRead(ctx context.Context, d *schema.ResourceData return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) + networkportC := instance.NewIBMPINetworkClient(ctx, sess, cloudInstanceID) networkportdata, err := networkportC.GetAllPorts(d.Get(helpers.PINetworkName).(string)) if err != nil { @@ -93,10 +99,9 @@ func dataSourceIBMPINetworkPortsRead(ctx context.Context, d *schema.ResourceData var clientgenU, _ = uuid.GenerateUUID() d.SetId(clientgenU) - d.Set("network_ports", flattenNetworkPorts(networkportdata.Ports)) + d.Set(Attr_NetworkPorts, flattenNetworkPorts(networkportdata.Ports)) return nil - } func flattenNetworkPorts(networkPorts []*models.NetworkPort) interface{} { @@ -104,14 +109,14 @@ func flattenNetworkPorts(networkPorts []*models.NetworkPort) interface{} { log.Printf("the number of ports is %d", len(networkPorts)) for _, i := range networkPorts { l := map[string]interface{}{ - "portid": *i.PortID, - "status": *i.Status, - "href": i.Href, - "ipaddress": *i.IPAddress, - "macaddress": *i.MacAddress, - "public_ip": i.ExternalIP, + Attr_Description: i.Description, + Attr_Href: i.Href, + Attr_IPAddress: *i.IPAddress, + Attr_MacAddress: *i.MacAddress, + Attr_PortID: *i.PortID, + Attr_PublicIP: i.ExternalIP, + Attr_Status: *i.Status, } - result = append(result, l) } return result diff --git a/ibm/service/power/data_source_ibm_pi_network_port_test.go b/ibm/service/power/data_source_ibm_pi_network_port_test.go new file mode 100644 index 0000000000..24a386af2d --- /dev/null +++ b/ibm/service/power/data_source_ibm_pi_network_port_test.go @@ -0,0 +1,36 @@ +// Copyright IBM Corp. 2017, 2021 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +package power_test + +import ( + "fmt" + "testing" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccIBMPINetworkPortDataSource_basic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCheckIBMPINetworkPortDataSourceConfig(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_pi_network_port.testacc_ds_network_port", "id"), + ), + }, + }, + }) +} + +func testAccCheckIBMPINetworkPortDataSourceConfig() string { + return fmt.Sprintf(` + data "ibm_pi_network_port" "testacc_ds_network_port" { + pi_network_name = "%s" + pi_cloud_instance_id = "%s" + }`, acc.Pi_network_name, acc.Pi_cloud_instance_id) +} diff --git a/ibm/service/power/data_source_ibm_pi_network_test.go b/ibm/service/power/data_source_ibm_pi_network_test.go index 873681869a..c4c09fa58c 100644 --- a/ibm/service/power/data_source_ibm_pi_network_test.go +++ b/ibm/service/power/data_source_ibm_pi_network_test.go @@ -29,9 +29,8 @@ func TestAccIBMPINetworkDataSource_basic(t *testing.T) { func testAccCheckIBMPINetworkDataSourceConfig() string { return fmt.Sprintf(` -data "ibm_pi_network" "testacc_ds_network" { - pi_network_name = "%s" - pi_cloud_instance_id = "%s" -}`, acc.Pi_network_name, acc.Pi_cloud_instance_id) - + data "ibm_pi_network" "testacc_ds_network" { + pi_network_name = "%s" + pi_cloud_instance_id = "%s" + }`, acc.Pi_network_name, acc.Pi_cloud_instance_id) } diff --git a/website/docs/d/pi_network.html.markdown b/website/docs/d/pi_network.html.markdown index c4f03cb824..e36ad9fcd0 100644 --- a/website/docs/d/pi_network.html.markdown +++ b/website/docs/d/pi_network.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_network" @@ -11,7 +10,6 @@ description: |- Retrieve information about the network that your Power Systems Virtual Server instance is connected to. For more information, about power virtual server instance network, see [setting up an IBM network install server](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-configuring-subnet). ## Example usage - ```terraform data "ibm_pi_network" "ds_network" { pi_network_name = "APP" @@ -19,15 +17,13 @@ data "ibm_pi_network" "ds_network" { } ``` -**Note** - -* 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` +**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: - +Example usage: ```terraform provider "ibm" { region = "lon" @@ -44,15 +40,15 @@ 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. +- `access_config` - (String) The network communication configuration option of the network (for satellite locations only). - `available_ip_count` - (Float) The total number of IP addresses that you have in your network. - `cidr` - (String) The CIDR of the network. -- `dns`- (Set of String) The DNS Servers for the network. +- `dns`- (Set) The DNS Servers for the network. - `gateway` - (String) The network gateway that is attached to your network. - `id` - (String) The ID of the network. +- `jumbo` - (Deprecated, Bool) MTU Jumbo option of the network (for multi-zone locations only). +- `mtu` - (Bool) Maximum Transmission Unit option of the network. - `type` - (String) The type of network. - `used_ip_count` - (Float) The number of used IP addresses. - `used_ip_percent` - (Float) The percentage of IP addresses used. - `vlan_id` - (String) The VLAN ID that the network is connected to. -- `jumbo` - (Bool) MTU Jumbo option of the network (for multi-zone locations only). `deprecated` -- `mtu` - (Bool) Maximum Transmission Unit option of the network. -- `access_config` - (String) The network communication configuration option of the network (for satellite locations only). \ No newline at end of file diff --git a/website/docs/d/pi_network_port.html.markdown b/website/docs/d/pi_network_port.html.markdown new file mode 100644 index 0000000000..9d46bee2d0 --- /dev/null +++ b/website/docs/d/pi_network_port.html.markdown @@ -0,0 +1,52 @@ +--- +subcategory: "Power Systems" +layout: "ibm" +page_title: "IBM: pi_network_port" +description: |- + Manages an Network Port in the Power Virtual Server Cloud. +--- + +# ibm_pi_network_port +Retrieve information about a network port in the Power Virtual Server Cloud. For more information, about networks in IBM power virtual server, see [adding or removing a public network](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-modifying-server#adding-removing-network). + +## Example usage +```terraform +data "ibm_pi_network_port" "test-network-port" { + pi_network_name = "Zone1-CFN" + pi_cloud_instance_id = "51e1879c-bcbe-4ee1-a008-49cdba0eaf60" +} +``` + +**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" + zone = "lon04" + } + ``` + +## Argument reference +Review the argument references that you can specify for your data source. + +- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. +- `pi_network_name` - (Required, String) The unique identifier or name of a network. + +## Attribute reference +In addition to all argument reference list, you can access the following attribute reference after your data source is created. + +- `network_ports` - (List) List of all in use network ports for a network. + + Nested scheme for `network_ports`: + - `description` - (String) The description for the network port. + - `href` - (String) Network port href. + - `ipaddress` - (String) The IP address of the port. + - `macaddress` - (String) The MAC address of the port. + - `portid` - (String) The ID of the port. + - `public_ip`- (String) The public IP associated with the port. + - `status` - (String) The status of the port. From be5457146f9f06010788054643b178dc7ff35fbb Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Thu, 28 Dec 2023 18:54:35 +0530 Subject: [PATCH 11/16] Catalog-refactor placement group data source and documentation --- .../data_source_ibm_pi_placement_group.go | 53 +++++++-------- ...data_source_ibm_pi_placement_group_test.go | 9 ++- .../data_source_ibm_pi_placement_groups.go | 66 +++++++++---------- ...ata_source_ibm_pi_placement_groups_test.go | 3 +- .../docs/d/pi_placement_group.html.markdown | 16 ++--- .../docs/d/pi_placement_groups.html.markdown | 14 ++-- 6 files changed, 76 insertions(+), 85 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_placement_group.go b/ibm/service/power/data_source_ibm_pi_placement_group.go index 9792aa331d..6b90a44f98 100644 --- a/ibm/service/power/data_source_ibm_pi_placement_group.go +++ b/ibm/service/power/data_source_ibm_pi_placement_group.go @@ -7,55 +7,56 @@ import ( "context" "log" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - 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/terraform-provider-ibm/ibm/conns" "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" ) func DataSourceIBMPIPlacementGroup() *schema.Resource { - return &schema.Resource{ ReadContext: dataSourceIBMPIPlacementGroupRead, Schema: map[string]*schema.Schema{ - helpers.PIPlacementGroupName: { - Type: schema.TypeString, - Required: true, - }, - - "policy": { - Type: schema.TypeString, - Computed: true, - }, - - helpers.PICloudInstanceId: { + // Arguments + Arg_CloudInstanceID: { + Description: "The GUID of the service instance associated with an account.", + Required: true, Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, + }, + Arg_PlacementGroupName: { + Description: "The name of the placement group.", Required: true, + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - PIPlacementGroupMembers: { - Type: schema.TypeList, - Elem: &schema.Schema{Type: schema.TypeString}, - Computed: true, + // Attribute + Attr_Members: { + Computed: true, + Description: "List of server instances IDs that are members of the placement group.", + Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeList, + }, + Attr_Policy: { + Computed: true, + Description: "The value of the group's affinity policy. Valid values are affinity and anti-affinity.", + Type: schema.TypeString, }, }, } } func dataSourceIBMPIPlacementGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - sess, err := meta.(conns.ClientSession).IBMPISession() if err != nil { return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) - placementGroupName := d.Get(helpers.PIPlacementGroupName).(string) - client := st.NewIBMPIPlacementGroupClient(ctx, sess, cloudInstanceID) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) + placementGroupName := d.Get(Arg_PlacementGroupName).(string) + client := instance.NewIBMPIPlacementGroupClient(ctx, sess, cloudInstanceID) response, err := client.Get(placementGroupName) if err != nil { @@ -64,8 +65,8 @@ func dataSourceIBMPIPlacementGroupRead(ctx context.Context, d *schema.ResourceDa } d.SetId(*response.ID) - d.Set("policy", response.Policy) - d.Set(PIPlacementGroupMembers, response.Members) + d.Set(Attr_Members, response.Members) + d.Set(Attr_Policy, response.Policy) return nil } diff --git a/ibm/service/power/data_source_ibm_pi_placement_group_test.go b/ibm/service/power/data_source_ibm_pi_placement_group_test.go index 0738266a98..05478cc72a 100644 --- a/ibm/service/power/data_source_ibm_pi_placement_group_test.go +++ b/ibm/service/power/data_source_ibm_pi_placement_group_test.go @@ -28,9 +28,8 @@ func TestAccIBMPIPlacementGroupDataSource_basic(t *testing.T) { func testAccCheckIBMPIPlacementGroupDataSourceConfig() string { return fmt.Sprintf(` -data "ibm_pi_placement_group" "testacc_ds_placement_group" { - pi_placement_group_name = "%s" - pi_cloud_instance_id = "%s" -}`, acc.Pi_placement_group_name, acc.Pi_cloud_instance_id) - + data "ibm_pi_placement_group" "testacc_ds_placement_group" { + pi_placement_group_name = "%s" + pi_cloud_instance_id = "%s" + }`, acc.Pi_placement_group_name, acc.Pi_cloud_instance_id) } diff --git a/ibm/service/power/data_source_ibm_pi_placement_groups.go b/ibm/service/power/data_source_ibm_pi_placement_groups.go index 345f2bf05c..6b25ed99ba 100644 --- a/ibm/service/power/data_source_ibm_pi_placement_groups.go +++ b/ibm/service/power/data_source_ibm_pi_placement_groups.go @@ -7,52 +7,52 @@ import ( "context" "log" + "github.com/IBM-Cloud/power-go-client/clients/instance" + "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" "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/terraform-provider-ibm/ibm/conns" -) - -const ( - PIPlacementGroups = "placement_groups" ) func DataSourceIBMPIPlacementGroups() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceIBMPIPlacementGroupsRead, 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, - Description: "PI cloud instance ID", + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - // Computed Attributes - PIPlacementGroups: { + + // Attributes + Attr_PlacementGroups: { Type: schema.TypeList, Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "id": { - Type: schema.TypeString, - Computed: true, + Attr_ID: { + Computed: true, + Description: "The ID of the placement group.", + Type: schema.TypeString, }, - "name": { - Type: schema.TypeString, - Computed: true, + Attr_Members: { + Computed: true, + Description: "List of server instances IDs that are members of the placement group.", + Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeList, }, - PIPlacementGroupMembers: { - Type: schema.TypeList, - Elem: &schema.Schema{Type: schema.TypeString}, - Computed: true, + Attr_Name: { + Computed: true, + Description: "User defined name for the placement group.", + Type: schema.TypeString, }, - "policy": { - Type: schema.TypeString, - Computed: true, + Attr_Policy: { + Computed: true, + Description: "The value of the group's affinity policy. Valid values are affinity and anti-affinity.", + Type: schema.TypeString, }, }, }, @@ -67,9 +67,9 @@ func dataSourceIBMPIPlacementGroupsRead(ctx context.Context, d *schema.ResourceD return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) - client := st.NewIBMPIPlacementGroupClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPIPlacementGroupClient(ctx, sess, cloudInstanceID) groups, err := client.GetAll() if err != nil { log.Printf("[ERROR] get all placement groups failed %v", err) @@ -79,17 +79,17 @@ func dataSourceIBMPIPlacementGroupsRead(ctx context.Context, d *schema.ResourceD result := make([]map[string]interface{}, 0, len(groups.PlacementGroups)) for _, placementGroup := range groups.PlacementGroups { key := map[string]interface{}{ - "id": placementGroup.ID, - "name": placementGroup.Name, - PIPlacementGroupMembers: placementGroup.Members, - "policy": placementGroup.Policy, + Attr_ID: placementGroup.ID, + Attr_Members: placementGroup.Members, + Attr_Name: placementGroup.Name, + Attr_Policy: placementGroup.Policy, } result = append(result, key) } var genID, _ = uuid.GenerateUUID() d.SetId(genID) - d.Set(PIPlacementGroups, result) + d.Set(Attr_PlacementGroups, result) return nil } diff --git a/ibm/service/power/data_source_ibm_pi_placement_groups_test.go b/ibm/service/power/data_source_ibm_pi_placement_groups_test.go index 2f0e8131c8..d520f3f1e0 100644 --- a/ibm/service/power/data_source_ibm_pi_placement_groups_test.go +++ b/ibm/service/power/data_source_ibm_pi_placement_groups_test.go @@ -30,6 +30,5 @@ func testAccCheckIBMPIPlacementGrousDataSourceConfig() string { return fmt.Sprintf(` data "ibm_pi_placement_groups" "test" { pi_cloud_instance_id = "%s" - } - `, acc.Pi_cloud_instance_id) + }`, acc.Pi_cloud_instance_id) } diff --git a/website/docs/d/pi_placement_group.html.markdown b/website/docs/d/pi_placement_group.html.markdown index d90d4b83f9..0c6aebd4d4 100644 --- a/website/docs/d/pi_placement_group.html.markdown +++ b/website/docs/d/pi_placement_group.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_placement_group" @@ -11,7 +10,6 @@ description: |- Retrieve information about a placement group. For more information, about placement groups, see [Managing server placement groups](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-placement-groups). ## Example Usage - ```terraform data "ibm_pi_placement_group" "ds_placement_group" { pi_placement_group_name = "my-pg" @@ -20,20 +18,18 @@ data "ibm_pi_placement_group" "ds_placement_group" { ``` **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: +- 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" zone = "lon04" } ``` - ## Argument reference Review the argument references that you can specify for your data source. @@ -45,5 +41,5 @@ 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. - `id` - (String) The ID of the placement group. -- `members` - (List of strings) The list of server instances IDs that are members of the placement group. +- `members` - (List) List of server instances IDs that are members of the placement group. - `policy` - (String) The value of the group's affinity policy. Valid values are affinity and anti-affinity. diff --git a/website/docs/d/pi_placement_groups.html.markdown b/website/docs/d/pi_placement_groups.html.markdown index c4ef5d7946..a1e11659bf 100644 --- a/website/docs/d/pi_placement_groups.html.markdown +++ b/website/docs/d/pi_placement_groups.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_placement_groups" @@ -11,7 +10,6 @@ description: |- Retrieve information about all placement groups. For more information, 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_placement_groups" "example" { pi_cloud_instance_id = "" @@ -19,14 +17,12 @@ data "ibm_pi_placement_groups" "example" { ``` **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` +- 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" @@ -46,6 +42,6 @@ In addition to all argument reference list, you can access the following attribu Nested scheme for `placement_groups`: - `id` - (String) The ID of the placement group. + - `members` - (List) List of server instances IDs that are members of the placement group. - `name` - (String) User defined name for the placement group. - - `members` - (List of strings) The list of server instances IDs that are members of the placement group. - `policy` - (String) The value of the group's affinity policy. Valid values are affinity and anti-affinity. From 80ae39bda23d1acf776b178b8c253e574236b25f Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Thu, 28 Dec 2023 18:56:40 +0530 Subject: [PATCH 12/16] Catalog-refactor sap profile data source and documentation --- .../power/data_source_ibm_pi_sap_profile.go | 60 +++++++++-------- .../power/data_source_ibm_pi_sap_profiles.go | 66 ++++++++++--------- website/docs/d/pi_sap_profile.html.markdown | 14 ++-- website/docs/d/pi_sap_profiles.html.markdown | 14 ++-- 4 files changed, 75 insertions(+), 79 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_sap_profile.go b/ibm/service/power/data_source_ibm_pi_sap_profile.go index 43510987d1..1f53d1ad72 100644 --- a/ibm/service/power/data_source_ibm_pi_sap_profile.go +++ b/ibm/service/power/data_source_ibm_pi_sap_profile.go @@ -7,49 +7,51 @@ import ( "context" "log" + "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" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - - "github.com/IBM-Cloud/power-go-client/clients/instance" - "github.com/IBM-Cloud/power-go-client/helpers" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" ) func DataSourceIBMPISAPProfile() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceIBMPISAPProfileRead, 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, }, - PISAPInstanceProfileID: { - Type: schema.TypeString, - Required: true, - Description: "SAP Profile ID", + Arg_SAPProfileID: { + Description: "SAP Profile ID", + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, }, - // Computed Attributes - PISAPProfileCertified: { - Type: schema.TypeBool, + + // Attributes + Attr_Certified: { Computed: true, - Description: "Has certification been performed on profile", + Description: "Has certification been performed on profile.", + Type: schema.TypeBool, }, - PISAPProfileCores: { - Type: schema.TypeInt, + Attr_Cores: { Computed: true, - Description: "Amount of cores", - }, - PISAPProfileMemory: { + Description: "Amount of cores.", Type: schema.TypeInt, + }, + Attr_Memory: { Computed: true, - Description: "Amount of memory (in GB)", + Description: "Amount of memory (in GB).", + Type: schema.TypeInt, }, - PISAPProfileType: { - Type: schema.TypeString, + Attr_Type: { Computed: true, - Description: "Type of profile", + Description: "Type of profile.", + Type: schema.TypeString, }, }, } @@ -61,8 +63,8 @@ func dataSourceIBMPISAPProfileRead(ctx context.Context, d *schema.ResourceData, return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) - profileID := d.Get(PISAPInstanceProfileID).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) + profileID := d.Get(Arg_SAPProfileID).(string) client := instance.NewIBMPISAPInstanceClient(ctx, sess, cloudInstanceID) sapProfile, err := client.GetSAPProfile(profileID) @@ -72,10 +74,10 @@ func dataSourceIBMPISAPProfileRead(ctx context.Context, d *schema.ResourceData, } d.SetId(*sapProfile.ProfileID) - d.Set(PISAPProfileCertified, *sapProfile.Certified) - d.Set(PISAPProfileCores, *sapProfile.Cores) - d.Set(PISAPProfileMemory, *sapProfile.Memory) - d.Set(PISAPProfileType, *sapProfile.Type) + d.Set(Attr_Certified, *sapProfile.Certified) + d.Set(Attr_Cores, *sapProfile.Cores) + d.Set(Attr_Memory, *sapProfile.Memory) + d.Set(Attr_Type, *sapProfile.Type) return nil } diff --git a/ibm/service/power/data_source_ibm_pi_sap_profiles.go b/ibm/service/power/data_source_ibm_pi_sap_profiles.go index 0b314791ca..a3c3c5f5a6 100644 --- a/ibm/service/power/data_source_ibm_pi_sap_profiles.go +++ b/ibm/service/power/data_source_ibm_pi_sap_profiles.go @@ -7,58 +7,60 @@ import ( "context" "log" + "github.com/IBM-Cloud/power-go-client/clients/instance" + "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" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - - "github.com/IBM-Cloud/power-go-client/clients/instance" - "github.com/IBM-Cloud/power-go-client/helpers" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" ) func DataSourceIBMPISAPProfiles() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceIBMPISAPProfilesRead, 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 - PISAPProfiles: { - Type: schema.TypeList, - Computed: true, + + // Attributes + Attr_Profiles: { + Computed: true, + Description: "List of all the SAP Profiles.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - PISAPProfileCertified: { - Type: schema.TypeBool, + Attr_Certified: { Computed: true, - Description: "Has certification been performed on profile", + Description: "Has certification been performed on profile.", + Type: schema.TypeBool, }, - PISAPProfileCores: { - Type: schema.TypeInt, + Attr_Cores: { Computed: true, - Description: "Amount of cores", - }, - PISAPProfileMemory: { + Description: "Amount of cores.", Type: schema.TypeInt, - Computed: true, - Description: "Amount of memory (in GB)", }, - PISAPProfileID: { - Type: schema.TypeString, + Attr_Memory: { Computed: true, - Description: "SAP Profile ID", + Description: "Amount of memory (in GB).", + Type: schema.TypeInt, }, - PISAPProfileType: { + Attr_ProfileID: { + Computed: true, + Description: "SAP Profile ID.", Type: schema.TypeString, + }, + Attr_Type: { Computed: true, - Description: "Type of profile", + Description: "Type of profile.", + Type: schema.TypeString, }, }, }, + Type: schema.TypeList, }, }, } @@ -70,7 +72,7 @@ func dataSourceIBMPISAPProfilesRead(ctx context.Context, d *schema.ResourceData, return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) client := instance.NewIBMPISAPInstanceClient(ctx, sess, cloudInstanceID) sapProfiles, err := client.GetAllSAPProfiles(cloudInstanceID) @@ -82,18 +84,18 @@ func dataSourceIBMPISAPProfilesRead(ctx context.Context, d *schema.ResourceData, result := make([]map[string]interface{}, 0, len(sapProfiles.Profiles)) for _, sapProfile := range sapProfiles.Profiles { profile := map[string]interface{}{ - PISAPProfileCertified: *sapProfile.Certified, - PISAPProfileCores: *sapProfile.Cores, - PISAPProfileMemory: *sapProfile.Memory, - PISAPProfileID: *sapProfile.ProfileID, - PISAPProfileType: *sapProfile.Type, + Attr_Certified: *sapProfile.Certified, + Attr_Cores: *sapProfile.Cores, + Attr_Memory: *sapProfile.Memory, + Attr_ProfileID: *sapProfile.ProfileID, + Attr_Type: *sapProfile.Type, } result = append(result, profile) } var genID, _ = uuid.GenerateUUID() d.SetId(genID) - d.Set(PISAPProfiles, result) + d.Set(Attr_Profiles, result) return nil } diff --git a/website/docs/d/pi_sap_profile.html.markdown b/website/docs/d/pi_sap_profile.html.markdown index 2be43b8874..4f80a10755 100644 --- a/website/docs/d/pi_sap_profile.html.markdown +++ b/website/docs/d/pi_sap_profile.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_sap_profile" @@ -11,7 +10,6 @@ description: |- Retrieve information about a SAP profile. For more information, 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_sap_profile" "example" { pi_cloud_instance_id = "" @@ -20,14 +18,12 @@ data "ibm_pi_sap_profile" "example" { ``` **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` +- 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,7 +40,7 @@ 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. -- `certified` - (Boolean) Has certification been performed on profile. +- `certified` - (Bool) Has certification been performed on profile. - `cores` - (Integer) Amount of cores. - `memory` - (Integer) Amount of memory (in GB). - `type` - (String) Type of profile. diff --git a/website/docs/d/pi_sap_profiles.html.markdown b/website/docs/d/pi_sap_profiles.html.markdown index 4106f1fa84..afa565dc58 100644 --- a/website/docs/d/pi_sap_profiles.html.markdown +++ b/website/docs/d/pi_sap_profiles.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_sap_profiles" @@ -11,7 +10,6 @@ description: |- Retrieve information about all SAP profiles. For more information, 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_sap_profiles" "example" { pi_cloud_instance_id = "" @@ -19,14 +17,12 @@ data "ibm_pi_sap_profiles" "example" { ``` **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` +- 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" @@ -45,7 +41,7 @@ In addition to all argument reference list, you can access the following attribu - `profiles` - (List) List of all the SAP Profiles. Nested scheme for `profiles`: - - `certified` - (Boolean) Has certification been performed on profile. + - `certified` - (Bool) Has certification been performed on profile. - `cores` - (Integer) Amount of cores. - `memory` - (Integer) Amount of memory (in GB). - `profile_id` - (String) SAP Profile ID. From e1a16c2d79862e0fa30b6c95eed09fe9614e19b2 Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Thu, 28 Dec 2023 18:59:26 +0530 Subject: [PATCH 13/16] Catalog-refactor shared processor pool data source and documentation --- ...ata_source_ibm_pi_shared_processor_pool.go | 196 +++++++++--------- ...ource_ibm_pi_shared_processor_pool_test.go | 9 +- ...ta_source_ibm_pi_shared_processor_pools.go | 105 +++++----- ...urce_ibm_pi_shared_processor_pools_test.go | 3 +- .../d/pi_shared_processor_pool.html.markdown | 19 +- .../d/pi_shared_processor_pools.html.markdown | 14 +- 6 files changed, 168 insertions(+), 178 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_shared_processor_pool.go b/ibm/service/power/data_source_ibm_pi_shared_processor_pool.go index e3fcc1be34..b6c04c4f58 100644 --- a/ibm/service/power/data_source_ibm_pi_shared_processor_pool.go +++ b/ibm/service/power/data_source_ibm_pi_shared_processor_pool.go @@ -6,143 +6,137 @@ package power import ( "context" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - 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/terraform-provider-ibm/ibm/conns" "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" ) func DataSourceIBMPISharedProcessorPool() *schema.Resource { - return &schema.Resource{ ReadContext: dataSourceIBMPISharedProcessorPoolRead, Schema: map[string]*schema.Schema{ - Arg_SharedProcessorPoolID: { - Type: schema.TypeString, - Required: true, - }, - + // Arguments Arg_CloudInstanceID: { - Type: schema.TypeString, - Required: true, - Description: "PI cloud instance ID", + Description: "The GUID of the service instance associated with an account.", + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, }, - - Attr_SharedProcessorPoolName: { - Type: schema.TypeString, - Computed: true, - Description: "Name of the shared processor pool", - }, - - Attr_SharedProcessorPoolHostID: { - Type: schema.TypeInt, - Computed: true, - Description: "The host ID where the shared processor pool resides", - }, - - Attr_SharedProcessorPoolReservedCores: { - Type: schema.TypeInt, - Computed: true, - Description: "The amount of reserved cores for the shared processor pool", + Arg_SharedProcessorPoolID: { + Description: "The ID of the shared processor pool.", + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, }, - Attr_SharedProcessorPoolAvailableCores: { - Type: schema.TypeFloat, + // Attributes + Attr_AllocatedCores: { Computed: true, - Description: "Shared processor pool available cores", - }, - - Attr_SharedProcessorPoolAllocatedCores: { + Description: "The allocated cores in the shared processor pool.", Type: schema.TypeFloat, - Computed: true, - Description: "Shared processor pool allocated cores", }, - - Attr_SharedProcessorPoolStatus: { - Type: schema.TypeString, + Attr_AvailableCores: { Computed: true, - Description: "The status of the shared processor pool", + Description: "The available cores in the shared processor pool.", + Type: schema.TypeFloat, }, - - Attr_SharedProcessorPoolStatusDetail: { - Type: schema.TypeString, + Attr_HostID: { Computed: true, - Description: "The status details of the shared processor pool", + Description: "The host ID where the shared processor pool resides.", + Type: schema.TypeInt, }, - - Attr_SharedProcessorPoolInstances: { - Type: schema.TypeList, + Attr_Instances: { Computed: true, - Description: "List of server instances deployed in the shared processor pool", + Description: "List of server instances deployed in the shared processor pool.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - Attr_SharedProcessorPoolInstanceCpus: { - Type: schema.TypeInt, - Optional: true, + Attr_AvailabilityZone: { Computed: true, - Description: "The amount of cpus for the server instance", - }, - Attr_SharedProcessorPoolInstanceUncapped: { - Type: schema.TypeBool, + Description: "Availability zone for the server instances.", Optional: true, - Computed: true, - Description: "Identifies if uncapped or not", - }, - Attr_SharedProcessorPoolInstanceAvailabilityZone: { Type: schema.TypeString, - Optional: true, - Computed: true, - Description: "Availability zone for the server instances", }, - Attr_SharedProcessorPoolInstanceId: { - Type: schema.TypeString, - Optional: true, + Attr_CPUs: { Computed: true, - Description: "The server instance ID", - }, - Attr_SharedProcessorPoolInstanceMemory: { - Type: schema.TypeInt, + Description: "The amount of cpus for the server instance.", Optional: true, - Computed: true, - Description: "The amount of memory for the server instance", + Type: schema.TypeInt, }, - Attr_SharedProcessorPoolInstanceName: { - Type: schema.TypeString, + Attr_ID: { + Computed: true, + Description: "The server instance ID.", Optional: true, + Type: schema.TypeString, + }, + Attr_Memory: { Computed: true, - Description: "The server instance name", + Description: "The amount of memory for the server instance.", + Optional: true, + Type: schema.TypeInt, }, - Attr_SharedProcessorPoolInstanceStatus: { - Type: schema.TypeString, + Attr_Name: { + Computed: true, + Description: "The server instance name.", Optional: true, + Type: schema.TypeString, + }, + Attr_Status: { Computed: true, - Description: "Status of the server", + Description: "Status of the instance.", + Optional: true, + Type: schema.TypeString, }, - Attr_SharedProcessorPoolInstanceVcpus: { - Type: schema.TypeFloat, + Attr_Uncapped: { + Computed: true, + Description: "Identifies if uncapped or not.", Optional: true, + Type: schema.TypeBool, + }, + Attr_VCPUs: { Computed: true, - Description: "The amout of vcpus for the server instance", + Description: "The amout of vcpus for the server instance.", + Optional: true, + Type: schema.TypeFloat, }, }, }, + Type: schema.TypeList, + }, + Attr_Name: { + Computed: true, + Description: "The name of the shared processor pool.", + Type: schema.TypeString, + }, + Attr_ReservedCores: { + Computed: true, + Description: "The amount of reserved cores for the shared processor pool.", + Type: schema.TypeInt, + }, + Attr_Status: { + Computed: true, + Description: "The status of the shared processor pool.", + Type: schema.TypeString, + }, + Attr_StatusDetail: { + Computed: true, + Description: "The status details of the shared processor pool.", + Type: schema.TypeString, }, }, } } func dataSourceIBMPISharedProcessorPoolRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - sess, err := meta.(conns.ClientSession).IBMPISession() if err != nil { return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) poolID := d.Get(Arg_SharedProcessorPoolID).(string) - client := st.NewIBMPISharedProcessorPoolClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPISharedProcessorPoolClient(ctx, sess, cloudInstanceID) response, err := client.Get(poolID) if err != nil || response == nil { @@ -150,33 +144,33 @@ func dataSourceIBMPISharedProcessorPoolRead(ctx context.Context, d *schema.Resou } d.SetId(*response.SharedProcessorPool.ID) - d.Set(Attr_SharedProcessorPoolName, response.SharedProcessorPool.Name) - d.Set(Attr_SharedProcessorPoolReservedCores, response.SharedProcessorPool.ReservedCores) - d.Set(Attr_SharedProcessorPoolAllocatedCores, response.SharedProcessorPool.AllocatedCores) - d.Set(Attr_SharedProcessorPoolAvailableCores, response.SharedProcessorPool.AvailableCores) - d.Set(Attr_SharedProcessorPoolHostID, response.SharedProcessorPool.HostID) - d.Set(Attr_SharedProcessorPoolStatus, response.SharedProcessorPool.Status) - d.Set(Attr_SharedProcessorPoolStatusDetail, response.SharedProcessorPool.StatusDetail) + d.Set(Attr_AllocatedCores, response.SharedProcessorPool.AllocatedCores) + d.Set(Attr_AvailableCores, response.SharedProcessorPool.AvailableCores) + d.Set(Attr_HostID, response.SharedProcessorPool.HostID) + d.Set(Attr_Name, response.SharedProcessorPool.Name) + d.Set(Attr_ReservedCores, response.SharedProcessorPool.ReservedCores) + d.Set(Attr_Status, response.SharedProcessorPool.Status) + d.Set(Attr_StatusDetail, response.SharedProcessorPool.StatusDetail) serversMap := []map[string]interface{}{} if response.Servers != nil { for _, s := range response.Servers { if s != nil { v := map[string]interface{}{ - Attr_SharedProcessorPoolInstanceCpus: s.Cpus, - Attr_SharedProcessorPoolInstanceUncapped: s.Uncapped, - Attr_SharedProcessorPoolInstanceAvailabilityZone: s.AvailabilityZone, - Attr_SharedProcessorPoolInstanceId: s.ID, - Attr_SharedProcessorPoolInstanceMemory: s.Memory, - Attr_SharedProcessorPoolInstanceName: s.Name, - Attr_SharedProcessorPoolInstanceStatus: s.Status, - Attr_SharedProcessorPoolInstanceVcpus: s.Vcpus, + Attr_AvailabilityZone: s.AvailabilityZone, + Attr_CPUs: s.Cpus, + Attr_ID: s.ID, + Attr_Memory: s.Memory, + Attr_Name: s.Name, + Attr_Status: s.Status, + Attr_Uncapped: s.Uncapped, + Attr_VCPUs: s.Vcpus, } serversMap = append(serversMap, v) } } } - d.Set(Attr_SharedProcessorPoolInstances, serversMap) + d.Set(Attr_Instances, serversMap) return nil } diff --git a/ibm/service/power/data_source_ibm_pi_shared_processor_pool_test.go b/ibm/service/power/data_source_ibm_pi_shared_processor_pool_test.go index a39f509265..17df24c366 100644 --- a/ibm/service/power/data_source_ibm_pi_shared_processor_pool_test.go +++ b/ibm/service/power/data_source_ibm_pi_shared_processor_pool_test.go @@ -28,9 +28,8 @@ func TestAccIBMPIPISharedProcessorPoolDataSource_basic(t *testing.T) { func testAccCheckIBMPIPISharedProcessorPoolDataSourceConfig() string { return fmt.Sprintf(` -data "ibm_pi_shared_processor_pool" "test_pool" { - pi_shared_processor_pool_id = "%s" - pi_cloud_instance_id = "%s" -}`, acc.Pi_shared_processor_pool_id, acc.Pi_cloud_instance_id) - + data "ibm_pi_shared_processor_pool" "test_pool" { + pi_shared_processor_pool_id = "%s" + pi_cloud_instance_id = "%s" + }`, acc.Pi_shared_processor_pool_id, acc.Pi_cloud_instance_id) } diff --git a/ibm/service/power/data_source_ibm_pi_shared_processor_pools.go b/ibm/service/power/data_source_ibm_pi_shared_processor_pools.go index e14611d878..74ccf37d22 100644 --- a/ibm/service/power/data_source_ibm_pi_shared_processor_pools.go +++ b/ibm/service/power/data_source_ibm_pi_shared_processor_pools.go @@ -6,70 +6,75 @@ package power import ( "context" + "github.com/IBM-Cloud/power-go-client/clients/instance" + "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" "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/terraform-provider-ibm/ibm/conns" -) - -const ( - PISharedProcessorPools = "shared_processor_pools" ) func DataSourceIBMPISharedProcessorPools() *schema.Resource { return &schema.Resource{ ReadContext: dataSourceIBMPISharedProcessorPoolsRead, 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, - Description: "PI cloud instance ID", + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - // Computed Attributes - PISharedProcessorPools: { - Type: schema.TypeList, - Computed: true, + + // Attributes + Attr_SharedProcessorPools: { + Computed: true, + Description: "List of all the shared processor pools.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - Attr_SharedProcessorPoolID: { - Type: schema.TypeString, - Computed: true, + Attr_AllocatedCores: { + Computed: true, + Description: "The allocated cores in the shared processor pool.", + Type: schema.TypeFloat, }, - Attr_SharedProcessorPoolAllocatedCores: { - Type: schema.TypeFloat, - Computed: true, + Attr_AvailableCores: { + Computed: true, + Description: "The available cores in the shared processor pool.", + Type: schema.TypeInt, }, - Attr_SharedProcessorPoolAvailableCores: { - Type: schema.TypeInt, - Computed: true, + Attr_HostID: { + Computed: true, + Description: "The host ID where the shared processor pool resides.", + Type: schema.TypeInt, }, - Attr_SharedProcessorPoolName: { - Type: schema.TypeString, - Computed: true, + Attr_Name: { + Computed: true, + Description: "The name of the shared processor pool.", + Type: schema.TypeString, }, - Attr_SharedProcessorPoolReservedCores: { - Type: schema.TypeInt, - Computed: true, + Attr_ReservedCores: { + Computed: true, + Description: "The amount of reserved cores for the shared processor pool.", + Type: schema.TypeInt, }, - Attr_SharedProcessorPoolHostID: { - Type: schema.TypeInt, - Computed: true, + Attr_SharedProcessorPoolID: { + Computed: true, + Description: "The shared processor pool's unique ID.", + Type: schema.TypeString, }, - Attr_SharedProcessorPoolStatus: { - Type: schema.TypeString, - Computed: true, + Attr_Status: { + Computed: true, + Description: "The status of the shared processor pool.", + Type: schema.TypeString, }, - Attr_SharedProcessorPoolStatusDetail: { - Type: schema.TypeString, - Computed: true, + Attr_StatusDetail: { + Computed: true, + Description: "The status details of the shared processor pool.", + Type: schema.TypeString, }, }, }, + Type: schema.TypeList, }, }, } @@ -81,9 +86,9 @@ func dataSourceIBMPISharedProcessorPoolsRead(ctx context.Context, d *schema.Reso return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) - client := st.NewIBMPISharedProcessorPoolClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPISharedProcessorPoolClient(ctx, sess, cloudInstanceID) pools, err := client.GetAll() if err != nil || pools == nil { return diag.Errorf("error fetching shared processor pools: %v", err) @@ -92,21 +97,21 @@ func dataSourceIBMPISharedProcessorPoolsRead(ctx context.Context, d *schema.Reso result := make([]map[string]interface{}, 0, len(pools.SharedProcessorPools)) for _, pool := range pools.SharedProcessorPools { key := map[string]interface{}{ - Attr_SharedProcessorPoolID: *pool.ID, - Attr_SharedProcessorPoolName: *pool.Name, - Attr_SharedProcessorPoolAllocatedCores: *pool.AllocatedCores, - Attr_SharedProcessorPoolAvailableCores: *pool.AvailableCores, - Attr_SharedProcessorPoolReservedCores: *pool.ReservedCores, - Attr_SharedProcessorPoolHostID: pool.HostID, - Attr_SharedProcessorPoolStatus: pool.Status, - Attr_SharedProcessorPoolStatusDetail: pool.StatusDetail, + Attr_AllocatedCores: *pool.AllocatedCores, + Attr_AvailableCores: *pool.AvailableCores, + Attr_HostID: pool.HostID, + Attr_Name: *pool.Name, + Attr_ReservedCores: *pool.ReservedCores, + Attr_SharedProcessorPoolID: *pool.ID, + Attr_Status: pool.Status, + Attr_StatusDetail: pool.StatusDetail, } result = append(result, key) } var genID, _ = uuid.GenerateUUID() d.SetId(genID) - d.Set(PISharedProcessorPools, result) + d.Set(Attr_SharedProcessorPools, result) return nil } diff --git a/ibm/service/power/data_source_ibm_pi_shared_processor_pools_test.go b/ibm/service/power/data_source_ibm_pi_shared_processor_pools_test.go index fcbb9c4dbb..1d5367bf85 100644 --- a/ibm/service/power/data_source_ibm_pi_shared_processor_pools_test.go +++ b/ibm/service/power/data_source_ibm_pi_shared_processor_pools_test.go @@ -30,6 +30,5 @@ func testAccCheckIBMPISharedProcessorPoolsDataSourceConfig() string { return fmt.Sprintf(` data "ibm_pi_shared_processor_pools" "test" { pi_cloud_instance_id = "%s" - } - `, acc.Pi_cloud_instance_id) + }`, acc.Pi_cloud_instance_id) } diff --git a/website/docs/d/pi_shared_processor_pool.html.markdown b/website/docs/d/pi_shared_processor_pool.html.markdown index b47e607be6..7918b46199 100644 --- a/website/docs/d/pi_shared_processor_pool.html.markdown +++ b/website/docs/d/pi_shared_processor_pool.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_shared_processor_pool" @@ -11,7 +10,6 @@ description: |- Retrieve information about a shared processor pool. For more information, 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_shared_processor_pool" "ds_pool" { pi_shared_processor_pool_id = "my-spp" @@ -20,20 +18,18 @@ data "ibm_pi_shared_processor_pool" "ds_pool" { ``` **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: +- 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" zone = "lon04" } - ``` - + ``` ## Argument reference Review the argument references that you can specify for your data source. @@ -48,7 +44,8 @@ In addition to all argument reference list, you can access the following attribu - `available_cores` - (Integer) The available cores in the shared processor pool. - `host_id` - (Integer) The host ID where the shared processor pool resides. - `id` - (String) The shared processor pool's unique ID. -- `instances` - (List of Map) The list of server instances that are deployed in the shared processor pool. +- `instances` - (List) List of server instances deployed in the shared processor pool. + Nested scheme for `instances`: - `availability_zone` - (String) Availability zone for the server instances. - `cpus` - (Integer) The amount of cpus for the server instance. diff --git a/website/docs/d/pi_shared_processor_pools.html.markdown b/website/docs/d/pi_shared_processor_pools.html.markdown index dd9ad6d97e..3586e0437c 100644 --- a/website/docs/d/pi_shared_processor_pools.html.markdown +++ b/website/docs/d/pi_shared_processor_pools.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_shared_processor_pools" @@ -11,7 +10,6 @@ description: |- Retrieve information about all shared processor pools. For more information, 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_shared_processor_pools" "example" { pi_cloud_instance_id = "" @@ -19,14 +17,12 @@ data "ibm_pi_shared_processor_pools" "example" { ``` **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` +- 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" @@ -52,4 +48,4 @@ In addition to all argument reference list, you can access the following attribu - `reserved_cores` - (Integer) The amount of reserved cores for the shared processor pool. - `shared_processor_pool_id` - (String) The shared processor pool's unique ID. - `status` - (String) The status of the shared processor pool. - - `status_detail` - (String) The status details of the shared processor pool. \ No newline at end of file + - `status_detail` - (String) The status details of the shared processor pool. From d751593f384c648fd3bddb9b839666ae35df9122 Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Thu, 28 Dec 2023 19:04:05 +0530 Subject: [PATCH 14/16] Catalog-refactor public network-pvm instance snapshot data source and documentation --- .../data_source_ibm_pi_public_network.go | 49 ++++---- .../data_source_ibm_pi_public_network_test.go | 7 +- .../power/data_source_ibm_pi_snapshot.go | 113 +++++++++--------- .../power/data_source_ibm_pi_snapshot_test.go | 10 +- .../docs/d/pi_public_network.html.markdown | 16 +-- website/docs/d/pi_pvm_snapshots.html.markdown | 23 ++-- 6 files changed, 106 insertions(+), 112 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_public_network.go b/ibm/service/power/data_source_ibm_pi_public_network.go index ca5cc380e2..ef8195c964 100644 --- a/ibm/service/power/data_source_ibm_pi_public_network.go +++ b/ibm/service/power/data_source_ibm_pi_public_network.go @@ -4,41 +4,42 @@ package power import ( - //"fmt" "context" + "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" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - - "github.com/IBM-Cloud/power-go-client/clients/instance" - "github.com/IBM-Cloud/power-go-client/helpers" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" ) func DataSourceIBMPIPublicNetwork() *schema.Resource { - return &schema.Resource{ ReadContext: dataSourceIBMPIPublicNetworkRead, 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 - "name": { - Type: schema.TypeString, - Computed: true, + // Attributes + Attr_Name: { + Computed: true, + Description: "The name of the network.", + Type: schema.TypeString, }, - "type": { - Type: schema.TypeString, - Computed: true, + Attr_Type: { + Computed: true, + Description: "The type of VLAN that the network is connected to.", + Type: schema.TypeString, }, - "vlan_id": { - Type: schema.TypeInt, - Computed: true, + Attr_VLanID: { + Computed: true, + Description: "The ID of the VLAN that the network is connected to.", + Type: schema.TypeInt, }, }, } @@ -50,7 +51,7 @@ func dataSourceIBMPIPublicNetworkRead(ctx context.Context, d *schema.ResourceDat return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) networkC := instance.NewIBMPINetworkClient(ctx, sess, cloudInstanceID) networkdata, err := networkC.GetAllPublic() @@ -62,14 +63,14 @@ func dataSourceIBMPIPublicNetworkRead(ctx context.Context, d *schema.ResourceDat } d.SetId(*networkdata.Networks[0].NetworkID) - if networkdata.Networks[0].Type != nil { - d.Set("type", networkdata.Networks[0].Type) - } if networkdata.Networks[0].Name != nil { - d.Set("name", networkdata.Networks[0].Name) + d.Set(Attr_Name, networkdata.Networks[0].Name) + } + if networkdata.Networks[0].Type != nil { + d.Set(Attr_Type, networkdata.Networks[0].Type) } if networkdata.Networks[0].VlanID != nil { - d.Set("vlan_id", networkdata.Networks[0].VlanID) + d.Set(Attr_VLanID, networkdata.Networks[0].VlanID) } return nil diff --git a/ibm/service/power/data_source_ibm_pi_public_network_test.go b/ibm/service/power/data_source_ibm_pi_public_network_test.go index f8c3eb1c5b..3ac39c13a6 100644 --- a/ibm/service/power/data_source_ibm_pi_public_network_test.go +++ b/ibm/service/power/data_source_ibm_pi_public_network_test.go @@ -29,8 +29,7 @@ func TestAccIBMPIPublicNetworkDataSource_basic(t *testing.T) { func testAccCheckIBMPIPublicNetworkDataSourceConfig() string { return fmt.Sprintf(` -data "ibm_pi_public_network" "testacc_ds_public_network" { - pi_cloud_instance_id = "%s" -}`, acc.Pi_cloud_instance_id) - + data "ibm_pi_public_network" "testacc_ds_public_network" { + pi_cloud_instance_id = "%s" + }`, acc.Pi_cloud_instance_id) } diff --git a/ibm/service/power/data_source_ibm_pi_snapshot.go b/ibm/service/power/data_source_ibm_pi_snapshot.go index b852f1024f..ad454cf521 100644 --- a/ibm/service/power/data_source_ibm_pi_snapshot.go +++ b/ibm/service/power/data_source_ibm_pi_snapshot.go @@ -8,7 +8,6 @@ import ( "log" "github.com/IBM-Cloud/power-go-client/clients/instance" - "github.com/IBM-Cloud/power-go-client/helpers" "github.com/IBM-Cloud/power-go-client/power/models" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/hashicorp/go-uuid" @@ -18,65 +17,73 @@ import ( ) func DataSourceIBMPISnapshot() *schema.Resource { - return &schema.Resource{ ReadContext: dataSourceIBMPISnapshotRead, 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, }, - - helpers.PIInstanceName: { - Type: schema.TypeString, + Arg_InstanceName: { + Description: "The unique identifier or name of the instance.", Required: true, + Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, - //Computed Attributes - "pvm_snapshots": { + // Attributes + Attr_PVMSnapshots: { Type: schema.TypeList, Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "id": { - Type: schema.TypeString, - Computed: true, + Attr_Action: { + Computed: true, + Description: "Action performed on the instance snapshot.", + Type: schema.TypeString, }, - "name": { - Type: schema.TypeString, - Computed: true, + Attr_CreationDate: { + Computed: true, + Description: "Date of snapshot creation.", + Type: schema.TypeString, }, - "percent_complete": { - Type: schema.TypeInt, - Computed: true, + Attr_Description: { + Computed: true, + Description: "The description of the snapshot.", + Type: schema.TypeString, }, - - "description": { - Type: schema.TypeString, - Computed: true, + Attr_ID: { + Computed: true, + Description: "The unique identifier of the Power Virtual Machine instance snapshot.", + Type: schema.TypeString, }, - "action": { - Type: schema.TypeString, - Computed: true, + Attr_LastUpdatedDate: { + Computed: true, + Description: "Date of last update.", + Type: schema.TypeString, }, - "status": { - Type: schema.TypeString, - Computed: true, + Attr_Name: { + Computed: true, + Description: "The name of the Power Virtual Machine instance snapshot.", + Type: schema.TypeString, }, - "creation_date": { - Type: schema.TypeString, - Computed: true, + Attr_PercentComplete: { + Computed: true, + Description: "The snapshot completion percentage.", + Type: schema.TypeInt, }, - "last_updated_date": { - Type: schema.TypeString, - Computed: true, + Attr_Status: { + Computed: true, + Description: "The status of the Power Virtual Machine instance snapshot.", + Type: schema.TypeString, }, - "volume_snapshots": { - Type: schema.TypeMap, - Computed: true, + Attr_VolumeSnapshots: { + Computed: true, + Description: "A map of volume snapshots included in the Power Virtual Machine instance snapshot.", + Type: schema.TypeMap, }, }, }, @@ -86,14 +93,13 @@ func DataSourceIBMPISnapshot() *schema.Resource { } func dataSourceIBMPISnapshotRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - sess, err := meta.(conns.ClientSession).IBMPISession() if err != nil { return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) - powerinstancename := d.Get(helpers.PIInstanceName).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) + powerinstancename := d.Get(Arg_InstanceName).(string) snapshot := instance.NewIBMPIInstanceClient(ctx, sess, cloudInstanceID) snapshotData, err := snapshot.GetSnapShotVM(powerinstancename) @@ -103,30 +109,27 @@ func dataSourceIBMPISnapshotRead(ctx context.Context, d *schema.ResourceData, me var clientgenU, _ = uuid.GenerateUUID() d.SetId(clientgenU) - d.Set("pvm_snapshots", flattenPVMSnapshotInstances(snapshotData.Snapshots)) + d.Set(Attr_PVMSnapshots, flattenPVMSnapshotInstances(snapshotData.Snapshots)) return nil - } func flattenPVMSnapshotInstances(list []*models.Snapshot) []map[string]interface{} { - log.Printf("Calling the flattensnapshotinstances call with list %d", len(list)) + log.Printf("Calling the flattenPVMSnapshotInstances call with list %d", len(list)) result := make([]map[string]interface{}, 0, len(list)) for _, i := range list { l := map[string]interface{}{ - "id": *i.SnapshotID, - "name": *i.Name, - "description": i.Description, - "creation_date": i.CreationDate.String(), - "last_updated_date": i.LastUpdateDate.String(), - "action": i.Action, - "percent_complete": i.PercentComplete, - "status": i.Status, - "volume_snapshots": i.VolumeSnapshots, + Attr_Action: i.Action, + Attr_CreationDate: i.CreationDate.String(), + Attr_Description: i.Description, + Attr_ID: *i.SnapshotID, + Attr_LastUpdatedDate: i.LastUpdateDate.String(), + Attr_Name: *i.Name, + Attr_PercentComplete: i.PercentComplete, + Attr_Status: i.Status, + Attr_VolumeSnapshots: i.VolumeSnapshots, } - result = append(result, l) } - return result } diff --git a/ibm/service/power/data_source_ibm_pi_snapshot_test.go b/ibm/service/power/data_source_ibm_pi_snapshot_test.go index 3636fbf048..e5c502c1cb 100644 --- a/ibm/service/power/data_source_ibm_pi_snapshot_test.go +++ b/ibm/service/power/data_source_ibm_pi_snapshot_test.go @@ -29,10 +29,8 @@ func TestAccIBMPISnapshotDataSource_basic(t *testing.T) { func testAccCheckIBMPISnapshotDataSourceConfig() string { return fmt.Sprintf(` - -data "ibm_pi_pvm_snapshots" "testacc_pi_snapshots" { - pi_instance_name = "%s" - pi_cloud_instance_id = "%s" -}`, acc.Pi_instance_name, acc.Pi_cloud_instance_id) - + data "ibm_pi_pvm_snapshots" "testacc_pi_snapshots" { + pi_instance_name = "%s" + pi_cloud_instance_id = "%s" + }`, acc.Pi_instance_name, acc.Pi_cloud_instance_id) } diff --git a/website/docs/d/pi_public_network.html.markdown b/website/docs/d/pi_public_network.html.markdown index 9c00c9d0a3..3dd17e9de2 100644 --- a/website/docs/d/pi_public_network.html.markdown +++ b/website/docs/d/pi_public_network.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_public_network" @@ -8,32 +7,29 @@ description: |- --- # ibm_pi_public_network -Retrieve the details about a public network that is used for your Power Systems Virtual Server instance. For more information, about public network in IBM power virutal server, see [adding or removing a public network +Retrieve the details about a public network that is used for your Power Systems Virtual Server instance. For more information, about public network in IBM power virtual server, see [adding or removing a public network ](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-modifying-server#adding-removing-network). ## Example usage - ```terraform data "ibm_pi_public_network" "ds_public_network" { pi_cloud_instance_id = "49fba6c9-23f8-40bc-9899-aca322ee7d5b" } ``` -**Note** -* 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` +**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" zone = "lon04" } ``` - ## Argument reference Review the argument references that you can specify for your data source. diff --git a/website/docs/d/pi_pvm_snapshots.html.markdown b/website/docs/d/pi_pvm_snapshots.html.markdown index 7a2eeaf5e5..3a5fa6571a 100644 --- a/website/docs/d/pi_pvm_snapshots.html.markdown +++ b/website/docs/d/pi_pvm_snapshots.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_pvm_snapshots" @@ -11,7 +10,6 @@ description: |- Retrieve information about a Power Systems Virtual Server instance snapshots. For more information, about Power Virtual Server PVM instance snapshots, 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_pvm_snapshots" "ds_pvm_snapshots" { pi_instance_name = "terraform-test-instance" @@ -19,14 +17,13 @@ data "ibm_pi_pvm_snapshots" "ds_pvm_snapshots" { } ``` -**Note** -* 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` +**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: - +Example usage: ```terraform provider "ibm" { region = "lon" @@ -37,8 +34,8 @@ data "ibm_pi_pvm_snapshots" "ds_pvm_snapshots" { ## Argument reference Review the argument references that you can specify for your data source. -- `pi_instance_name` - (Required, String) The name of the instance. - `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. +- `pi_instance_name` - (Required, String) The unique identifier or name of the instance. ## Attribute reference In addition to all argument reference list, you can access the following attribute references after your data source is created. @@ -47,11 +44,11 @@ In addition to all argument reference list, you can access the following attribu Nested scheme for `pvm_snapshots`: - `action` - (String) Action performed on the instance snapshot. - - `creation_date` - (String) The creation date. + - `creation_date` - (String) Date of snapshot creation. - `description` - (String) The description of the snapshot. - `id` - (String) The unique identifier of the Power Virtual Machine instance snapshot. - - `last_updated_date` - (String) The last update date. + - `last_updated_date` - (String) Date of last update. - `name` - (String) The name of the Power Virtual Machine instance snapshot. - `percent_complete` - (Integer) The snapshot completion percentage. - `status` - (String) The status of the Power Virtual Machine instance snapshot. - - `volume_snapshots` - (Map) A map of volume snapshots included in the Power Virtual Machine instance snapshot. \ No newline at end of file + - `volume_snapshots` - (Map) A map of volume snapshots included in the Power Virtual Machine instance snapshot. From 246110f1e16b078b19cd8e5df4aa30646640b6f0 Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Thu, 28 Dec 2023 19:06:13 +0530 Subject: [PATCH 15/16] Catalog-refactor cloud instance snapshot data source and documentation --- .../data_source_ibm_pi_cloud_instance.go | 183 ++++++++++-------- .../data_source_ibm_pi_cloud_instance_test.go | 11 +- .../docs/d/pi_cloud_instance.html.markdown | 15 +- 3 files changed, 108 insertions(+), 101 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_cloud_instance.go b/ibm/service/power/data_source_ibm_pi_cloud_instance.go index f9fa86dcd5..4a09bf2768 100644 --- a/ibm/service/power/data_source_ibm_pi_cloud_instance.go +++ b/ibm/service/power/data_source_ibm_pi_cloud_instance.go @@ -6,96 +6,111 @@ package power import ( "context" - "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" - "github.com/IBM-Cloud/power-go-client/clients/instance" - "github.com/IBM-Cloud/power-go-client/helpers" "github.com/IBM-Cloud/power-go-client/power/models" "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" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) func DataSourceIBMPICloudInstance() *schema.Resource { - return &schema.Resource{ ReadContext: dataSourceIBMPICloudInstanceRead, 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, }, - // Start of Computed Attributes - "enabled": { - Type: schema.TypeBool, - Computed: true, - }, - "tenant_id": { - Type: schema.TypeString, - Computed: true, - }, - "region": { - Type: schema.TypeString, - Computed: true, - }, - "capabilities": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "total_processors_consumed": { - Type: schema.TypeFloat, - Computed: true, + // Attributes + Attr_Capabilities: { + Computed: true, + Description: "Lists the capabilities for this cloud instance.", + Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeList, }, - "total_instances": { - Type: schema.TypeFloat, - Computed: true, + Attr_Enabled: { + Computed: true, + Description: "Indicates whether the tenant is enabled.", + Type: schema.TypeBool, }, - "total_memory_consumed": { - Type: schema.TypeFloat, - Computed: true, - }, - "total_ssd_storage_consumed": { - Type: schema.TypeFloat, - Computed: true, - }, - "total_standard_storage_consumed": { - Type: schema.TypeFloat, - Computed: true, - }, - "pvm_instances": { - Type: schema.TypeList, - Computed: true, + Attr_PVMInstances: { + Computed: true, + Description: "PVM instances owned by the Cloud Instance.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "id": { - Type: schema.TypeString, - Computed: true, + Attr_CreationDate: { + Computed: true, + Description: "Date of PVM instance creation.", + Type: schema.TypeString, }, - "name": { - Type: schema.TypeString, - Computed: true, + Attr_Href: { + Computed: true, + Description: "Link to Cloud Instance resource.", + Type: schema.TypeString, }, - "href": { - Type: schema.TypeString, - Computed: true, + Attr_ID: { + Computed: true, + Description: "PVM Instance ID.", + Type: schema.TypeString, }, - "status": { - Type: schema.TypeString, - Computed: true, + Attr_Name: { + Computed: true, + Description: "Name of the server.", + Type: schema.TypeString, }, - "systype": { - Type: schema.TypeString, - Computed: true, + Attr_Status: { + Computed: true, + Description: "The status of the instance.", + Type: schema.TypeString, }, - "creation_date": { - Type: schema.TypeString, - Computed: true, + Attr_SysType: { + Computed: true, + Description: "System type used to host the instance.", + Type: schema.TypeString, }, }, }, + Type: schema.TypeList, + }, + Attr_Region: { + Computed: true, + Description: "The region the cloud instance lives.", + Type: schema.TypeString, + }, + Attr_TenantID: { + Computed: true, + Description: "The tenant ID that owns this cloud instance.", + Type: schema.TypeString, + }, + Attr_TotalInstances: { + Computed: true, + Description: "The count of lpars that belong to this specific cloud instance.", + Type: schema.TypeFloat, + }, + Attr_TotalMemoryConsumed: { + Computed: true, + Description: "The total memory consumed by this service instance.", + Type: schema.TypeFloat, + }, + Attr_TotalProcessorsConsumed: { + Computed: true, + Description: "The total processors consumed by this service instance.", + Type: schema.TypeFloat, + }, + Attr_TotalSSDStorageConsumed: { + Computed: true, + Description: "The total SSD Storage consumed by this service instance.", + Type: schema.TypeFloat, + }, + Attr_TotalStandardStorageConsumed: { + Computed: true, + Description: "The total Standard Storage consumed by this service instance.", + Type: schema.TypeFloat, }, }, } @@ -107,7 +122,7 @@ func dataSourceIBMPICloudInstanceRead(ctx context.Context, d *schema.ResourceDat return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) cloud_instance := instance.NewIBMPICloudInstanceClient(ctx, sess, cloudInstanceID) cloud_instance_data, err := cloud_instance.Get(cloudInstanceID) @@ -116,35 +131,33 @@ func dataSourceIBMPICloudInstanceRead(ctx context.Context, d *schema.ResourceDat } d.SetId(*cloud_instance_data.CloudInstanceID) - d.Set("tenant_id", (cloud_instance_data.TenantID)) - d.Set("enabled", cloud_instance_data.Enabled) - d.Set("region", cloud_instance_data.Region) - d.Set("capabilities", cloud_instance_data.Capabilities) - d.Set("pvm_instances", flattenpvminstances(cloud_instance_data.PvmInstances)) - d.Set("total_ssd_storage_consumed", cloud_instance_data.Usage.StorageSSD) - d.Set("total_instances", cloud_instance_data.Usage.Instances) - d.Set("total_standard_storage_consumed", cloud_instance_data.Usage.StorageStandard) - d.Set("total_processors_consumed", cloud_instance_data.Usage.Processors) - d.Set("total_memory_consumed", cloud_instance_data.Usage.Memory) - return nil + d.Set(Attr_Capabilities, cloud_instance_data.Capabilities) + d.Set(Attr_Enabled, cloud_instance_data.Enabled) + d.Set(Attr_PVMInstances, flattenpvminstances(cloud_instance_data.PvmInstances)) + d.Set(Attr_Region, cloud_instance_data.Region) + d.Set(Attr_TenantID, (cloud_instance_data.TenantID)) + d.Set(Attr_TotalInstances, cloud_instance_data.Usage.Instances) + d.Set(Attr_TotalMemoryConsumed, cloud_instance_data.Usage.Memory) + d.Set(Attr_TotalProcessorsConsumed, cloud_instance_data.Usage.Processors) + d.Set(Attr_TotalSSDStorageConsumed, cloud_instance_data.Usage.StorageSSD) + d.Set(Attr_TotalStandardStorageConsumed, cloud_instance_data.Usage.StorageStandard) + return nil } func flattenpvminstances(list []*models.PVMInstanceReference) []map[string]interface{} { pvms := make([]map[string]interface{}, 0) for _, lpars := range list { - l := map[string]interface{}{ - "id": *lpars.PvmInstanceID, - "name": *lpars.ServerName, - "href": *lpars.Href, - "status": *lpars.Status, - "systype": lpars.SysType, - "creation_date": lpars.CreationDate.String(), + Attr_CreationDate: lpars.CreationDate.String(), + Attr_ID: *lpars.PvmInstanceID, + Attr_Href: *lpars.Href, + Attr_Name: *lpars.ServerName, + Attr_Status: *lpars.Status, + Attr_SysType: lpars.SysType, } pvms = append(pvms, l) - } return pvms } diff --git a/ibm/service/power/data_source_ibm_pi_cloud_instance_test.go b/ibm/service/power/data_source_ibm_pi_cloud_instance_test.go index 1d80d59337..d2f0b69db9 100644 --- a/ibm/service/power/data_source_ibm_pi_cloud_instance_test.go +++ b/ibm/service/power/data_source_ibm_pi_cloud_instance_test.go @@ -13,7 +13,6 @@ import ( ) func TestAccIBMPICloudInstanceDataSource_basic(t *testing.T) { - resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -29,10 +28,8 @@ func TestAccIBMPICloudInstanceDataSource_basic(t *testing.T) { } func testAccCheckIBMPICloudInstanceDataSourceConfig() string { - return fmt.Sprintf(` - -data "ibm_pi_cloud_instance" "testacc_ds_cloud_instance" { - pi_cloud_instance_id = "%s" -}`, acc.Pi_cloud_instance_id) - + return fmt.Sprintf(` + data "ibm_pi_cloud_instance" "testacc_ds_cloud_instance" { + pi_cloud_instance_id = "%s" + }`, acc.Pi_cloud_instance_id) } diff --git a/website/docs/d/pi_cloud_instance.html.markdown b/website/docs/d/pi_cloud_instance.html.markdown index 5e65926b84..32dcbb43ba 100644 --- a/website/docs/d/pi_cloud_instance.html.markdown +++ b/website/docs/d/pi_cloud_instance.html.markdown @@ -10,21 +10,19 @@ description: |- Retrieve information about an existing IBM Power Virtual Server Cloud Instance 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_cloud_instance" "ds_cloud_instance" { pi_cloud_instance_id = "49fba6c9-23f8-40bc-9899-aca322ee7d5b" } ``` -## 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` +**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" @@ -46,7 +44,7 @@ In addition to the argument reference list, you can access the following attribu - `pvm_instances` - (List) PVM instances owned by the Cloud Instance. Nested scheme for `pvm_instances`: - - `creation_date` - (String) Date/Time of PVM creation. + - `creation_date` - (String) Date of PVM instance creation. - `href` - (String) Link to Cloud Instance resource. - `id` - (String) PVM Instance ID. - `name` - (String) Name of the server. @@ -59,4 +57,3 @@ In addition to the argument reference list, you can access the following attribu - `total_processors_consumed` - (String) The total processors consumed by this service instance. - `total_ssd_storage_consumed` - (String) The total SSD Storage consumed by this service instance. - `total_standard_storage_consumed` - (String) The total Standard Storage consumed by this service instance. - From 5c5d08e99dff18f7fea69ec8cc7949df8a692e82 Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Thu, 28 Dec 2023 20:04:45 +0530 Subject: [PATCH 16/16] Catalog-refactor constants --- ibm/service/power/ibm_pi_constants.go | 299 +++++++++++++++++++++----- 1 file changed, 249 insertions(+), 50 deletions(-) diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index 8e66a4bd83..7229f23831 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -3,18 +3,238 @@ package power import "time" const ( - // used by all - Arg_CloudInstanceID = "pi_cloud_instance_id" + // Arguments + Arg_CloudConnectionName = "pi_cloud_connection_name" + Arg_CloudInstanceID = "pi_cloud_instance_id" + Arg_ImageName = "pi_image_name" + Arg_InstanceName = "pi_instance_name" + Arg_Key = "pi_ssh_key" + Arg_KeyName = "pi_key_name" + Arg_NetworkName = "pi_network_name" + Arg_PlacementGroupName = "pi_placement_group_name" + Arg_SAP = "sap" + Arg_SAPProfileID = "pi_sap_profile_id" + Arg_SPPPlacementGroupID = "pi_spp_placement_group_id" + Arg_SPPPlacementGroupName = "pi_spp_placement_group_name" + Arg_SPPPlacementGroupPolicy = "pi_spp_placement_group_policy" + Arg_SharedProcessorPoolHostGroup = "pi_shared_processor_pool_host_group" + Arg_SharedProcessorPoolID = "pi_shared_processor_pool_id" + Arg_SharedProcessorPoolName = "pi_shared_processor_pool_name" + Arg_SharedProcessorPoolPlacementGroupID = "pi_shared_processor_pool_placement_group_id" + Arg_SharedProcessorPoolReservedCores = "pi_shared_processor_pool_reserved_cores" + Arg_StoragePool = "pi_storage_pool" + Arg_StorageType = "pi_storage_type" + Arg_VTL = "vtl" + Arg_VolumeGroupID = "pi_volume_group_id" + Arg_VolumeID = "pi_volume_id" + Arg_VolumeOnboardingID = "pi_volume_onboarding_id" - // Keys - Arg_KeyName = "pi_key_name" - Arg_Key = "pi_ssh_key" + // Attributes + Attr_AccessConfig = "access_config" + Attr_Action = "action" + Attr_Addresses = "addresses" + Attr_AllocatedCores = "allocated_cores" + Attr_Architecture = "architecture" + Attr_Auxiliary = "auxiliary" + Attr_AuxiliaryChangedVolumeName = "auxiliary_changed_volume_name" + Attr_AuxiliaryVolumeName = "auxiliary_volume_name" + Attr_AvailabilityZone = "availability_zone" + Attr_AvailableCores = "available_cores" + Attr_AvailableIPCount = "available_ip_count" + Attr_BootVolumeID = "boot_volume_id" + Attr_Bootable = "bootable" + Attr_CIDR = "cidr" + Attr_CPUs = "cpus" + Attr_CRN = "crn" + Attr_Capabilities = "capabilities" + Attr_Capacity = "capacity" + Attr_Certified = "certified" + Attr_ClassicEnabled = "classic_enabled" + Attr_CloudConnectionID = "cloud_connection_id" + Attr_CloudInstanceID = "cloud_instance_id" + Attr_CloudInstances = "cloud_instances" + Attr_Code = "code" + Attr_ConnectionMode = "connection_mode" + Attr_Connections = "connections" + Attr_ConsistencyGroupName = "consistency_group_name" + Attr_ConsoleLanguages = "console_languages" + Attr_ContainerFormat = "container_format" + Attr_CopyRate = "copy_rate" + Attr_CopyType = "copy_type" + Attr_CoreMemoryRatio = "core_memory_ratio" + Attr_Cores = "cores" + Attr_CreateTime = "create_time" + Attr_CreationDate = "creation_date" + Attr_CyclePeriodSeconds = "cycle_period_seconds" + Attr_CyclingMode = "cycling_mode" + Attr_DNS = "dns" + Attr_Datacenters = "datacenters" + Attr_Default = "default" + Attr_DeploymentType = "deployment_type" + Attr_Description = "description" + Attr_DisasterRecoveryLocations = "disaster_recovery_locations" + Attr_DiskFormat = "disk_format" + Attr_DiskType = "disk_type" + Attr_Enabled = "enabled" + Attr_Endianness = "endianness" + Attr_ExternalIP = "external_ip" + Attr_FailureMessage = "failure_message" + Attr_FlashCopyMappings = "flash_copy_mappings" + Attr_FlashCopyName = "flash_copy_name" + Attr_FreezeTime = "freeze_time" + Attr_Gateway = "gateway" + Attr_GlobalRouting = "global_routing" + Attr_GreDestinationAddress = "gre_destination_address" + Attr_GreSourceAddress = "gre_source_address" + Attr_GroupID = "group_id" + Attr_HealthStatus = "health_status" + Attr_HostID = "host_id" + Attr_Href = "href" + Attr_Hypervisor = "hypervisor" + Attr_HypervisorType = "hypervisor_type" + Attr_IBMIPAddress = "ibm_ip_address" + Attr_ID = "id" + Attr_IP = "ip" + Attr_IPAddress = "ipaddress" + Attr_IPOctet = "ipoctet" + Attr_ImageID = "image_id" + Attr_ImageInfo = "image_info" + Attr_ImageType = "image_type" + Attr_Images = "images" + Attr_InputVolumes = "input_volumes" + Attr_InstanceSnapshots = "instance_snapshots" + Attr_InstanceVolumes = "instance_volumes" + Attr_Instances = "instances" + Attr_IsActive = "is_active" + Attr_Jumbo = "jumbo" + Attr_Key = "key" + Attr_KeyCreationDate = "creation_date" + Attr_KeyID = "key_id" + Attr_KeyName = "name" + Attr_Keys = "keys" + Attr_Language = "language" + Attr_LastUpdateDate = "last_update_date" + Attr_LastUpdatedDate = "last_updated_date" + Attr_Leases = "leases" + Attr_LicenseRepositoryCapacity = "license_repository_capacity" + Attr_Location = "location" + Attr_MTU = "mtu" + Attr_MacAddress = "macaddress" + Attr_MasterChangedVolumeName = "master_changed_volume_name" + Attr_MasterVolumeName = "master_volume_name" + Attr_Max = "max" + Attr_MaxAllocationSize = "max_allocation_size" + Attr_MaxAvailable = "max_available" + Attr_MaxCoresAvailable = "max_cores_available" + Attr_MaxMem = "maxmem" + Attr_MaxMemoryAvailable = "max_memory_available" + Attr_MaxProc = "maxproc" + Attr_MaxVirtualCores = "max_virtual_cores" + Attr_MaximumStorageAllocation = "max_storage_allocation" + Attr_Members = "members" + Attr_Memory = "memory" + Attr_Message = "message" + Attr_Metered = "metered" + Attr_Min = "min" + Attr_MinMem = "minmem" + Attr_MinProc = "minproc" + Attr_MinVirtualCores = "min_virtual_cores" + Attr_MirroringState = "mirroring_state" + Attr_Name = "name" + Attr_NetworkID = "network_id" + Attr_NetworkName = "network_name" + Attr_NetworkPorts = "network_ports" + Attr_Networks = "networks" + Attr_NumberOfVolumes = "number_of_volumes" + Attr_Onboardings = "onboardings" + Attr_OperatingSystem = "operating_system" + Attr_PVMInstanceID = "pvm_instance_id" + Attr_PVMInstances = "pvm_instances" + Attr_PVMSnapshots = "pvm_snapshots" + Attr_PercentComplete = "percent_complete" + Attr_PinPolicy = "pin_policy" + Attr_PlacementGroupID = "placement_group_id" + Attr_PlacementGroups = "placement_groups" + Attr_Policy = "policy" + Attr_Pool = "pool" + Attr_PoolName = "pool_name" + Attr_Port = "port" + Attr_PortID = "portid" + Attr_PrimaryRole = "primary_role" + Attr_ProcType = "proctype" + Attr_Processors = "processors" + Attr_ProfileID = "profile_id" + Attr_Profiles = "profiles" + Attr_Progress = "progress" + Attr_PublicIP = "public_ip" + Attr_Region = "region" + Attr_RemoteCopyID = "remote_copy_id" + Attr_RemoteCopyRelationshipNames = "remote_copy_relationship_names" + Attr_RemoteCopyRelationships = "remote_copy_relationships" + Attr_ReplicationEnabled = "replication_enabled" + Attr_ReplicationSites = "replication_sites" + Attr_ReplicationStatus = "replication_status" + Attr_ReplicationType = "replication_type" + Attr_ReservedCores = "reserved_cores" + Attr_ResultsOnboardedVolumes = "results_onboarded_volumes" + Attr_ResultsVolumeOnboardingFailures = "results_volume_onboarding_failures" + Attr_SPPPlacementGroups = "spp_placement_groups" + Attr_SSHKey = "ssh_key" + Attr_Shareable = "shreable" + Attr_SharedCoreRatio = "shared_core_ratio" + Attr_SharedProcessorPool = "shared_processor_pool" + Attr_SharedProcessorPoolID = "shared_processor_pool_id" + Attr_SharedProcessorPoolPlacementGroups = "spp_placement_groups" + Attr_SharedProcessorPoolStatus = "status" + Attr_SharedProcessorPools = "shared_processor_pools" + Attr_Size = "size" + Attr_SourceVolumeName = "source_volume_name" + Attr_Speed = "speed" + Attr_StartTime = "start_time" + Attr_State = "state" + Attr_Status = "status" + Attr_StatusDescriptionErrors = "status_description_errors" + Attr_StatusDetail = "status_detail" + Attr_StoragePool = "storage_pool" + Attr_StoragePoolAffinity = "storage_pool_affinity" + Attr_StoragePoolsCapacity = "storage_pools_capacity" + Attr_StorageType = "storage_type" + Attr_StorageTypesCapacity = "storage_types_capacity" + Attr_Synchronized = "synchronized" + Attr_SysType = "systype" + Attr_SystemPoolName = "system_pool_name" + Attr_SystemPools = "system_pools" + Attr_Systems = "systems" + Attr_TargetVolumeName = "target_volume_name" + Attr_TenantID = "tenant_id" + Attr_TenantName = "tenant_name" + Attr_TotalCapacity = "total_capacity" + Attr_TotalInstances = "total_instances" + Attr_TotalMemoryConsumed = "total_memory_consumed" + Attr_TotalProcessorsConsumed = "total_processors_consumed" + Attr_TotalSSDStorageConsumed = "total_ssd_storage_consumed" + Attr_TotalStandardStorageConsumed = "total_standard_storage_consumed" + Attr_Type = "type" + Attr_URL = "url" + Attr_Uncapped = "uncapped" + Attr_UsedIPCount = "used_ip_count" + Attr_UsedIPPercent = "used_ip_percent" + Attr_UserIPAddress = "user_ip_address" + Attr_VCPUs = "vcpus" + Attr_VLanID = "vlan_id" + Attr_VPCCRNs = "vpc_crns" + Attr_VPCEnabled = "vpc_enabled" + Attr_VirtualCoresAssigned = "virtual_cores_assigned" + Attr_VolumeGroupName = "volume_group_name" + Attr_VolumeGroups = "volume_groups" + Attr_VolumeIDs = "volume_ids" + Attr_VolumePool = "volume_pool" + Attr_VolumeSnapshots = "volume_snapshots" + Attr_Volumes = "volumes" + Attr_WWN = "wwn" + Attr_Workspaces = "workspaces" - Attr_KeyID = "key_id" - Attr_Keys = "keys" - Attr_KeyCreationDate = "creation_date" - Attr_Key = "ssh_key" - Attr_KeyName = "name" + // TODO: Second Half Cleanup, remove extra variables // SAP Profile PISAPProfiles = "profiles" @@ -47,10 +267,6 @@ const ( Arg_PVMInstanceActionType = "pi_action" Arg_PVMInstanceHealthStatus = "pi_health_status" - Attr_Status = "status" - Attr_Progress = "progress" - Attr_HealthStatus = "health_status" - PVMInstanceHealthOk = "OK" PVMInstanceHealthWarning = "WARNING" @@ -58,14 +274,24 @@ const ( warningTimeOut = 60 * time.Second activeTimeOut = 2 * time.Minute // power service instance capabilities - CUSTOM_VIRTUAL_CORES = "custom-virtualcores" - PIInstanceDeploymentType = "pi_deployment_type" - PIInstanceNetwork = "pi_network" - PIInstanceStoragePool = "pi_storage_pool" - PISAPInstanceProfileID = "pi_sap_profile_id" - PISAPInstanceDeploymentType = "pi_sap_deployment_type" - PIInstanceStoragePoolAffinity = "pi_storage_pool_affinity" - Arg_PIInstanceSharedProcessorPool = "pi_shared_processor_pool" + CUSTOM_VIRTUAL_CORES = "custom-virtualcores" + + //Arg_CloudInstanceID = "pi_cloud_instance_id" + PIInstanceDeploymentType = "pi_deployment_type" + PIInstanceMigratable = "pi_migratable" + PIInstanceNetwork = "pi_network" + PIInstanceLicenseRepositoryCapacity = "pi_license_repository_capacity" + PIInstanceStoragePool = "pi_storage_pool" + PIInstanceStorageType = "pi_storage_type" + PISAPInstanceProfileID = "pi_sap_profile_id" + PISAPInstanceDeploymentType = "pi_sap_deployment_type" + PIInstanceSharedProcessorPool = "pi_shared_processor_pool" + PIInstanceStorageConnection = "pi_storage_connection" + PIInstanceStoragePoolAffinity = "pi_storage_pool_affinity" + + PIInstanceUserData = "pi_user_data" + PIInstanceVolumeIds = "pi_volume_ids" + Attr_PIInstanceSharedProcessorPool = "shared_processor_pool" Attr_PIInstanceSharedProcessorPoolID = "shared_processor_pool_id" @@ -104,37 +330,10 @@ const ( // Cloud Connections PICloudConnectionTransitEnabled = "pi_cloud_connection_transit_enabled" - // Shared Processor Pool - Arg_SharedProcessorPoolName = "pi_shared_processor_pool_name" - Arg_SharedProcessorPoolHostGroup = "pi_shared_processor_pool_host_group" - Arg_SharedProcessorPoolPlacementGroupID = "pi_shared_processor_pool_placement_group_id" - Arg_SharedProcessorPoolReservedCores = "pi_shared_processor_pool_reserved_cores" - Arg_SharedProcessorPoolID = "pi_shared_processor_pool_id" - Attr_SharedProcessorPoolID = "shared_processor_pool_id" - Attr_SharedProcessorPoolName = "name" - Attr_SharedProcessorPoolReservedCores = "reserved_cores" - Attr_SharedProcessorPoolAvailableCores = "available_cores" - Attr_SharedProcessorPoolAllocatedCores = "allocated_cores" - Attr_SharedProcessorPoolHostID = "host_id" - Attr_SharedProcessorPoolStatus = "status" - Attr_SharedProcessorPoolStatusDetail = "status_detail" - Attr_SharedProcessorPoolPlacementGroups = "spp_placement_groups" - Attr_SharedProcessorPoolInstances = "instances" - Attr_SharedProcessorPoolInstanceCpus = "cpus" - Attr_SharedProcessorPoolInstanceUncapped = "uncapped" - Attr_SharedProcessorPoolInstanceAvailabilityZone = "availability_zone" - Attr_SharedProcessorPoolInstanceId = "id" - Attr_SharedProcessorPoolInstanceMemory = "memory" - Attr_SharedProcessorPoolInstanceName = "name" - Attr_SharedProcessorPoolInstanceStatus = "status" - Attr_SharedProcessorPoolInstanceVcpus = "vcpus" - // SPP Placement Group - Arg_SPPPlacementGroupName = "pi_spp_placement_group_name" - Arg_SPPPlacementGroupPolicy = "pi_spp_placement_group_policy" + Attr_SPPPlacementGroupID = "spp_placement_group_id" Attr_SPPPlacementGroupMembers = "members" - Arg_SPPPlacementGroupID = "pi_spp_placement_group_id" Attr_SPPPlacementGroupPolicy = "policy" Attr_SPPPlacementGroupName = "name"