Skip to content

Commit

Permalink
Add Storage connection to datasource and resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Diptipowervs authored and michaelkad committed Apr 24, 2024
1 parent 6c7c7d9 commit 2ad486a
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 52 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.19

require (
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240216115622-a311507b4b5b
github.com/IBM-Cloud/power-go-client v1.6.0
github.com/IBM-Cloud/power-go-client v1.6.0-beta9
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca
github.com/IBM/appconfiguration-go-admin-sdk v0.3.0
github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f
Expand Down Expand Up @@ -65,6 +65,7 @@ require (
github.com/IBM/go-sdk-core v1.1.0
github.com/IBM/mqcloud-go-sdk v0.0.4
github.com/IBM/sarama v1.41.2
github.com/IBM/vmware-go-sdk v0.1.2
github.com/stretchr/testify v1.9.0
k8s.io/utils v0.0.0-20230313181309-38a27ef9d749
sigs.k8s.io/controller-runtime v0.14.1
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ github.com/IBM-Cloud/bluemix-go v0.0.0-20240402122236-5c5b994a3f1a/go.mod h1:/7h
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240216115622-a311507b4b5b h1:Wnq0BuprazpP41+nQlRpxpmAs8+8jyOqU50KrvFdJQ4=
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240216115622-a311507b4b5b/go.mod h1:xUQL9SGAjoZFd4GNjrjjtEpjpkgU7RFXRyHesbKTjiY=
github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.5.3/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs=
github.com/IBM-Cloud/power-go-client v1.6.0 h1:X+QX+WSF66+aouyaf4r+IeBLXUurAJj9+Bd+vH7G5I0=
github.com/IBM-Cloud/power-go-client v1.6.0/go.mod h1:0ad5Lcq1utoYVJx0uqooMjCpUaYaK0ItP9QJYtY6k0Y=
github.com/IBM-Cloud/power-go-client v1.6.0-beta9 h1:yMF53vAVoxapFEqJEIFCqx8bAjC/ZA6gbPqId3Gj4NI=
github.com/IBM-Cloud/power-go-client v1.6.0-beta9/go.mod h1:ucyaXsQxyssFFIbWT01uAA5784aKcU7u+q31yu04Rs4=
github.com/IBM-Cloud/softlayer-go v1.0.5-tf h1:koUAyF9b6X78lLLruGYPSOmrfY2YcGYKOj/Ug9nbKNw=
github.com/IBM-Cloud/softlayer-go v1.0.5-tf/go.mod h1:6HepcfAXROz0Rf63krk5hPZyHT6qyx2MNvYyHof7ik4=
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca h1:crniVcf+YcmgF03NmmfonXwSQ73oJF+IohFYBwknMxs=
Expand Down Expand Up @@ -172,6 +172,8 @@ github.com/IBM/schematics-go-sdk v0.2.3 h1:lgTt0Sbudii3cuSk1YSQgrtiZAXDbBABAoVj3
github.com/IBM/schematics-go-sdk v0.2.3/go.mod h1:Tw2OSAPdpC69AxcwoyqcYYaGTTW6YpERF9uNEU+BFRQ=
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.4 h1:xa9e+POVqaXxXHXkSMCOVAbKdUNEu86jQmo5hcpd+L4=
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.4/go.mod h1:5gq8D8uWOIbqOm1uztay6lpOysgJaxxEsaVZLWGWb40=
github.com/IBM/vmware-go-sdk v0.1.2 h1:5lKWFyInWz9e2hwGsoFTEoLa1jYkD30SReN0fQ10w9M=
github.com/IBM/vmware-go-sdk v0.1.2/go.mod h1:2UGPBJju3jiv5VKKBBm9a5L6bzF/aJdKOKAzJ7HaOjA=
github.com/IBM/vpc-beta-go-sdk v0.6.0 h1:wfM3AcW3zOM3xsRtZ+EA6+sESlGUjQ6Yf4n5QQyz4uc=
github.com/IBM/vpc-beta-go-sdk v0.6.0/go.mod h1:fzHDAQIqH/5yJmYsKodKHLcqxMDT+yfH6vZjdiw8CQA=
github.com/IBM/vpc-go-sdk v0.50.0 h1:+vnXYK0FXFXYqaS/5/X1XEqH0bbRotkzkerRk21ZEjE=
Expand Down
46 changes: 25 additions & 21 deletions ibm/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,37 +188,38 @@ var (
// For Power Colo

var (
Pi_auxiliary_volume_name string
Pi_cloud_instance_id string
Pi_dhcp_id string
Pi_image string
Pi_sap_image string
Pi_image_bucket_name string
Pi_image_bucket_file_name string
Pi_image_bucket_access_key string
Pi_image_bucket_secret_key string
Pi_image_bucket_file_name string
Pi_image_bucket_name string
Pi_image_bucket_region string
Pi_image_bucket_secret_key string
Pi_instance_name string
Pi_key_name string
Pi_volume_name string
Pi_volume_id string
Pi_network_name string
Pi_placement_group_name string
Pi_replication_volume_name string
Pi_volume_onboarding_source_crn string
Pi_auxiliary_volume_name string
Pi_volume_group_name string
Pi_resource_group_id string
Pi_sap_image string
Pi_shared_processor_pool_id string
Pi_snapshot_id string
Pi_spp_placement_group_id string
Pi_storage_connection string
Pi_target_storage_tier string
Pi_volume_clone_task_id string
Pi_volume_group_id string
Pi_volume_group_name string
Pi_volume_id string
Pi_volume_name string
Pi_volume_onboarding_id string
Pi_network_name string
Pi_cloud_instance_id string
Pi_snapshot_id string
Pi_instance_name string
Pi_dhcp_id string
Pi_volume_onboarding_source_crn string
PiCloudConnectionName string
PiSAPProfileID string
Pi_placement_group_name string
Pi_spp_placement_group_id string
PiStoragePool string
PiStorageType string
Pi_shared_processor_pool_id string
Pi_target_storage_tier string
Pi_volume_clone_task_id string
Pi_resource_group_id string
)

var (
Expand Down Expand Up @@ -1136,7 +1137,10 @@ func init() {
Pi_shared_processor_pool_id = "tf-pi-shared-processor-pool"
fmt.Println("[WARN] Set the environment variable PI_SHARED_PROCESSOR_POOL_ID for testing ibm_pi_shared_processor_pool resource else it is set to default value 'tf-pi-shared-processor-pool'")
}

Pi_storage_connection = os.Getenv("PI_STORAGE_CONNECTION")
if Pi_storage_connection == "" {
fmt.Println("[WARN] Set the environment variable PI_STORAGE_CONNECTION for testing pi_storage_connection resource else it is empty")
}
Pi_target_storage_tier = os.Getenv("PI_TARGET_STORAGE_TIER")
if Pi_target_storage_tier == "" {
Pi_target_storage_tier = "terraform-test-tier"
Expand Down
18 changes: 6 additions & 12 deletions ibm/service/power/data_source_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func DataSourceIBMPIInstance() *schema.Resource {
},
Attr_LicenseRepositoryCapacity: {
Computed: true,
Deprecated: "This field is deprecated.",
Description: "The VTL license repository capacity TB value.",
Type: schema.TypeInt,
},
Expand Down Expand Up @@ -182,6 +181,11 @@ func DataSourceIBMPIInstance() *schema.Resource {
Description: "The status of the instance.",
Type: schema.TypeString,
},
Attr_StorageConnection: {
Computed: true,
Description: "The storage connection type.",
Type: schema.TypeString,
},
Attr_StoragePool: {
Computed: true,
Description: "The storage Pool where server is deployed.",
Expand Down Expand Up @@ -245,6 +249,7 @@ func dataSourceIBMPIInstancesRead(ctx context.Context, d *schema.ResourceData, m
d.Set(Attr_SharedProcessorPool, powervmdata.SharedProcessorPool)
d.Set(Attr_SharedProcessorPoolID, powervmdata.SharedProcessorPoolID)
d.Set(Attr_Status, powervmdata.Status)
d.Set(Attr_StorageConnection, powervmdata.StorageConnection)
d.Set(Attr_StorageType, powervmdata.StorageType)
d.Set(Attr_StoragePool, powervmdata.StoragePool)
d.Set(Attr_StoragePoolAffinity, powervmdata.StoragePoolAffinity)
Expand All @@ -259,16 +264,5 @@ func dataSourceIBMPIInstancesRead(ctx context.Context, d *schema.ResourceData, m
d.Set(Attr_HealthStatus, powervmdata.Health.Status)
}

if powervmdata.SoftwareLicenses != nil {
d.Set(Attr_IBMiCSS, powervmdata.SoftwareLicenses.IbmiCSS)
d.Set(Attr_IBMiPHA, powervmdata.SoftwareLicenses.IbmiPHA)
d.Set(Attr_IBMiRDS, powervmdata.SoftwareLicenses.IbmiRDS)
if *powervmdata.SoftwareLicenses.IbmiRDS {
d.Set(Attr_IBMiRDSUsers, powervmdata.SoftwareLicenses.IbmiRDSUsers)
} else {
d.Set(Attr_IBMiRDSUsers, 0)
}
}

return nil
}
7 changes: 6 additions & 1 deletion ibm/service/power/data_source_ibm_pi_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func DataSourceIBMPIInstances() *schema.Resource {
},
Attr_LicenseRepositoryCapacity: {
Computed: true,
Deprecated: "This field is deprecated.",
Description: "The VTL license repository capacity TB value.",
Type: schema.TypeInt,
},
Expand Down Expand Up @@ -162,6 +161,11 @@ func DataSourceIBMPIInstances() *schema.Resource {
Description: "The status of the instance.",
Type: schema.TypeString,
},
Attr_StorageConnection: {
Computed: true,
Description: "The storage connection type.",
Type: schema.TypeString,
},
Attr_StoragePool: {
Computed: true,
Description: "The storage Pool where server is deployed.",
Expand Down Expand Up @@ -235,6 +239,7 @@ func flattenPvmInstances(list []*models.PVMInstanceReference) []map[string]inter
Attr_SharedProcessorPool: i.SharedProcessorPool,
Attr_SharedProcessorPoolID: i.SharedProcessorPoolID,
Attr_Status: *i.Status,
Attr_StorageConnection: i.StorageConnection,
Attr_StoragePool: i.StoragePool,
Attr_StoragePoolAffinity: i.StoragePoolAffinity,
Attr_StorageType: i.StorageType,
Expand Down
9 changes: 8 additions & 1 deletion ibm/service/power/ibm_pi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
Arg_IBMiPHA = "pi_ibmi_pha"
Arg_IBMiRDSUsers = "pi_ibmi_rds_users"
Arg_ImageName = "pi_image_name"
Arg_ImportDetails = "pi_image_import_details"
Arg_InstanceName = "pi_instance_name"
Arg_KeyName = "pi_key_name"
Arg_NetworkName = "pi_network_name"
Expand Down Expand Up @@ -153,6 +154,7 @@ const (
Attr_LastUpdatedDate = "last_updated_date"
Attr_Leases = "leases"
Attr_LicenseRepositoryCapacity = "license_repository_capacity"
Attr_LicenseType = "license_type"
Attr_Location = "location"
Attr_MacAddress = "macaddress"
Attr_MasterChangedVolumeName = "master_changed_volume_name"
Expand Down Expand Up @@ -200,6 +202,7 @@ const (
Attr_PrimaryRole = "primary_role"
Attr_Processors = "processors"
Attr_ProcType = "proctype"
Attr_Product = "product"
Attr_ProfileID = "profile_id"
Attr_Profiles = "profiles"
Attr_Progress = "progress"
Expand Down Expand Up @@ -255,6 +258,7 @@ const (
Attr_Status = "status"
Attr_StatusDescriptionErrors = "status_description_errors"
Attr_StatusDetail = "status_detail"
Attr_StorageConnection = "storage_connection"
Attr_StoragePool = "storage_pool"
Attr_StoragePoolAffinity = "storage_pool_affinity"
Attr_StoragePoolsCapacity = "storage_pools_capacity"
Expand All @@ -281,6 +285,7 @@ const (
Attr_UsedIPPercent = "used_ip_percent"
Attr_UserIPAddress = "user_ip_address"
Attr_VCPUs = "vcpus"
Attr_Vendor = "vendor"
Attr_VirtualCoresAssigned = "virtual_cores_assigned"
Attr_VLanID = "vlan_id"
Attr_VolumeGroupName = "volume_group_name"
Expand All @@ -300,7 +305,9 @@ const (
Attr_WorkspaceStatus = "pi_workspace_status"
Attr_WorkspaceType = "pi_workspace_type"
Attr_WWN = "wwn"
OS_IBMI = "ibmi"

MaxVolumeSupport = "maxVolumeSupport"
OS_IBMI = "ibmi"

// TODO: Second Half Cleanup, remove extra variables

Expand Down
4 changes: 2 additions & 2 deletions ibm/service/power/resource_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func ResourceIBMPIInstance() *schema.Resource {
helpers.PIInstanceStorageConnection: {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validate.ValidateAllowedStringValues([]string{"vSCSI"}),
ValidateFunc: validate.ValidateAllowedStringValues([]string{"vSCSI", MaxVolumeSupport}),
Description: "Storage Connectivity Group for server deployment",
},
PIInstanceStoragePoolAffinity: {
Expand Down Expand Up @@ -1450,7 +1450,7 @@ func createPVMInstance(d *schema.ResourceData, client *st.IBMPIInstanceClient, i
}

if sc, ok := d.GetOk(helpers.PIInstanceStorageConnection); ok {
body.StorageConnection = sc.(string)
body.StorageConnectionV2 = sc.(string)
}

if pg, ok := d.GetOk(helpers.PIPlacementGroupID); ok {
Expand Down
46 changes: 44 additions & 2 deletions ibm/service/power/resource_ibm_pi_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,31 @@ func testAccCheckIBMPIInstanceReplicantConfig(name string) string {
}
`, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name, acc.Pi_volume_name)
}

func testAccCheckIBMPIInstanceStorageConnectionConfig(name, instanceHealthStatus string) string {
return fmt.Sprintf(`
resource "ibm_pi_volume" "power_volume" {
pi_cloud_instance_id = "%[1]s"
pi_volume_size = 1
pi_volume_name = "%[2]s"
pi_volume_type = "tier3"
}
resource "ibm_pi_instance" "power_instance" {
pi_cloud_instance_id = "%[1]s"
pi_memory = "2"
pi_processors = "1"
pi_instance_name = "%[2]s"
pi_proc_type = "shared"
pi_image_id = "%[3]s"
pi_sys_type = "s922"
pi_network {
network_id = "%[4]s"
}
pi_storage_connection = "%[5]s"
pi_health_status = "%[6]s"
pi_volume_ids = [ibm_pi_volume.power_volume.volume_id]
}
`, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name, acc.Pi_storage_connection, instanceHealthStatus)
}
func testAccCheckIBMPIInstanceDestroy(s *terraform.State) error {
sess, err := acc.TestAccProvider.Meta().(conns.ClientSession).IBMPISession()
if err != nil {
Expand Down Expand Up @@ -305,7 +329,25 @@ func TestAccIBMPIInstanceBasic(t *testing.T) {
},
})
}

func TestAccIBMPIInstanceStorageConnection(t *testing.T) {
instanceRes := "ibm_pi_instance.power_instance"
name := fmt.Sprintf("tf-pi-instance-%d", acctest.RandIntRange(10, 100))
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIBMPIInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMPIInstanceStorageConnectionConfig(name, helpers.PIInstanceHealthOk),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMPIInstanceExists(instanceRes),
resource.TestCheckResourceAttr(instanceRes, "pi_instance_name", name),
resource.TestCheckResourceAttr(instanceRes, "pi_storage_connection", acc.Pi_storage_connection),
),
},
},
})
}
func TestAccIBMPIInstanceDeploymentType(t *testing.T) {
instanceRes := "ibm_pi_instance.power_instance"
name := fmt.Sprintf("tf-pi-instance-%d", acctest.RandIntRange(10, 100))
Expand Down
19 changes: 11 additions & 8 deletions website/docs/d/pi_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,19 @@ 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.

- `addresses` - (Deprecated, List of objects) - The address associated with this instance.

Nested scheme for `addresses`:
- `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.
- `deployment_type` - (String) The custom deployment type.
- `health_status` - (String) The health of the instance.

**Notes** IBM i software licenses for IBM i virtual server instances -- only for IBM i instances
- `ibmi_css` - (Boolean) IBM i Cloud Storage Solution.
- `ibmi_pha` - (Boolean) IBM i Power High Availability.
- `ibmi_rds` - (Boolean) IBM i Rational Dev Studio.
- `ibmi_rds_users` - (Integer) IBM i Rational Dev Studio Number of User Licenses.
- `id` - (String) The unique identifier of the instance.
- `license_repository_capacity` - (Deprecated, Integer) The VTL license repository capacity TB value. Only available with VTL instances.
- `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 number of virtual cores that can be assigned without rebooting the instance.
Expand All @@ -71,10 +74,10 @@ In addition to all argument reference list, you can access the following attribu
- `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`.
- `server_name` - (String) The name 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_connection` - (String) The storage connection type for the instance.
- `storage_pool` - (String) The storage Pool where server is deployed.
- `storage_pool_affinity` - (Boolean) 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.
Expand Down
3 changes: 2 additions & 1 deletion website/docs/d/pi_instances.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ In addition to all argument reference list, you can access the following attribu

Nested scheme for `pvm_instances`:
- `health_status` - (String) The health of the instance.
- `license_repository_capacity` - (Deprecated, Integer) The VTL license repository capacity TB value. Only available with VTL instances.
- `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.
- `maxproc`- (Float) The maximum number of processors that can be allocated to the instance without shutting down or rebooting the `LPAR`.
Expand All @@ -69,6 +69,7 @@ In addition to all argument reference list, you can access the following attribu
- `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_connection` - (String) The storage connection type for the instance.
- `storage_pool` - (String) The storage Pool where server is deployed.
- `storage_pool_affinity` - (Boolean) 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.
Expand Down
Loading

0 comments on commit 2ad486a

Please sign in to comment.