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 ibm_pi_console_language resource #5336

Merged
merged 4 commits into from
May 8, 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
1 change: 1 addition & 0 deletions ibm/service/power/ibm_pi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
Arg_ImageName = "pi_image_name"
Arg_InstanceName = "pi_instance_name"
Arg_KeyName = "pi_key_name"
Arg_LanguageCode = "pi_language_code"
Arg_NetworkName = "pi_network_name"
Arg_PIInstanceSharedProcessorPool = "pi_shared_processor_pool"
Arg_PlacementGroupName = "pi_placement_group_name"
Expand Down
50 changes: 26 additions & 24 deletions ibm/service/power/resource_ibm_pi_instance_console_language.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import (
"log"
"time"

"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/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 ResourceIBMPIInstanceConsoleLanguage() *schema.Resource {
Expand All @@ -31,21 +30,24 @@ func ResourceIBMPIInstanceConsoleLanguage() *schema.Resource {
},

Schema: map[string]*schema.Schema{
// Required Attributes
helpers.PICloudInstanceId: {
Type: schema.TypeString,
Required: true,
Description: "PI cloud instance ID",
// 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,
Required: true,
Description: "The unique identifier or name of the instance",
Arg_InstanceName: {
Description: "The unique identifier or name of the instance.",
Required: true,
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
},
PIConsoleLanguageCode: {
Type: schema.TypeString,
Required: true,
Description: "Language code",
Arg_LanguageCode: {
Description: "Language code.",
Required: true,
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
},
},
}
Expand All @@ -57,9 +59,9 @@ func resourceIBMPIInstanceConsoleLanguageCreate(ctx context.Context, d *schema.R
return diag.FromErr(err)
}

cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string)
instanceName := d.Get(helpers.PIInstanceName).(string)
code := d.Get(PIConsoleLanguageCode).(string)
cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)
instanceName := d.Get(Arg_InstanceName).(string)
code := d.Get(Arg_LanguageCode).(string)

client := instance.NewIBMPIInstanceClient(ctx, sess, cloudInstanceID)

Expand Down Expand Up @@ -89,10 +91,10 @@ func resourceIBMPIInstanceConsoleLanguageUpdate(ctx context.Context, d *schema.R
return diag.FromErr(err)
}

if d.HasChange(PIConsoleLanguageCode) {
cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string)
instanceName := d.Get(helpers.PIInstanceName).(string)
code := d.Get(PIConsoleLanguageCode).(string)
if d.HasChange(Arg_LanguageCode) {
cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)
instanceName := d.Get(Arg_InstanceName).(string)
code := d.Get(Arg_LanguageCode).(string)

client := instance.NewIBMPIInstanceClient(ctx, sess, cloudInstanceID)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ func TestAccIBMPIInstanceConsoleLanguage(t *testing.T) {

func testAccCheckIBMPIInstanceConsoleLanguageConfig(code string) string {
return fmt.Sprintf(`
resource "ibm_pi_console_language" "example" {
pi_cloud_instance_id = "%s"
pi_instance_name = "%s"
pi_language_code = "%s"
}
`, acc.Pi_cloud_instance_id, acc.Pi_instance_name, code)
resource "ibm_pi_console_language" "example" {
pi_cloud_instance_id = "%[1]s"
pi_instance_name = "%[2]s"
pi_language_code = "%[3]s"
}`, acc.Pi_cloud_instance_id, acc.Pi_instance_name, code)
}
18 changes: 9 additions & 9 deletions website/docs/r/pi_console_language.html.markdown
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

subcategory: "Power Systems"
layout: "ibm"
page_title: "IBM: pi_console_language"
Expand All @@ -12,6 +11,7 @@ description: |-
Update the Console Language of a Server for your Power Systems Virtual Server 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

The following example enables you to update the Console Languages of a Server:

```terraform
Expand All @@ -22,14 +22,14 @@ resource "ibm_pi_console_language" "example" {
}
```

**Note**
### 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" {
Expand All @@ -47,7 +47,7 @@ The `ibm_pi_console_language` provides the following [timeouts](https://www.terr

## Argument reference

Review the argument references that you can specify for your resource.
Review the argument references that you can specify for your resource.

- `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.
Expand All @@ -57,4 +57,4 @@ Review the argument references that you can specify for your resource.

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

- `id` - (String) The unique identifier of the instance console language. The ID is composed of `<power_instance_id>/<pi_instance_name>`.
- `id` - (String) The unique identifier of the instance console language. The ID is composed of `<pi_cloud_instance_id>/<pi_instance_name>`.
Loading