Merge pull request #8070 from fatmcgav/openstack_router_update_external_gw
provider/openstack: Add support for updating the External GW assigned to a Neutron router
This commit is contained in:
commit
38f0e62430
|
@ -213,6 +213,15 @@ func resourceNetworkingRouterV2Update(d *schema.ResourceData, meta interface{})
|
|||
asu := d.Get("admin_state_up").(bool)
|
||||
updateOpts.AdminStateUp = &asu
|
||||
}
|
||||
if d.HasChange("external_gateway") {
|
||||
externalGateway := d.Get("external_gateway").(string)
|
||||
if externalGateway != "" {
|
||||
gatewayInfo := routers.GatewayInfo{
|
||||
NetworkID: externalGateway,
|
||||
}
|
||||
updateOpts.GatewayInfo = &gatewayInfo
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Updating Router %s with options: %+v", d.Id(), updateOpts)
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package openstack
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
|
@ -34,6 +35,46 @@ func TestAccNetworkingV2Router_basic(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccNetworkingV2Router_update_external_gw(t *testing.T) {
|
||||
var router routers.Router
|
||||
externalGateway := os.Getenv("OS_EXTGW_ID")
|
||||
|
||||
var testAccNetworkingV2Router_update_external_gw_1 = fmt.Sprintf(`
|
||||
resource "openstack_networking_router_v2" "foo" {
|
||||
name = "router"
|
||||
admin_state_up = "true"
|
||||
distributed = "false"
|
||||
}`)
|
||||
|
||||
var testAccNetworkingV2Router_update_external_gw_2 = fmt.Sprintf(`
|
||||
resource "openstack_networking_router_v2" "foo" {
|
||||
name = "router"
|
||||
admin_state_up = "true"
|
||||
distributed = "false"
|
||||
external_gateway = "%s"
|
||||
}`, externalGateway)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckNetworkingV2RouterDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccNetworkingV2Router_update_external_gw_1,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckNetworkingV2RouterExists(t, "openstack_networking_router_v2.foo", &router),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
Config: testAccNetworkingV2Router_update_external_gw_2,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr("openstack_networking_router_v2.foo", "external_gateway", externalGateway),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccCheckNetworkingV2RouterDestroy(s *terraform.State) error {
|
||||
config := testAccProvider.Meta().(*Config)
|
||||
networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
|
||||
|
|
Loading…
Reference in New Issue