Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor powervs terraform data sources and documentation #21

Closed
wants to merge 53 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
821fe58
Refactor catalog images data source and documentation
ismirlia Dec 22, 2023
60311fe
Refactor cloud connection data source and documentation
ismirlia Dec 22, 2023
f3150c2
Refactor cloud connections data source and documentation
ismirlia Dec 22, 2023
7d40297
Refactor cloud instance data source and documentation
ismirlia Dec 22, 2023
232df2d
Refactor datacenter data source and documentation
ismirlia Dec 22, 2023
67fbd77
Refactor datacenters data source and documentation
ismirlia Dec 22, 2023
48a8e4e
Refactor dhcp data source and documentation
ismirlia Dec 22, 2023
cdfccf8
Refactor dhcps data source and documentation
ismirlia Dec 22, 2023
7813b38
Refactor disaster recovery location data source and documentation
ismirlia Dec 22, 2023
c9751db
Refactor disaster recovery locations data source and documentation
ismirlia Dec 22, 2023
b22d71e
Refactor image data source and documentation
ismirlia Dec 22, 2023
c0b81a6
Refactor images data source and documentation
ismirlia Dec 22, 2023
f085fae
Refactor instance data source and documentation
ismirlia Dec 22, 2023
af10e10
Refactor instance console languages data source and documentation
ismirlia Dec 22, 2023
116f691
Refactor instance ip data source and documentation
ismirlia Dec 22, 2023
7ce7de9
Refactor instance volumes data source and documentation
ismirlia Dec 22, 2023
4f51004
Refactor instances data source and documentation
ismirlia Dec 22, 2023
31fc40e
Refactor ssh key data source and documentation
ismirlia Dec 22, 2023
08b4583
Refactor ssh keys data source and documentation
ismirlia Dec 22, 2023
a9cfb17
Refactor network data source and documentation
ismirlia Dec 22, 2023
ab81f4a
Refactor network port data source and documentation
ismirlia Dec 22, 2023
ba34029
Refactor placement group data source and documentation
ismirlia Dec 22, 2023
cf497a2
Refactor placement groups data source and documentation
ismirlia Dec 22, 2023
4cfa23a
Refactor public network data source and documentation
ismirlia Dec 22, 2023
1e288fd
Refactor sap profile data source and documentation
ismirlia Dec 22, 2023
f09ceac
Refactor sap profiles data source and documentation
ismirlia Dec 22, 2023
e333ea5
Refactor shared processor pool data source and documentation
ismirlia Dec 22, 2023
1e25cce
Refactor shared processor pools data source and documentation
ismirlia Dec 22, 2023
31f3c1b
Refactor pvm instance snapshot data source and documentation
ismirlia Dec 22, 2023
cd38e55
Refactor instance snapshots data source and documentation
ismirlia Dec 22, 2023
761571a
Refactor spp placement group data source and documentation
ismirlia Dec 22, 2023
153aac3
Refactor spp placement groups data source and documentation
ismirlia Dec 22, 2023
99dadb8
Refactor storage pool capacity data source and documentation
ismirlia Dec 22, 2023
6dec01f
Refactor storage pools capacity data source and documentation
ismirlia Dec 22, 2023
b71c474
Refactor storage type capacity data source and documentation
ismirlia Dec 22, 2023
4d35895
Refactor storage types capacity data source and documentation
ismirlia Dec 22, 2023
571dab0
Refactor system pools data source and documentation
ismirlia Dec 22, 2023
303ef64
Refactor tenant data source and documentation
ismirlia Dec 22, 2023
6946dad
Refactor volume data source and documentation
ismirlia Dec 22, 2023
e596ce8
Refactor volume flash copy mappings data source and documentation
ismirlia Dec 22, 2023
5a16148
Refactor volume group data source and documentation
ismirlia Dec 22, 2023
be6b874
Refactor volume group details data source and documentation
ismirlia Dec 22, 2023
b32dd29
Refactor volume group remote copy relationships data source and docum…
ismirlia Dec 22, 2023
4b09003
Refactor volume group storage details details data source and documen…
ismirlia Dec 22, 2023
dea425b
Refactor volume groups data source and documentation
ismirlia Dec 22, 2023
5920ca9
Refactor volume groups details data source and documentation
ismirlia Dec 22, 2023
edda96c
Refactor onboarding data source and documentation
ismirlia Dec 22, 2023
43ec6cb
Refactor volume onboardings data source and documentation
ismirlia Dec 22, 2023
579a41c
Refactor volume remote copy relationship data source and documentation
ismirlia Dec 22, 2023
23a731b
Refactor workspace data source and documentation
ismirlia Dec 22, 2023
5cbc03f
Refactor workspaces data source and documentation
ismirlia Dec 22, 2023
6db1622
Add argument and attribute constants
ismirlia Dec 22, 2023
5c81458
Update resource constant variables
ismirlia Dec 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
250 changes: 134 additions & 116 deletions ibm/service/power/data_source_ibm_pi_catalog_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
Expand All @@ -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)
Expand All @@ -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
}
36 changes: 16 additions & 20 deletions ibm/service/power/data_source_ibm_pi_catalog_images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading
Loading