Skip to content

Commit

Permalink
fix(tg): fixed global change issue
Browse files Browse the repository at this point in the history
  • Loading branch information
uibm authored and hkantare committed May 31, 2024
1 parent f19d2b8 commit a42ffe3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
6 changes: 2 additions & 4 deletions ibm/service/transitgateway/resource_ibm_tg_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,8 @@ func resourceIBMTransitGatewayUpdate(d *schema.ResourceData, meta interface{}) e
}
}
if d.HasChange(tgGlobal) {
if tgwglobal, ok := d.GetOk(tgGlobal); ok {
global := tgwglobal.(bool)
updateTransitGatewayOptions.Global = &global
}
global := d.Get(tgGlobal).(bool)
updateTransitGatewayOptions.Global = &global
}
if d.HasChange(tgGatewayTags) {
oldList, newList := d.GetChange(tgGatewayTags)
Expand Down
53 changes: 53 additions & 0 deletions ibm/service/transitgateway/resource_ibm_tg_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,49 @@ func TestAccIBMTransitGateway_basic(t *testing.T) {
},
})
}
func TestAccIBMTransitGateway_globalUpdate(t *testing.T) {
var instance string
gatewayname := fmt.Sprintf("tg-gateway-name-%d", acctest.RandIntRange(10, 100))
newgatewayname := fmt.Sprintf("newgateway-name-%d", acctest.RandIntRange(10, 100))
location := "us-south"
globalTrue := true
globalFalse := false
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIBMTransitGatewayDestroy, // Delete test case
Steps: []resource.TestStep{
{
//Create test case
Config: testAccCheckIBMTransitGatewayGlobalUpdateConfig(gatewayname, location, globalTrue),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMTransitGatewayExists("ibm_tg_gateway.test_tg_gateway", instance),
resource.TestCheckResourceAttr("ibm_tg_gateway.test_tg_gateway", "name", gatewayname),
resource.TestCheckResourceAttr("ibm_tg_gateway.test_tg_gateway", "location", location),
resource.TestCheckResourceAttr("ibm_tg_gateway.test_tg_gateway", "global", fmt.Sprintf("%t", globalTrue)),
),
},
{
//Update test case
Config: testAccCheckIBMTransitGatewayGlobalUpdateConfig(newgatewayname, location, globalFalse),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMTransitGatewayExists("ibm_tg_gateway.test_tg_gateway", instance),
resource.TestCheckResourceAttr("ibm_tg_gateway.test_tg_gateway", "name", newgatewayname),
resource.TestCheckResourceAttr("ibm_tg_gateway.test_tg_gateway", "global", fmt.Sprintf("%t", globalFalse)),
),
},
{
//Update test case
Config: testAccCheckIBMTransitGatewayGlobalUpdateConfig(newgatewayname, location, globalTrue),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMTransitGatewayExists("ibm_tg_gateway.test_tg_gateway", instance),
resource.TestCheckResourceAttr("ibm_tg_gateway.test_tg_gateway", "name", newgatewayname),
resource.TestCheckResourceAttr("ibm_tg_gateway.test_tg_gateway", "global", fmt.Sprintf("%t", globalTrue)),
),
},
},
})
}

func testAccCheckIBMTransitGatewayConfig(gatewayname, location string) string {
return fmt.Sprintf(`
Expand All @@ -58,6 +101,16 @@ func testAccCheckIBMTransitGatewayConfig(gatewayname, location string) string {
}
`, gatewayname, location)
}
func testAccCheckIBMTransitGatewayGlobalUpdateConfig(gatewayname, location string, global bool) string {
return fmt.Sprintf(`
resource "ibm_tg_gateway" "test_tg_gateway"{
name="%s"
location="%s"
global=%t
}
`, gatewayname, location, global)
}

func testAccCheckIBMTransitGatewayExists(n string, instance string) resource.TestCheckFunc {
return func(s *terraform.State) error {
Expand Down

0 comments on commit a42ffe3

Please sign in to comment.