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

Add Fault Attribute to Pi_Instance #5344

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ require (
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1912,8 +1912,8 @@ golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down
8 changes: 8 additions & 0 deletions ibm/service/power/data_source_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ func DataSourceIBMPIInstance() *schema.Resource {
Description: "The custom deployment type.",
Type: schema.TypeString,
},
Attr_Fault: {
Computed: true,
Description: "Fault information.",
Type: schema.TypeMap,
},
Attr_HealthStatus: {
Computed: true,
Description: "The health of the instance.",
Expand Down Expand Up @@ -269,6 +274,9 @@ func dataSourceIBMPIInstancesRead(ctx context.Context, d *schema.ResourceData, m
d.Set(Attr_IBMiRDSUsers, 0)
}
}
if powervmdata.Fault != nil {
d.Set(Attr_Fault, flattenPvmInstanceFault(powervmdata.Fault))
}

return nil
}
25 changes: 25 additions & 0 deletions ibm/service/power/data_source_ibm_pi_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package power

import (
"context"
"strconv"

"github.com/IBM-Cloud/power-go-client/clients/instance"
"github.com/IBM-Cloud/power-go-client/power/models"
Expand Down Expand Up @@ -33,6 +34,11 @@ func DataSourceIBMPIInstances() *schema.Resource {
Description: "List of power virtual server instances for the respective cloud instance.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Attr_Fault: {
Computed: true,
Description: "Fault information.",
Type: schema.TypeMap,
},
Attr_HealthStatus: {
Computed: true,
Description: "The health of the instance.",
Expand Down Expand Up @@ -245,6 +251,10 @@ func flattenPvmInstances(list []*models.PVMInstanceReference) []map[string]inter
l[Attr_HealthStatus] = i.Health.Status
}

if i.Fault != nil {
l[Attr_Fault] = flattenPvmInstanceFault(i.Fault)
}

result = append(result, l)
}
return result
Expand All @@ -267,3 +277,18 @@ func flattenPvmInstanceNetworks(list []*models.PVMInstanceNetwork) (networks []m
}
return
}

func flattenPvmInstanceFault(fault *models.PVMInstanceFault) map[string]interface{} {
faultMap := make(map[string]interface{})
faultMap[Attr_Code] = strconv.FormatFloat(fault.Code, 'f', -1, 64)
if !fault.Created.IsZero() {
faultMap[Attr_Created] = fault.Created.String()
}
if fault.Details != "" {
faultMap[Attr_Details] = fault.Details
}
if fault.Message != "" {
faultMap[Attr_Message] = fault.Message
}
return faultMap
}
3 changes: 3 additions & 0 deletions ibm/service/power/ibm_pi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const (
Attr_CPUs = "cpus"
Attr_CreateTime = "create_time"
Attr_CreationDate = "creation_date"
Attr_Created = "created"
Attr_CRN = "crn"
Attr_CyclePeriodSeconds = "cycle_period_seconds"
Attr_CyclingMode = "cycling_mode"
Expand All @@ -104,6 +105,7 @@ const (
Attr_DeleteOnTermination = "delete_on_termination"
Attr_DeploymentType = "deployment_type"
Attr_Description = "description"
Attr_Details = "details"
Attr_DhcpID = "dhcp_id"
Attr_DhcpLeaseInstanceIP = "instance_ip"
Attr_DhcpLeaseInstanceMac = "instance_mac"
Expand All @@ -122,6 +124,7 @@ const (
Attr_Endianness = "endianness"
Attr_ExternalIP = "external_ip"
Attr_FailureMessage = "failure_message"
Attr_Fault = "fault"
Attr_FlashCopyMappings = "flash_copy_mappings"
Attr_FlashCopyName = "flash_copy_name"
Attr_FreezeTime = "freeze_time"
Expand Down
8 changes: 8 additions & 0 deletions ibm/service/power/resource_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,11 @@ func ResourceIBMPIInstance() *schema.Resource {
Optional: true,
Description: "IBM i Rational Dev Studio Number of User Licenses",
},
Attr_Fault: {
Computed: true,
Description: "Fault information.",
Type: schema.TypeMap,
},
},
}
}
Expand Down Expand Up @@ -554,6 +559,9 @@ func resourceIBMPIInstanceRead(ctx context.Context, d *schema.ResourceData, meta
d.Set(Arg_IBMiRDSUsers, 0)
}
}
if powervmdata.Fault != nil {
d.Set(Attr_Fault, flattenPvmInstanceFault(powervmdata.Fault))
}
return nil
}

Expand Down
23 changes: 19 additions & 4 deletions website/docs/d/pi_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,27 @@ description: |-
---

# ibm_pi_instance

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"
pi_cloud_instance_id = "49fba6c9-23f8-40bc-9899-aca322ee7d5b"
}
```

**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"
Expand All @@ -32,18 +36,29 @@ Example usage:
```

## Argument reference
Review the argument references that you can specify for your data source.

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.

In addition to all argument reference list, you can access the following attribute references after your data source is created.

- `deployment_type` - (String) The custom deployment type.
- `fault` - (Map) Fault information, if any.

Nested scheme for `fault`:
- `code` - (String) The fault status of the server.
- `created` - (String) The date and time the fault occurred.
- `details` - (String) The fault details of the server.
- `message` - (String) The fault message of the server.

- `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.
Expand All @@ -55,7 +70,7 @@ In addition to all argument reference list, you can access the following attribu
- `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.
- `minproc`- (Float) The minimum number of processors that must be allocated to the 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.

Expand Down
34 changes: 24 additions & 10 deletions website/docs/d/pi_instances.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@ description: |-
---

# ibm_pi_instances

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"
}
```

**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"
Expand All @@ -31,20 +35,30 @@ Example usage:
```

## Argument reference
Review the argument references that you can specify for your data source.

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.

In addition to all argument reference list, you can access the following attribute references after your data source is created.

- `pvm_instances` - (List) List of power virtual server instances for the respective cloud instance.

Nested scheme for `pvm_instances`:
- `fault` - (Map) Fault information, if any.

Nested scheme for `fault`:
- `code` - (String) The fault status of the server.
- `created` - (String) The date and time the fault occurred.
- `details` - (String) The fault details of the server.
- `message` - (String) The fault message of the server.

- `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.
- `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.
- `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 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.
Expand All @@ -53,12 +67,12 @@ In addition to all argument reference list, you can access the following attribu
- `networks` - (List) List of networks associated with this instance.

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.
- `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.
Expand Down
10 changes: 9 additions & 1 deletion website/docs/r/pi_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: |-
---

# ibm_pi_instance
Create or update a [Power Systems Virtual Server instance](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-creating-power-virtual-server).
Create, delete or update a [Power Systems Virtual Server instance](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-creating-power-virtual-server).

## Example usage
The following example creates a Power Systems Virtual Server instance.
Expand Down Expand Up @@ -111,6 +111,14 @@ Review the argument references that you can specify for your resource.
## Attribute reference
In addition to all argument reference list, you can access the following attribute reference after your resource is created.

- `fault` - (Map) Fault information, if any.

Nested scheme for `fault`:
- `code` - (String) The fault status of the server.
- `created` - (String) The date and time the fault occurred.
- `details` - (String) The fault details of the server.
- `message` - (String) The fault message of the server.

- `health_status` - (String) The health status of the VM.
- `ibmi_rds` - (Boolean) IBM i Rational Dev Studio.
- `id` - (String) The unique identifier of the instance. The ID is composed of `<cloud_instance_id>/<instance_id_1>/.../<instance_id_n>`.
Expand Down
Loading