provider/openstack: Rename provider to loadbalancer_provider (#12239)

* provider/openstack: Rename provider to loadbalancer_provider

This commit renames provider to loadbalancer_provider in the
openstack_lb_loadbalancer_v2 resource.

It also changes security_group_ids to Computed so default
security groups are added to the state correctly.

* provider/openstack: Switch to a deprecation path for loadbalancer provider

This commit switches to using a deprecation path for removal of the
previous "provider" argument in favor of the new "loadbalancer_provider".
This commit is contained in:
Joe Topjian 2017-02-28 09:06:49 -07:00 committed by Paul Stack
parent 92d4809db3
commit 85de5f1e04
3 changed files with 23 additions and 5 deletions

View File

@ -76,6 +76,14 @@ func resourceLoadBalancerV2() *schema.Resource {
}, },
"provider": &schema.Schema{ "provider": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Deprecated: "Please use loadbalancer_provider",
},
"loadbalancer_provider": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Computed: true, Computed: true,
@ -85,6 +93,7 @@ func resourceLoadBalancerV2() *schema.Resource {
"security_group_ids": &schema.Schema{ "security_group_ids": &schema.Schema{
Type: schema.TypeSet, Type: schema.TypeSet,
Optional: true, Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString, Set: schema.HashString,
}, },
@ -99,6 +108,11 @@ func resourceLoadBalancerV2Create(d *schema.ResourceData, meta interface{}) erro
return fmt.Errorf("Error creating OpenStack networking client: %s", err) return fmt.Errorf("Error creating OpenStack networking client: %s", err)
} }
var lbProvider string
if v, ok := d.GetOk("loadbalancer_provider"); ok {
lbProvider = v.(string)
}
adminStateUp := d.Get("admin_state_up").(bool) adminStateUp := d.Get("admin_state_up").(bool)
createOpts := loadbalancers.CreateOpts{ createOpts := loadbalancers.CreateOpts{
Name: d.Get("name").(string), Name: d.Get("name").(string),
@ -108,7 +122,7 @@ func resourceLoadBalancerV2Create(d *schema.ResourceData, meta interface{}) erro
VipAddress: d.Get("vip_address").(string), VipAddress: d.Get("vip_address").(string),
AdminStateUp: &adminStateUp, AdminStateUp: &adminStateUp,
Flavor: d.Get("flavor").(string), Flavor: d.Get("flavor").(string),
Provider: d.Get("provider").(string), Provider: lbProvider,
} }
log.Printf("[DEBUG] Create Options: %#v", createOpts) log.Printf("[DEBUG] Create Options: %#v", createOpts)
@ -168,7 +182,7 @@ func resourceLoadBalancerV2Read(d *schema.ResourceData, meta interface{}) error
d.Set("vip_port_id", lb.VipPortID) d.Set("vip_port_id", lb.VipPortID)
d.Set("admin_state_up", lb.AdminStateUp) d.Set("admin_state_up", lb.AdminStateUp)
d.Set("flavor", lb.Flavor) d.Set("flavor", lb.Flavor)
d.Set("provider", lb.Provider) d.Set("loadbalancer_provider", lb.Provider)
// Get any security groups on the VIP Port // Get any security groups on the VIP Port
if lb.VipPortID != "" { if lb.VipPortID != "" {

View File

@ -190,6 +190,7 @@ resource "openstack_networking_subnet_v2" "subnet_1" {
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" { resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
name = "loadbalancer_1" name = "loadbalancer_1"
loadbalancer_provider = "haproxy"
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
} }
` `
@ -209,6 +210,7 @@ resource "openstack_networking_subnet_v2" "subnet_1" {
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" { resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
name = "loadbalancer_1_updated" name = "loadbalancer_1_updated"
loadbalancer_provider = "haproxy"
admin_state_up = "true" admin_state_up = "true"
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
} }

View File

@ -50,8 +50,10 @@ The following arguments are supported:
* `flavor` - (Optional) The UUID of a flavor. Changing this creates a new * `flavor` - (Optional) The UUID of a flavor. Changing this creates a new
loadbalancer. loadbalancer.
* `provider` - (Optional) The name of the provider. Changing this creates a new * `provider` - (Deprecated) Use `loadbalancer_provider` instead.
loadbalancer.
* `loadbalancer_provider` - (Optional) The name of the provider. Changing this
creates a new loadbalancer.
* `security_group_ids` - (Optional) A list of security group IDs to apply to the * `security_group_ids` - (Optional) A list of security group IDs to apply to the
loadbalancer. The security groups must be specified by ID and not name (as loadbalancer. The security groups must be specified by ID and not name (as
@ -69,6 +71,6 @@ The following attributes are exported:
* `vip_address` - See Argument Reference above. * `vip_address` - See Argument Reference above.
* `admin_state_up` - See Argument Reference above. * `admin_state_up` - See Argument Reference above.
* `flavor` - See Argument Reference above. * `flavor` - See Argument Reference above.
* `provider` - See Argument Reference above. * `loadbalancer_provider` - See Argument Reference above.
* `security_group_ids` - See Argument Reference above. * `security_group_ids` - See Argument Reference above.
* `vip_port_id` - The Port ID of the Load Balancer IP. * `vip_port_id` - The Port ID of the Load Balancer IP.