Skip to content

Commit

Permalink
Add power edge details to workspace data source (IBM-Cloud#5205)
Browse files Browse the repository at this point in the history
* Refactor whitespace

* Add power edge router attributes

* Add power edge router documentation

* Remove commented out code

* Simplify poweredge router code
  • Loading branch information
ismirlia authored Apr 15, 2024
1 parent 74ae14c commit a5201f3
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 28 deletions.
18 changes: 9 additions & 9 deletions ibm/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,18 +602,20 @@ func Provider() *schema.Provider {
"ibm_pi_cloud_connections": power.DataSourceIBMPICloudConnections(),
"ibm_pi_cloud_instance": power.DataSourceIBMPICloudInstance(),
"ibm_pi_console_languages": power.DataSourceIBMPIInstanceConsoleLanguages(),
"ibm_pi_datacenter": power.DataSourceIBMPIDatacenter(),
"ibm_pi_datacenters": power.DataSourceIBMPIDatacenters(),
"ibm_pi_dhcp": power.DataSourceIBMPIDhcp(),
"ibm_pi_dhcps": power.DataSourceIBMPIDhcps(),
"ibm_pi_disaster_recovery_location": power.DataSourceIBMPIDisasterRecoveryLocation(),
"ibm_pi_disaster_recovery_locations": power.DataSourceIBMPIDisasterRecoveryLocations(),
"ibm_pi_image": power.DataSourceIBMPIImage(),
"ibm_pi_images": power.DataSourceIBMPIImages(),
"ibm_pi_instance": power.DataSourceIBMPIInstance(),
"ibm_pi_instances": power.DataSourceIBMPIInstances(),
"ibm_pi_instance_ip": power.DataSourceIBMPIInstanceIP(),
"ibm_pi_instance_snapshot": power.DataSourceIBMPIInstanceSnapshot(),
"ibm_pi_instance_snapshots": power.DataSourceIBMPIInstanceSnapshots(),
"ibm_pi_instance_volumes": power.DataSourceIBMPIInstanceVolumes(),
"ibm_pi_instances": power.DataSourceIBMPIInstances(),
"ibm_pi_key": power.DataSourceIBMPIKey(),
"ibm_pi_keys": power.DataSourceIBMPIKeys(),
"ibm_pi_network": power.DataSourceIBMPINetwork(),
Expand All @@ -636,20 +638,18 @@ func Provider() *schema.Provider {
"ibm_pi_tenant": power.DataSourceIBMPITenant(),
"ibm_pi_volume": power.DataSourceIBMPIVolume(),
"ibm_pi_volume_clone": power.DataSourceIBMPIVolumeClone(),
"ibm_pi_volume_flash_copy_mappings": power.DataSourceIBMPIVolumeFlashCopyMappings(),
"ibm_pi_volume_group": power.DataSourceIBMPIVolumeGroup(),
"ibm_pi_volume_groups": power.DataSourceIBMPIVolumeGroups(),
"ibm_pi_volume_group_details": power.DataSourceIBMPIVolumeGroupDetails(),
"ibm_pi_volume_groups_details": power.DataSourceIBMPIVolumeGroupsDetails(),
"ibm_pi_volume_group_storage_details": power.DataSourceIBMPIVolumeGroupStorageDetails(),
"ibm_pi_volume_group_remote_copy_relationships": power.DataSourceIBMPIVolumeGroupRemoteCopyRelationships(),
"ibm_pi_volume_flash_copy_mappings": power.DataSourceIBMPIVolumeFlashCopyMappings(),
"ibm_pi_volume_remote_copy_relationship": power.DataSourceIBMPIVolumeRemoteCopyRelationship(),
"ibm_pi_volume_onboardings": power.DataSourceIBMPIVolumeOnboardings(),
"ibm_pi_volume_group_storage_details": power.DataSourceIBMPIVolumeGroupStorageDetails(),
"ibm_pi_volume_groups": power.DataSourceIBMPIVolumeGroups(),
"ibm_pi_volume_groups_details": power.DataSourceIBMPIVolumeGroupsDetails(),
"ibm_pi_volume_onboarding": power.DataSourceIBMPIVolumeOnboarding(),
"ibm_pi_volume_onboardings": power.DataSourceIBMPIVolumeOnboardings(),
"ibm_pi_volume_remote_copy_relationship": power.DataSourceIBMPIVolumeRemoteCopyRelationship(),
"ibm_pi_workspace": power.DatasourceIBMPIWorkspace(),
"ibm_pi_workspaces": power.DatasourceIBMPIWorkspaces(),
"ibm_pi_datacenter": power.DataSourceIBMPIDatacenter(),
"ibm_pi_datacenters": power.DataSourceIBMPIDatacenters(),

// Added for private dns zones

Expand Down
66 changes: 57 additions & 9 deletions ibm/service/power/data_source_ibm_pi_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,45 @@ func DatasourceIBMPIWorkspace() *schema.Resource {
Type: schema.TypeMap,
},
Attr_WorkspaceDetails: {
Computed: true,
Description: "Workspace information.",
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Attr_CreationDate: {
Computed: true,
Description: "Workspace creation date.",
Type: schema.TypeString,
},
Attr_CRN: {
Computed: true,
Description: "The Workspace crn.",
Type: schema.TypeString,
},
Attr_PowerEdgeRouter: {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Attr_MigrationStatus: {
Computed: true,
Description: "The migration status of a Power Edge Router.",
Type: schema.TypeString,
},
Attr_State: {
Computed: true,
Description: "The state of a Power Edge Router.",
Type: schema.TypeString,
},
Attr_Type: {
Computed: true,
Description: "The Power Edge Router type.",
Type: schema.TypeString,
},
},
},
Type: schema.TypeList,
},
},
},
Type: schema.TypeList,
},
Attr_WorkspaceLocation: {
Computed: true,
Expand Down Expand Up @@ -81,17 +117,29 @@ func dataSourceIBMPIWorkspaceRead(ctx context.Context, d *schema.ResourceData, m
d.Set(Attr_WorkspaceStatus, wsData.Status)
d.Set(Attr_WorkspaceType, wsData.Type)
d.Set(Attr_WorkspaceCapabilities, wsData.Capabilities)
wsdetails := map[string]interface{}{
Attr_CreationDate: wsData.Details.CreationDate.String(),
Attr_CRN: *wsData.Details.Crn,

wsDetails := []map[string]interface{}{}
detailsData := make(map[string]interface{})
detailsData[Attr_CreationDate] = wsData.Details.CreationDate.String()
detailsData[Attr_CRN] = *wsData.Details.Crn

if wsData.Details.PowerEdgeRouter != nil {
wsPowerEdge := map[string]interface{}{
Attr_MigrationStatus: wsData.Details.PowerEdgeRouter.MigrationStatus,
Attr_State: *wsData.Details.PowerEdgeRouter.State,
Attr_Type: *wsData.Details.PowerEdgeRouter.Type,
}
detailsData[Attr_PowerEdgeRouter] = []map[string]interface{}{wsPowerEdge}
wsDetails = append(wsDetails, detailsData)
}
d.Set(Attr_WorkspaceDetails, flex.Flatten(wsdetails))
wslocation := map[string]interface{}{

d.Set(Attr_WorkspaceDetails, wsDetails)
wsLocation := map[string]interface{}{
Attr_Region: *wsData.Location.Region,
Attr_Type: wsData.Location.Type,
Attr_URL: wsData.Location.URL,
}
d.Set(Attr_WorkspaceLocation, flex.Flatten(wslocation))
d.Set(Attr_WorkspaceLocation, flex.Flatten(wsLocation))
d.SetId(*wsData.ID)
return nil
}
65 changes: 57 additions & 8 deletions ibm/service/power/data_source_ibm_pi_workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,45 @@ func DatasourceIBMPIWorkspaces() *schema.Resource {
Type: schema.TypeMap,
},
Attr_WorkspaceDetails: {
Computed: true,
Description: "Workspace information.",
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Attr_CreationDate: {
Computed: true,
Description: "Workspace creation date.",
Type: schema.TypeString,
},
Attr_CRN: {
Computed: true,
Description: "The Workspace crn.",
Type: schema.TypeString,
},
Attr_PowerEdgeRouter: {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Attr_MigrationStatus: {
Computed: true,
Description: "The migration status of a Power Edge Router.",
Type: schema.TypeString,
},
Attr_State: {
Computed: true,
Description: "The state of a Power Edge Router.",
Type: schema.TypeString,
},
Attr_Type: {
Computed: true,
Description: "The Power Edge Router type.",
Type: schema.TypeString,
},
},
},
Type: schema.TypeList,
},
},
},
Type: schema.TypeList,
},
Attr_WorkspaceID: {
Computed: true,
Expand Down Expand Up @@ -76,6 +112,7 @@ func DatasourceIBMPIWorkspaces() *schema.Resource {
},
}
}

func dataSourceIBMPIWorkspacesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
sess, err := meta.(conns.ClientSession).IBMPISession()
if err != nil {
Expand All @@ -91,13 +128,25 @@ func dataSourceIBMPIWorkspacesRead(ctx context.Context, d *schema.ResourceData,
workspaces := make([]map[string]interface{}, 0, len(wsData.Workspaces))
for _, ws := range wsData.Workspaces {
if ws != nil {
wsDetails := []map[string]interface{}{}
detailsData := make(map[string]interface{})
detailsData[Attr_CreationDate] = ws.Details.CreationDate.String()
detailsData[Attr_CRN] = *ws.Details.Crn

if ws.Details.PowerEdgeRouter != nil {
wsPowerEdge := map[string]interface{}{
Attr_MigrationStatus: ws.Details.PowerEdgeRouter.MigrationStatus,
Attr_State: *ws.Details.PowerEdgeRouter.State,
Attr_Type: *ws.Details.PowerEdgeRouter.Type,
}
detailsData[Attr_PowerEdgeRouter] = []map[string]interface{}{wsPowerEdge}
wsDetails = append(wsDetails, detailsData)
}

workspace := map[string]interface{}{
Attr_WorkspaceCapabilities: ws.Capabilities,
Attr_WorkspaceDetails: map[string]interface{}{
Attr_CreationDate: ws.Details.CreationDate.String(),
Attr_CRN: *ws.Details.Crn,
},
Attr_WorkspaceID: ws.ID,
Attr_WorkspaceDetails: wsDetails,
Attr_WorkspaceID: ws.ID,
Attr_WorkspaceLocation: map[string]interface{}{
Attr_Region: *ws.Location.Region,
Attr_Type: ws.Location.Type,
Expand Down
2 changes: 2 additions & 0 deletions ibm/service/power/ibm_pi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ const (
Attr_Memory = "memory"
Attr_Message = "message"
Attr_Metered = "metered"
Attr_MigrationStatus = "migration_status"
Attr_Min = "min"
Attr_MinMem = "minmem"
Attr_MinProc = "minproc"
Expand All @@ -160,6 +161,7 @@ const (
Attr_PoolName = "pool_name"
Attr_Port = "port"
Attr_PortID = "portid"
Attr_PowerEdgeRouter = "power_edge_router"
Attr_PrimaryRole = "primary_role"
Attr_Processors = "processors"
Attr_ProcType = "proctype"
Expand Down
8 changes: 7 additions & 1 deletion website/docs/d/pi_workspace.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ In addition to all argument reference listed, you can access the following attri
Some of `pi_workspace_capabilities` are:
- `cloud-connections`, `power-edge-router`, `power-vpn-connections`, `transit-gateway-connection`

- `pi_workspace_details` - (Map) Workspace information.
- `pi_workspace_details` - (List) Workspace information.

Nested schema for `pi_workspace_details`:
- `creation_date` - (String) Date of workspace creation.
- `crn` - (String) Workspace crn.
- `power_edge_router` - (List) Power Edge Router information.

Nested schema for `power_edge_router`:
- `migration_status` - (String) The migration status of a Power Edge Router.
- `status` - (String) The state of a Power Edge Router.
- `type` - (String) The Power Edge Router type.
- `pi_workspace_location` - (Map) Workspace location.

Nested schema for `Workspace location`:
Expand Down
8 changes: 7 additions & 1 deletion website/docs/d/pi_workspaces.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,17 @@ In addition to all argument reference listed, you can access the following attri
Some of `pi_workspace_capabilities` are:
- `cloud-connections`, `power-edge-router`, `power-vpn-connections`, `transit-gateway-connection`

- `pi_workspace_details` - (Map) Workspace information.
- `pi_workspace_details` - (List) Workspace information.

Nested schema for `pi_workspace_details`:
- `creation_date` - (String) Date of workspace creation.
- `crn` - (String) Workspace crn.
- `power_edge_router` - (List) Power Edge Router information.

Nested schema for `power_edge_router`:
- `migration_status` - (String) The migration status of a Power Edge Router.
- `status` - (String) The state of a Power Edge Router.
- `type` - (String) The Power Edge Router type.
- `pi_workspace_id` - (String) Workspace ID.
- `pi_workspace_location` - (Map) Workspace location.

Expand Down

0 comments on commit a5201f3

Please sign in to comment.