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 cloud connection network attach resource and documentation #61

Closed
wants to merge 2 commits into from
Closed
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 @@ -29,6 +29,7 @@ const (
Arg_VolumeGroupID = "pi_volume_group_id"
Arg_VolumeID = "pi_volume_id"
Arg_VolumeOnboardingID = "pi_volume_onboarding_id"
Arg_CloudConnectionID = "pi_cloud_connection_id"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be around the top of the file


// Attributes
Attr_AccessConfig = "access_config"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ import (
"log"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

st "github.com/IBM-Cloud/power-go-client/clients/instance"
"github.com/IBM-Cloud/power-go-client/helpers"
"github.com/IBM-Cloud/power-go-client/clients/instance"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

const (
PICloudConnectionNetworkId = "pi_network_id"
Arg_CloudConnectionNetworkId = "pi_network_id"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be moved to the const file

)

func ResourceIBMPICloudConnectionNetworkAttach() *schema.Resource {
Expand All @@ -35,24 +33,24 @@ func ResourceIBMPICloudConnectionNetworkAttach() *schema.Resource {
},

Schema: map[string]*schema.Schema{
// Required Attributes
helpers.PICloudInstanceId: {
// Arguments
Arg_CloudInstanceID: {
Description: "The GUID of the service instance associated with an account",
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "PI cloud instance ID",
},
helpers.PICloudConnectionId: {
Arg_CloudConnectionID: {
Description: "The Cloud Connection ID",
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Cloud Connection ID",
},
PICloudConnectionNetworkId: {
Arg_CloudConnectionNetworkId: {
Description: "The Network ID to attach to this cloud connection",
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Network ID to attach to this cloud connection",
},
},
}
Expand All @@ -64,12 +62,12 @@ func resourceIBMPICloudConnectionNetworkAttachCreate(ctx context.Context, d *sch
return diag.FromErr(err)
}

cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string)
cloudConnectionID := d.Get(helpers.PICloudConnectionId).(string)
networkID := d.Get(PICloudConnectionNetworkId).(string)
cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)
cloudConnectionID := d.Get(Arg_CloudConnectionID).(string)
networkID := d.Get(Arg_CloudConnectionNetworkId).(string)

client := st.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID)
jobClient := st.NewIBMPIJobClient(ctx, sess, cloudInstanceID)
client := instance.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID)
jobClient := instance.NewIBMPIJobClient(ctx, sess, cloudInstanceID)

_, jobReference, err := client.AddNetwork(cloudConnectionID, networkID)
if err != nil {
Expand Down Expand Up @@ -97,9 +95,9 @@ func resourceIBMPICloudConnectionNetworkAttachRead(ctx context.Context, d *schem
cloudConnectionID := parts[1]
networkID := parts[2]

d.Set(helpers.PICloudInstanceId, cloudInstanceID)
d.Set(helpers.PICloudConnectionId, cloudConnectionID)
d.Set(PICloudConnectionNetworkId, networkID)
d.Set(Arg_CloudInstanceID, cloudInstanceID)
d.Set(Arg_CloudConnectionID, cloudConnectionID)
d.Set(Arg_CloudConnectionNetworkId, networkID)

return nil
}
Expand All @@ -119,8 +117,8 @@ func resourceIBMPICloudConnectionNetworkAttachDelete(ctx context.Context, d *sch
cloudConnectionID := parts[1]
networkID := parts[2]

client := st.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID)
jobClient := st.NewIBMPIJobClient(ctx, sess, cloudInstanceID)
client := instance.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID)
jobClient := instance.NewIBMPIJobClient(ctx, sess, cloudInstanceID)

_, jobReference, err := client.DeleteNetwork(cloudConnectionID, networkID)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,5 @@ func testAccCheckIBMPICloudConnectionNetworkAttachConfig(name string) string {
depends_on = [ibm_pi_cloud_connection_network_attach.example]
pi_cloud_instance_id = "%[1]s"
pi_cloud_connection_name = "%[2]s"
}
`, acc.Pi_cloud_instance_id, name)
}`, acc.Pi_cloud_instance_id, name)
}
12 changes: 6 additions & 6 deletions website/docs/r/pi_cloud_connection_network_attach.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ resource "ibm_pi_cloud_connection_network_attach" "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 Down
Loading