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

Networking V2: add description to the router resource #529

Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 12 additions & 0 deletions openstack/resource_openstack_networking_router_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ func resourceNetworkingRouterV2() *schema.Resource {
Optional: true,
ForceNew: false,
},
"description": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: false,
},
"admin_state_up": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -143,6 +148,7 @@ func resourceNetworkingRouterV2Create(d *schema.ResourceData, meta interface{})
createOpts := RouterCreateOpts{
routers.CreateOpts{
Name: d.Get("name").(string),
Description: d.Get("description").(string),
TenantID: d.Get("tenant_id").(string),
AvailabilityZoneHints: resourceNetworkingAvailabilityZoneHintsV2(d),
},
Expand Down Expand Up @@ -273,6 +279,7 @@ func resourceNetworkingRouterV2Read(d *schema.ResourceData, meta interface{}) er
log.Printf("[DEBUG] Retrieved Router %s: %+v", d.Id(), n)

d.Set("name", n.Name)
d.Set("description", n.Description)
d.Set("admin_state_up", n.AdminStateUp)
d.Set("distributed", n.Distributed)
d.Set("tenant_id", n.TenantID)
Expand Down Expand Up @@ -320,6 +327,11 @@ func resourceNetworkingRouterV2Update(d *schema.ResourceData, meta interface{})
hasChange = true
updateOpts.Name = d.Get("name").(string)
}
if d.HasChange("description") {
hasChange = true
description := d.Get("description").(string)
updateOpts.Description = &description
}
if d.HasChange("admin_state_up") {
hasChange = true
asu := d.Get("admin_state_up").(bool)
Expand Down
13 changes: 9 additions & 4 deletions openstack/resource_openstack_networking_router_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ func TestAccNetworkingV2Router_basic(t *testing.T) {
Config: testAccNetworkingV2Router_basic,
Check: resource.ComposeTestCheckFunc(
testAccCheckNetworkingV2RouterExists("openstack_networking_router_v2.router_1", &router),
resource.TestCheckResourceAttr(
"openstack_networking_router_v2.router_1", "description", "router description"),
),
},
resource.TestStep{
Config: testAccNetworkingV2Router_update,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"openstack_networking_router_v2.router_1", "name", "router_2"),
resource.TestCheckResourceAttr(
"openstack_networking_router_v2.router_1", "description", ""),
),
},
},
Expand Down Expand Up @@ -158,8 +162,9 @@ func testAccCheckNetworkingV2RouterExists(n string, router *routers.Router) reso

const testAccNetworkingV2Router_basic = `
resource "openstack_networking_router_v2" "router_1" {
name = "router_1"
admin_state_up = "true"
name = "router_1"
description = "router description"
admin_state_up = "true"

timeouts {
create = "5m"
Expand All @@ -170,8 +175,8 @@ resource "openstack_networking_router_v2" "router_1" {

const testAccNetworkingV2Router_update = `
resource "openstack_networking_router_v2" "router_1" {
name = "router_2"
admin_state_up = "true"
name = "router_2"
admin_state_up = "true"

timeouts {
create = "5m"
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/networking_router_v2.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ The following arguments are supported:
* `name` - (Optional) A unique name for the router. Changing this
updates the `name` of an existing router.

* `description` - (Optional) Human-readable description for the router.

* `admin_state_up` - (Optional) Administrative up/down status for the router
(must be "true" or "false" if provided). Changing this updates the
`admin_state_up` of an existing router.
Expand Down Expand Up @@ -92,6 +94,7 @@ The following attributes are exported:
* `id` - ID of the router.
* `region` - See Argument Reference above.
* `name` - See Argument Reference above.
* `description` - See Argument Reference above.
* `admin_state_up` - See Argument Reference above.
* `external_gateway` - See Argument Reference above.
* `external_network_id` - See Argument Reference above.
Expand Down