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

Modified TGW connection resource to support powerVS dependency… #4657

Merged
merged 6 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
2 changes: 1 addition & 1 deletion ibm/conns/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ func (sess clientSession) CisMtlsSession() (*cismtlsv1.MtlsV1, error) {
return sess.cisMtlsClient.Clone(), nil
}

//CIS Bot Management
sushmitha1506 marked this conversation as resolved.
Show resolved Hide resolved
// CIS Bot Management
func (sess clientSession) CisBotManagementSession() (*cisbotmanagementv1.BotManagementV1, error) {
if sess.cisBotManagementErr != nil {
return sess.cisBotManagementClient, sess.cisBotManagementErr
Expand Down
2 changes: 1 addition & 1 deletion ibm/service/cos/resource_ibm_cos_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ func TestAccIBMCOSHPCS(t *testing.T) {
})
}

//new hpcs
// new hpcs
func TestAccIBMCOSKPKmsParamValid(t *testing.T) {

instanceName := fmt.Sprintf("kms_%d", acctest.RandIntRange(10, 100))
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
7 changes: 4 additions & 3 deletions website/docs/d/tg_gateway.html.markdown
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
sushmitha1506 marked this conversation as resolved.
Show resolved Hide resolved

subcategory: "Transit Gateway"
layout: "ibm"
Expand All @@ -13,6 +12,7 @@ Retrieve information of an existing IBM Cloud infrastructure transit gateway as

## Example usage

---
```terraform
resource "ibm_tg_gateway" "new_tg_gw" {
name = "transit-gateway-1"
Expand All @@ -25,6 +25,7 @@ data "ibm_tg_gateway" "ds_tggateway" {
name = ibm_tg_gateway.new_tg_gw.name
}
```
---

## Argument reference
Review the argument references that you can specify for your data source.
Expand All @@ -44,11 +45,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`, or `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
8 changes: 6 additions & 2 deletions website/docs/r/tg_connection.html.markdown
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
sushmitha1506 marked this conversation as resolved.
Show resolved Hide resolved

subcategory: "Transit Gateway"
layout: "ibm"
page_title: "IBM : tg_connection"
Expand All @@ -11,6 +11,7 @@ Create, update and delete for the transit gateway's connection resource. For mor

## Example usage

---
```terraform
resource "ibm_tg_connection" "test_ibm_tg_connection" {
gateway = ibm_tg_gateway.test_tg_gateway.id
Expand All @@ -20,6 +21,7 @@ resource "ibm_tg_connection" "test_ibm_tg_connection" {
}

```
---

## Argument reference
Review the argument references that you can specify for your resource.
Expand All @@ -31,7 +33,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 Expand Up @@ -60,7 +62,9 @@ The `ibm_tg_connection` resource can be imported by using transit gateway ID and

**Example**

---
```
$ terraform import ibm_tg_connection.example 5ffda12064634723b079acdb018ef308/cea6651a-bd0a-4438-9f8a-a0770bbf3ebb

```
---