Skip to content

Commit

Permalink
Add support for transit enabled cloud connections (IBM-Cloud#3758)
Browse files Browse the repository at this point in the history
Code changes to use features from latest release of power-go-client

Fixed typo

Removed test case

Review comment code changes

Review comment code changes

Updated power-go-client to v1.1.9

added PICloudConnectionConnectionMode in CloudConnectionRead
  • Loading branch information
rachari authored and SunithaGudisagarIBM1 committed Sep 14, 2022
1 parent c264a0f commit cd0e00b
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 104 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.16
require (
github.com/IBM-Cloud/bluemix-go v0.0.0-20220407050707-b4cd0d4da813
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20210705152127-41ca00fc9a62
github.com/IBM-Cloud/power-go-client v1.1.8
github.com/IBM-Cloud/power-go-client v1.1.9
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca
github.com/IBM/appconfiguration-go-admin-sdk v0.2.3
github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ github.com/IBM-Cloud/bluemix-go v0.0.0-20220407050707-b4cd0d4da813/go.mod h1:UOh
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20210705152127-41ca00fc9a62 h1:MOkcr6qQGk4tY542ZJ1DggVh2WUP72EEyLB79llFVH8=
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20210705152127-41ca00fc9a62/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.1.8 h1:EPfUzEbSz6Cg1O5mLv65dMlmbju4zXeDUXQ3h21gGVA=
github.com/IBM-Cloud/power-go-client v1.1.8/go.mod h1:Qfx0fNi+9hms+xu9Z6Euhu9088ByW6C/TCMLECTRWNE=
github.com/IBM-Cloud/power-go-client v1.1.9 h1:NKG4lxQNe1HHANC+94mRqgogIkiAHo5COMNsqUGdNqg=
github.com/IBM-Cloud/power-go-client v1.1.9/go.mod h1:Qfx0fNi+9hms+xu9Z6Euhu9088ByW6C/TCMLECTRWNE=
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
8 changes: 7 additions & 1 deletion ibm/service/power/data_source_ibm_pi_cloud_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
PICloudConnectionClassicGreSource = "gre_source_address"
PICloudConnectionVPCEnabled = "vpc_enabled"
PICloudConnectionVPCCRNs = "vpc_crns"
PICloudConnectionConnectionMode = "connection_mode"
)

func DataSourceIBMPICloudConnection() *schema.Resource {
Expand Down Expand Up @@ -112,6 +113,11 @@ func DataSourceIBMPICloudConnection() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
Description: "Set of VPCs attached to this cloud connection",
},
PICloudConnectionConnectionMode: {
Type: schema.TypeString,
Computed: true,
Description: "Type of service the gateway is attached to",
},
},
}
}
Expand Down Expand Up @@ -168,6 +174,7 @@ func dataSourceIBMPICloudConnectionRead(ctx context.Context, d *schema.ResourceD
d.Set(PICloudConnectionPort, cloudConnection.Port)
d.Set(PICloudConnectionSpeed, cloudConnection.Speed)
d.Set(helpers.PICloudInstanceId, cloudInstanceID)
d.Set(PICloudConnectionConnectionMode, cloudConnection.ConnectionMode)
if cloudConnection.Networks != nil {
networks := make([]string, len(cloudConnection.Networks))
for i, ccNetwork := range cloudConnection.Networks {
Expand All @@ -194,6 +201,5 @@ func dataSourceIBMPICloudConnectionRead(ctx context.Context, d *schema.ResourceD
d.Set(PICloudConnectionVPCCRNs, vpcCRNs)
}
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestAccIBMPICloudConnectionDataSource_basic(t *testing.T) {
Config: testAccCheckIBMPICloudConnectionDataSourceConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_pi_cloud_connection.example", "id"),
resource.TestCheckResourceAttrSet("data.ibm_pi_cloud_connection.example", "connection_mode"),
),
},
},
Expand Down
24 changes: 15 additions & 9 deletions ibm/service/power/data_source_ibm_pi_cloud_connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ func DataSourceIBMPICloudConnections() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
Description: "Set of VPCs attached to this cloud connection",
},
PICloudConnectionConnectionMode: {
Type: schema.TypeString,
Computed: true,
Description: "Type of service the gateway is attached to",
},
},
},
},
Expand All @@ -132,15 +137,16 @@ func dataSourceIBMPICloudConnectionsRead(ctx context.Context, d *schema.Resource
result := make([]map[string]interface{}, 0, len(cloudConnections.CloudConnections))
for _, cloudConnection := range cloudConnections.CloudConnections {
cc := map[string]interface{}{
PICloudConnectionId: *cloudConnection.CloudConnectionID,
PICloudConnectionName: *cloudConnection.Name,
PICloudConnectionGlobalRouting: *cloudConnection.GlobalRouting,
PICloudConnectionMetered: *cloudConnection.Metered,
PICloudConnectionIBMIPAddress: *cloudConnection.IbmIPAddress,
PICloudConnectionUserIPAddress: *cloudConnection.UserIPAddress,
PICloudConnectionStatus: *cloudConnection.LinkStatus,
PICloudConnectionPort: *cloudConnection.Port,
PICloudConnectionSpeed: *cloudConnection.Speed,
PICloudConnectionId: *cloudConnection.CloudConnectionID,
PICloudConnectionName: *cloudConnection.Name,
PICloudConnectionGlobalRouting: *cloudConnection.GlobalRouting,
PICloudConnectionMetered: *cloudConnection.Metered,
PICloudConnectionIBMIPAddress: *cloudConnection.IbmIPAddress,
PICloudConnectionUserIPAddress: *cloudConnection.UserIPAddress,
PICloudConnectionStatus: *cloudConnection.LinkStatus,
PICloudConnectionPort: *cloudConnection.Port,
PICloudConnectionSpeed: *cloudConnection.Speed,
PICloudConnectionConnectionMode: cloudConnection.ConnectionMode,
}

if cloudConnection.Networks != nil {
Expand Down
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 @@ -61,4 +61,7 @@ const (
PIVPNConnectionDeadPeerDetectionThreshold = "threshold"
PIVPNConnectionLocalGatewayAddress = "local_gateway_address"
PIVPNConnectionVpnGatewayAddress = "gateway_address"

// Cloud Connections
PICloudConnectionTransitEnabled = "pi_cloud_connection_transit_enabled"
)
12 changes: 12 additions & 0 deletions ibm/service/power/resource_ibm_pi_cloud_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ func ResourceIBMPICloudConnection() *schema.Resource {
RequiredWith: []string{helpers.PICloudConnectionVPCEnabled},
Description: "Set of VPCs to attach to this cloud connection",
},
PICloudConnectionTransitEnabled: {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Enable transit gateway for this cloud connection",
},

//Computed Attributes
PICloudConnectionId: {
Expand Down Expand Up @@ -203,6 +209,11 @@ func resourceIBMPICloudConnectionCreate(ctx context.Context, d *schema.ResourceD
body.Vpc = vpc
}

// Transit Gateway
if v, ok := d.GetOk(PICloudConnectionTransitEnabled); ok {
body.TransitEnabled = v.(bool)
}

client := st.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID)
cloudConnection, cloudConnectionJob, err := client.Create(body)
if err != nil {
Expand Down Expand Up @@ -397,6 +408,7 @@ func resourceIBMPICloudConnectionRead(ctx context.Context, d *schema.ResourceDat
d.Set(PICloudConnectionPort, cloudConnection.Port)
d.Set(helpers.PICloudConnectionSpeed, cloudConnection.Speed)
d.Set(helpers.PICloudInstanceId, cloudInstanceID)
d.Set(PICloudConnectionConnectionMode, cloudConnection.ConnectionMode)
if cloudConnection.Networks != nil {
networks := make([]string, 0)
for _, ccNetwork := range cloudConnection.Networks {
Expand Down
165 changes: 104 additions & 61 deletions ibm/service/power/resource_ibm_pi_cloud_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,18 @@ func testAccCheckIBMPICloudConnectionExists(n string) resource.TestCheckFunc {
}
func testAccCheckIBMPICloudConnectionConfig(name string) string {
return fmt.Sprintf(`
resource "ibm_pi_cloud_connection" "cloud_connection" {
pi_cloud_instance_id = "%[1]s"
pi_cloud_connection_name = "%[2]s"
pi_cloud_connection_speed = 100
pi_cloud_connection_networks = [ibm_pi_network.network1.network_id]
}
resource "ibm_pi_network" "network1" {
pi_cloud_instance_id = "%[1]s"
pi_network_name = "%[2]s"
pi_network_type = "vlan"
pi_cidr = "192.112.111.0/24"
}
resource "ibm_pi_cloud_connection" "cloud_connection" {
pi_cloud_instance_id = "%[1]s"
pi_cloud_connection_name = "%[2]s"
pi_cloud_connection_speed = 100
pi_cloud_connection_networks = [ibm_pi_network.network1.network_id]
}
resource "ibm_pi_network" "network1" {
pi_cloud_instance_id = "%[1]s"
pi_network_name = "%[2]s"
pi_network_type = "vlan"
pi_cidr = "192.112.111.0/24"
}
`, acc.Pi_cloud_instance_id, name)
}

Expand Down Expand Up @@ -150,47 +150,47 @@ func TestAccIBMPICloudConnectionNetworks(t *testing.T) {

func testAccCheckIBMPICloudConnectionNetworkConfig(name string) string {
return fmt.Sprintf(`
resource "ibm_pi_cloud_connection" "cc_network" {
pi_cloud_instance_id = "%[1]s"
pi_cloud_connection_name = "%[2]s"
pi_cloud_connection_speed = 1000
pi_cloud_connection_networks = [ibm_pi_network.network1.network_id]
}
resource "ibm_pi_network" "network1" {
pi_cloud_instance_id = "%[1]s"
pi_network_name = "%[2]s_net1"
pi_network_type = "vlan"
pi_cidr = "192.112.112.0/24"
}
resource "ibm_pi_network" "network2" {
pi_cloud_instance_id = "%[1]s"
pi_network_name = "%[2]s_net2"
pi_network_type = "vlan"
pi_cidr = "192.112.113.0/24"
}
resource "ibm_pi_cloud_connection" "cc_network" {
pi_cloud_instance_id = "%[1]s"
pi_cloud_connection_name = "%[2]s"
pi_cloud_connection_speed = 1000
pi_cloud_connection_networks = [ibm_pi_network.network1.network_id]
}
resource "ibm_pi_network" "network1" {
pi_cloud_instance_id = "%[1]s"
pi_network_name = "%[2]s_net1"
pi_network_type = "vlan"
pi_cidr = "192.112.112.0/24"
}
resource "ibm_pi_network" "network2" {
pi_cloud_instance_id = "%[1]s"
pi_network_name = "%[2]s_net2"
pi_network_type = "vlan"
pi_cidr = "192.112.113.0/24"
}
`, acc.Pi_cloud_instance_id, name)
}

func testAccCheckIBMPICloudConnectionNetworkUpdateConfig(name string) string {
return fmt.Sprintf(`
resource "ibm_pi_cloud_connection" "cc_network" {
pi_cloud_instance_id = "%[1]s"
pi_cloud_connection_name = "%[2]s"
pi_cloud_connection_speed = 1000
pi_cloud_connection_networks = [ibm_pi_network.network2.network_id]
}
resource "ibm_pi_network" "network1" {
pi_cloud_instance_id = "%[1]s"
pi_network_name = "%[2]s_net1"
pi_network_type = "vlan"
pi_cidr = "192.112.112.0/24"
}
resource "ibm_pi_network" "network2" {
pi_cloud_instance_id = "%[1]s"
pi_network_name = "%[2]s_net2"
pi_network_type = "vlan"
pi_cidr = "192.112.113.0/24"
}
resource "ibm_pi_cloud_connection" "cc_network" {
pi_cloud_instance_id = "%[1]s"
pi_cloud_connection_name = "%[2]s"
pi_cloud_connection_speed = 1000
pi_cloud_connection_networks = [ibm_pi_network.network2.network_id]
}
resource "ibm_pi_network" "network1" {
pi_cloud_instance_id = "%[1]s"
pi_network_name = "%[2]s_net1"
pi_network_type = "vlan"
pi_cidr = "192.112.112.0/24"
}
resource "ibm_pi_network" "network2" {
pi_cloud_instance_id = "%[1]s"
pi_network_name = "%[2]s_net2"
pi_network_type = "vlan"
pi_cidr = "192.112.113.0/24"
}
`, acc.Pi_cloud_instance_id, name)
}

Expand Down Expand Up @@ -220,12 +220,12 @@ func TestAccIBMPICloudConnectionClassic(t *testing.T) {
}
func testAccCheckIBMPICloudConnectionClassicConfig(name string) string {
return fmt.Sprintf(`
resource "ibm_pi_cloud_connection" "classic" {
pi_cloud_instance_id = "%[1]s"
pi_cloud_connection_name = "%[2]s"
pi_cloud_connection_speed = 50
pi_cloud_connection_classic_enabled = true
}
resource "ibm_pi_cloud_connection" "classic" {
pi_cloud_instance_id = "%[1]s"
pi_cloud_connection_name = "%[2]s"
pi_cloud_connection_speed = 50
pi_cloud_connection_classic_enabled = true
}
`, acc.Pi_cloud_instance_id, name)
}

Expand Down Expand Up @@ -258,12 +258,55 @@ func TestAccIBMPICloudConnectionVPC(t *testing.T) {

func testAccCheckIBMPICloudConnectionVPCConfig(name string) string {
return fmt.Sprintf(`
resource "ibm_pi_cloud_connection" "vpc" {
pi_cloud_instance_id = "%[1]s"
pi_cloud_connection_name = "%[2]s"
pi_cloud_connection_speed = 50
pi_cloud_connection_vpc_enabled = true
pi_cloud_connection_vpc_crns = ["crn:v1:bluemix:public:is:us-south:a/d9cec80d0adc400ead8e2076afe26698::vpc:r006-6486cf73-451d-4d44-b90d-83dff504cbed"]
}
resource "ibm_pi_cloud_connection" "vpc" {
pi_cloud_instance_id = "%[1]s"
pi_cloud_connection_name = "%[2]s"
pi_cloud_connection_speed = 50
pi_cloud_connection_vpc_enabled = true
pi_cloud_connection_vpc_crns = ["crn:v1:bluemix:public:is:us-south:a/d9cec80d0adc400ead8e2076afe26698::vpc:r006-6486cf73-451d-4d44-b90d-83dff504cbed"]
}
`, acc.Pi_cloud_instance_id, name)
}

func TestAccIBMPICloudConnectionTransitGateway(t *testing.T) {
name := fmt.Sprintf("tf-cloudconnection-%d", acctest.RandIntRange(10, 100))
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIBMPICloudConnectionDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMPICloudConnectionConfigTransitGateway(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMPICloudConnectionExists("ibm_pi_cloud_connection.cloud_connection_transit"),
resource.TestCheckResourceAttr("ibm_pi_cloud_connection.cloud_connection_transit",
"pi_cloud_connection_name", name),
resource.TestCheckResourceAttr("ibm_pi_cloud_connection.cloud_connection_transit",
"pi_cloud_connection_speed", "100"),
resource.TestCheckResourceAttr("ibm_pi_cloud_connection.cloud_connection_transit",
"pi_cloud_connection_networks.#", "1"),
resource.TestCheckResourceAttr("ibm_pi_cloud_connection.cloud_connection_transit",
"pi_cloud_connection_transit_enabled", "true"),
),
},
},
})
}

func testAccCheckIBMPICloudConnectionConfigTransitGateway(name string) string {
return fmt.Sprintf(`
resource "ibm_pi_cloud_connection" "cloud_connection_transit" {
pi_cloud_instance_id = "%[1]s"
pi_cloud_connection_name = "%[2]s"
pi_cloud_connection_speed = 100
pi_cloud_connection_networks = [ibm_pi_network.network1.network_id]
pi_cloud_connection_transit_enabled = true
}
resource "ibm_pi_network" "network1" {
pi_cloud_instance_id = "%[1]s"
pi_network_name = "%[2]s"
pi_network_type = "vlan"
pi_cidr = "192.112.111.0/24"
}
`, acc.Pi_cloud_instance_id, name)
}
24 changes: 13 additions & 11 deletions website/docs/d/pi_cloud_connection.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,33 @@ data "ibm_pi_cloud_connection" "example" {
}
```

**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`

* 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"
zone = "lon04"
}
```

## 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_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account.
- `pi_cloud_connection_name` - (Required, String) The cloud connection name to be used.

## 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.

- `id` - (String) The unique identifier of the cloud connection.
- `classic_enabled` - (Bool) Is classic endpoint destination enabled?
Expand All @@ -60,3 +61,4 @@ In addition to all argument reference list, you can access the following attribu
- `user_ip_address` - (String) User IP address.
- `vpc_crns` - (Set of String) Set of VPCs attached to this cloud connection.
- `vpc_enabled` - (Bool) Is VPC enabled for this cloud connection?
- `connection_mode` - (String) Type of service the gateway is attached to.
Loading

0 comments on commit cd0e00b

Please sign in to comment.