Skip to content

Commit

Permalink
Networking V2: add description to the floatingip resource (#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
kayrus authored and jtopjian committed Dec 15, 2018
1 parent 3e4cf29 commit 64a38cb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions openstack/resource_openstack_networking_floatingip_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func resourceNetworkingFloatingIPV2() *schema.Resource {
Computed: true,
ForceNew: true,
},
"description": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"address": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -100,6 +104,7 @@ func resourceNetworkFloatingIPV2Create(d *schema.ResourceData, meta interface{})
createOpts := FloatingIPCreateOpts{
floatingips.CreateOpts{
FloatingNetworkID: poolID,
Description: d.Get("description").(string),
FloatingIP: d.Get("address").(string),
PortID: d.Get("port_id").(string),
TenantID: d.Get("tenant_id").(string),
Expand Down Expand Up @@ -157,6 +162,7 @@ func resourceNetworkFloatingIPV2Read(d *schema.ResourceData, meta interface{}) e
return CheckDeleted(d, err, "floating IP")
}

d.Set("description", floatingIP.Description)
d.Set("address", floatingIP.FloatingIP)
d.Set("port_id", floatingIP.PortID)
d.Set("fixed_ip", floatingIP.FixedIP)
Expand All @@ -180,12 +186,22 @@ func resourceNetworkFloatingIPV2Update(d *schema.ResourceData, meta interface{})
return fmt.Errorf("Error creating OpenStack network client: %s", err)
}

var hasChange bool
var updateOpts floatingips.UpdateOpts

if d.HasChange("description") {
hasChange = true
description := d.Get("description").(string)
updateOpts.Description = &description
}

if d.HasChange("port_id") {
hasChange = true
portID := d.Get("port_id").(string)
updateOpts.PortID = &portID
}

if hasChange {
log.Printf("[DEBUG] Update Options: %#v", updateOpts)
_, err = floatingips.Update(networkingClient, d.Id(), updateOpts).Extract()
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions openstack/resource_openstack_networking_floatingip_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestAccNetworkingV2FloatingIP_basic(t *testing.T) {
Config: testAccNetworkingV2FloatingIP_basic,
Check: resource.ComposeTestCheckFunc(
testAccCheckNetworkingV2FloatingIPExists("openstack_networking_floatingip_v2.fip_1", &fip),
resource.TestCheckResourceAttr("openstack_networking_floatingip_v2.fip_1", "description", "test floating IP"),
),
},
},
Expand All @@ -42,6 +43,7 @@ func TestAccNetworkingV2FloatingIP_fixedip_bind(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckNetworkingV2FloatingIPExists("openstack_networking_floatingip_v2.fip_1", &fip),
testAccCheckNetworkingV2FloatingIPBoundToCorrectIP(&fip, "192.168.199.20"),
resource.TestCheckResourceAttr("openstack_networking_floatingip_v2.fip_1", "description", ""),
),
},
},
Expand Down Expand Up @@ -153,6 +155,7 @@ func testAccCheckNetworkingV2InstanceFloatingIPAttach(

const testAccNetworkingV2FloatingIP_basic = `
resource "openstack_networking_floatingip_v2" "fip_1" {
description = "test floating IP"
}
`

Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/networking_floatingip_v2.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ The following arguments are supported:
`region` argument of the provider is used. Changing this creates a new
floating IP (which may or may not have a different address).

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

* `pool` - (Required) The name of the pool from which to obtain the floating
IP. Changing this creates a new floating IP.

Expand Down Expand Up @@ -62,6 +64,7 @@ The following arguments are supported:
The following attributes are exported:

* `region` - See Argument Reference above.
* `description` - See Argument Reference above.
* `pool` - See Argument Reference above.
* `address` - The actual floating IP address itself.
* `port_id` - ID of associated port.
Expand Down

0 comments on commit 64a38cb

Please sign in to comment.