From d2b33d51b833c96f7755cbc8b774e516832a1028 Mon Sep 17 00:00:00 2001 From: Cristian Calin Date: Tue, 24 May 2016 16:31:09 +0300 Subject: [PATCH] provider/openstack allow specifying tenant_id on a floatingip resource Allow a cloud admin to target a specific tenant in which to allocate a floating IP. This is useful when the cloud admin does not want to delegate network privileges to the tenants or various Q&A scenarios. --- .../resource_openstack_networking_floatingip_v2.go | 8 ++++++++ .../openstack/r/networking_floatingip_v2.html.markdown | 10 ++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/builtin/providers/openstack/resource_openstack_networking_floatingip_v2.go b/builtin/providers/openstack/resource_openstack_networking_floatingip_v2.go index cdd85fc4a625..4dd6b1041b74 100644 --- a/builtin/providers/openstack/resource_openstack_networking_floatingip_v2.go +++ b/builtin/providers/openstack/resource_openstack_networking_floatingip_v2.go @@ -43,6 +43,12 @@ func resourceNetworkingFloatingIPV2() *schema.Resource { Optional: true, Computed: true, }, + "tenant_id": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, }, } } @@ -64,6 +70,7 @@ func resourceNetworkFloatingIPV2Create(d *schema.ResourceData, meta interface{}) createOpts := floatingips.CreateOpts{ FloatingNetworkID: poolID, PortID: d.Get("port_id").(string), + TenantID: d.Get("tenant_id").(string), } log.Printf("[DEBUG] Create Options: %#v", createOpts) floatingIP, err := floatingips.Create(networkingClient, createOpts).Extract() @@ -107,6 +114,7 @@ func resourceNetworkFloatingIPV2Read(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error retrieving floating IP pool name: %s", err) } d.Set("pool", poolName) + d.Set("tenant_id", floatingIP.TenantID) return nil } diff --git a/website/source/docs/providers/openstack/r/networking_floatingip_v2.html.markdown b/website/source/docs/providers/openstack/r/networking_floatingip_v2.html.markdown index fb1c57cbc4dd..e33dc8d98147 100644 --- a/website/source/docs/providers/openstack/r/networking_floatingip_v2.html.markdown +++ b/website/source/docs/providers/openstack/r/networking_floatingip_v2.html.markdown @@ -35,8 +35,13 @@ The following arguments are supported: * `pool` - (Required) The name of the pool from which to obtain the floating IP. Changing this creates a new floating IP. -* `port_id` - ID of an existing port with at least one IP address to associate with -this floating IP. +* `port_id` - (Optional) ID of an existing port with at least one IP address to + associate with this floating IP. + +* `tenant_id` - (Optional) The target tenant ID in which to allocate the floating + IP, if you specify this together with a port_id, make sure the target port + belongs to the same tenant. Changing this creates a new floating IP (which + may or may not have a different address) ## Attributes Reference @@ -46,3 +51,4 @@ The following attributes are exported: * `pool` - See Argument Reference above. * `address` - The actual floating IP address itself. * `port_id` - ID of associated port. +* `tenant_id` - the ID of the tenant in which to create the floating IP.