Skip to content

Commit

Permalink
Modified TGW connection resource to support powerVS dependency… (IBM-…
Browse files Browse the repository at this point in the history
…Cloud#4657)

* feat: modified TGW connection resource to support powerVS  dependency: None

* feat: terrafrom support for powerVs connection  dependency: None

* feat: modified TGW connection resource to support powerVS  dependency: None

* feat: terrafrom support for powerVs connection  dependency: None

* feat: terrafrom support for powerVs connection  dependency: None

---------

Co-authored-by: sushmitha M <sushmitham@sushmithas-MacBook-Pro.local>
  • Loading branch information
2 people authored and benbuchanan committed Aug 17, 2023
1 parent 60dde18 commit 9941cdf
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 13 deletions.
10 changes: 9 additions & 1 deletion ibm/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
"strconv"
"testing"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/provider"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/provider"
)

var AppIDTenantID string
Expand Down Expand Up @@ -191,6 +192,9 @@ var Image_cos_url string
var Image_cos_url_encrypted string
var Image_operating_system string

// Transit Gateway Power Virtual Server
var Tg_power_vs_network_id string

// Transit Gateway cross account
var Tg_cross_network_account_id string
var Tg_cross_network_account_api_key string
Expand Down Expand Up @@ -1128,6 +1132,10 @@ func init() {
if Tg_cross_network_id == "" {
fmt.Println("[INFO] Set the environment variable IBM_TG_CROSS_NETWORK_ID for testing ibm_tg_connection resource else tests will fail if this is not set correctly")
}
Tg_power_vs_network_id = os.Getenv("IBM_TG_POWER_VS_NETWORK_ID")
if Tg_power_vs_network_id == "" {
fmt.Println("[INFO] Set the environment variable IBM_TG_POWER_VS_NETWORK_ID for testing ibm_tg_connection resource else tests will fail if this is not set correctly")
}
Account_to_be_imported = os.Getenv("ACCOUNT_TO_BE_IMPORTED")
if Account_to_be_imported == "" {
fmt.Println("[INFO] Set the environment variable ACCOUNT_TO_BE_IMPORTED for testing import enterprise account resource else tests will fail if this is not set correctly")
Expand Down
11 changes: 6 additions & 5 deletions ibm/service/transitgateway/resource_ibm_tg_gateway_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
"log"
"time"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate"
"github.com/IBM/networking-go-sdk/transitgatewayapisv1"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate"
)

const (
Expand Down Expand Up @@ -73,7 +74,7 @@ func ResourceIBMTransitGatewayConnection() *schema.Resource {
Required: true,
ForceNew: true,
ValidateFunc: validate.InvokeValidator("ibm_tg_connection", tgNetworkType),
Description: "Defines what type of network is connected via this connection. Allowable values (classic,directlink,vpc,gre_tunnel,unbound_gre_tunnel)",
Description: "Defines what type of network is connected via this connection. Allowable values (classic,directlink,vpc,gre_tunnel,unbound_gre_tunnel,power_virtual_server)",
},
tgName: {
Type: schema.TypeString,
Expand All @@ -87,7 +88,7 @@ func ResourceIBMTransitGatewayConnection() *schema.Resource {
Optional: true,
Computed: true,
ForceNew: true,
Description: "The ID of the network being connected via this connection. This field is required for some types, such as 'vpc' or 'directlink'. The value of this is the CRN of the VPC or direct link gateway to be connected. This field is required to be unspecified for network type 'classic', 'gre_tunnel', and 'unbound_gre_tunnel'.",
Description: "The ID of the network being connected via this connection. This field is required for some types, such as 'vpc' or 'directlink' or 'power_virtual_server'. The value of this is the CRN of the VPC or direct link or power_virtual_server gateway to be connected. This field is required to be unspecified for network type 'classic', 'gre_tunnel', and 'unbound_gre_tunnel'.",
},
tgNetworkAccountID: {
Type: schema.TypeString,
Expand Down Expand Up @@ -182,7 +183,7 @@ func ResourceIBMTransitGatewayConnection() *schema.Resource {
func ResourceIBMTransitGatewayConnectionValidator() *validate.ResourceValidator {

validateSchema := make([]validate.ValidateSchema, 0)
networkType := "classic, directlink, vpc, gre_tunnel, unbound_gre_tunnel"
networkType := "classic, directlink, vpc, gre_tunnel, unbound_gre_tunnel, power_virtual_server"
validateSchema = append(validateSchema,
validate.ValidateSchema{
Identifier: tgNetworkType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"log"
"testing"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"

"github.com/IBM/networking-go-sdk/transitgatewayapisv1"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
)

func TestAccIBMTransitGatewayConnection_basic(t *testing.T) {
Expand Down Expand Up @@ -84,6 +84,15 @@ func TestAccIBMTransitGatewayConnection_basic(t *testing.T) {
resource.TestCheckResourceAttr("ibm_tg_connection.test_ibm_tg_dl_connection", "name", tgConnectionName),
),
},
// tg power vs test
{
//Create test case
Config: testAccCheckIBMTransitGatewayPowerVSConnectionConfig(gatewayName, tgConnectionName),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMTransitGatewayConnectionExists("ibm_tg_connection.test_tg_powervs_connection", tgConnection),
resource.TestCheckResourceAttr("ibm_tg_connection.test_tg_powervs_connection", "name", tgConnectionName),
),
},
},
},
)
Expand Down Expand Up @@ -218,6 +227,23 @@ resource "ibm_tg_connection" "test_ibm_tg_dl_connection"{
`, dlGatewayName, gatewayName, dlConnectionName)

}
func testAccCheckIBMTransitGatewayPowerVSConnectionConfig(gatewayName, powerVSConnName string) string {
return fmt.Sprintf(`
resource "ibm_tg_gateway" "test_tg_gateway"{
name="%s"
location="us-south"
global=true
}
resource "ibm_tg_connection" "test_tg_powervs_connection"{
gateway = "${ibm_tg_gateway.test_tg_gateway.id}"
network_type = "power_virtual_server"
name = "%s"
network_id = "%s"
}
`, gatewayName, powerVSConnName, acc.Tg_power_vs_network_id)
}

func transitgatewayClient(meta interface{}) (*transitgatewayapisv1.TransitGatewayApisV1, error) {
sess, err := meta.(conns.ClientSession).TransitGatewayV1API()
return sess, err
Expand Down
4 changes: 2 additions & 2 deletions website/docs/d/tg_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ In addition to the argument reference list, you can access the following attribu

Nested scheme for `connections`:
- `created_at` - (String) The date and time the connection is created.
- `id` - (String) The unique identifier for the transit gateway connection to network either `VPC`, `classic`.
- `id` - (String) The unique identifier for the transit gateway connection to network either `vpc`, `classic`.
- `base_connection_id` - (String) The ID of a network_type `classic` connection a tunnel is configured over. This field applies to network type `gre_tunnel` or `unbound_gre_tunnel` connections.
- `base_network_type` - (String) The type of network the unbound gre tunnel is targeting. This field is required for network type `unbound_gre_tunnel`.
- `name` - (String) The user-defined name for the transit gateway connection.
- `network_type` - (String) The type of network connected with the connection. Possible values are `classic`, `directlink`, `VPC`, `gre_tunnel`, or `unbound_gre_tunnel`).
- `network_type` - (String) The type of network connected with the connection. Possible values are `classic`, `directlink`, `vpc`, `gre_tunnel`, `unbound_gre_tunnel`, or `power_virtual_server`.
- `network_account_id` - (String) The ID of the network connected account. This is used if the network is in a different account than the gateway.
- `network_id` - (String) The ID of the network being connected with the connection.
- `local_bgp_asn` - (Integer) The local network BGP ASN. This field only applies to network type '`gre_tunnel` connections.
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/tg_connection.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Review the argument references that you can specify for your resource.
- `local_tunnel_ip` - (Optional, Forces new resource, String) - The local tunnel IP address. This field is required for and only applicable to type gre_tunnel connections.
- `name` - (Optional, String) Enter a name. If the name is not given, the default name is provided based on the network type, such as `vpc` for network type VPC and `classic` for network type classic.
- `network_account_id` - (Optional, Forces new resource, String) The ID of the network connected account. This is used if the network is in a different account than the gateway.
- `network_type` - (Required, Forces new resource, String) Enter the network type. Allowed values are `classic`, `directlink`, `gre_tunnel`, `unbound_gre_tunnel`, and `vpc`.
- `network_type` - (Required, Forces new resource, String) Enter the network type. Allowed values are `classic`, `directlink`, `gre_tunnel`, `unbound_gre_tunnel`, `vpc`, and `power_virtual_server`.
- `network_id` - (Optional, Forces new resource, String) Enter the ID of the network being connected through this connection. This parameter is required for network type `vpc` and `directlink`, the CRN of the VPC or direct link gateway to be connected. This field is required to be unspecified for network type `classic`. For example, `crn:v1:bluemix:public:is:us-south:a/123456::vpc:4727d842-f94f-4a2d-824a-9bc9b02c523b`.
- `remote_bgp_asn` - (Optional, Forces new resource, Integer) - The remote network BGP ASN (will be generated for the connection if not specified). This field only applies to network type `gre_tunnel` and `unbound_gre_tunnel` connections.
- `remote_gateway_ip` - (Optional, Forces new resource, String) - The remote gateway IP address. This field only applies to network type `gre_tunnel` and `unbound_gre_tunnel` connections.
Expand Down

0 comments on commit 9941cdf

Please sign in to comment.