provider/openstack: Add support for 'value_specs' param on 'openstack_networking_network_v2' provider.

This can be used to pass additional custom values to the netowrk
resource upon creation.
This commit is contained in:
Gavin Williams 2016-08-11 17:27:54 +01:00
parent 3481d1bf6e
commit 90efe68ce3
2 changed files with 54 additions and 3 deletions

View File

@ -53,10 +53,50 @@ func resourceNetworkingNetworkV2() *schema.Resource {
ForceNew: true,
Computed: true,
},
"value_specs": &schema.Schema{
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
},
},
}
}
// NetworkCreateOpts contains all teh values needed to create a new network.
type NetworkCreateOpts struct {
AdminStateUp *bool
Name string
Shared *bool
TenantID string
ValueSpecs map[string]string
}
// ToNetworkCreateMpa casts a networkCreateOpts struct to a map.
func (opts NetworkCreateOpts) ToNetworkCreateMap() (map[string]interface{}, error) {
n := make(map[string]interface{})
if opts.AdminStateUp != nil {
n["admin_state_up"] = &opts.AdminStateUp
}
if opts.Name != "" {
n["name"] = opts.Name
}
if opts.Shared != nil {
n["shared"] = &opts.Shared
}
if opts.TenantID != "" {
n["tenant_id"] = opts.TenantID
}
if opts.ValueSpecs != nil {
for k, v := range opts.ValueSpecs {
n[k] = v
}
}
return map[string]interface{}{"network": n}, nil
}
func resourceNetworkingNetworkV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
@ -64,9 +104,10 @@ func resourceNetworkingNetworkV2Create(d *schema.ResourceData, meta interface{})
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
createOpts := networks.CreateOpts{
Name: d.Get("name").(string),
TenantID: d.Get("tenant_id").(string),
createOpts := NetworkCreateOpts{
Name: d.Get("name").(string),
TenantID: d.Get("tenant_id").(string),
ValueSpecs: networkValueSpecs(d),
}
asuRaw := d.Get("admin_state_up").(string)
@ -249,3 +290,11 @@ func waitForNetworkDelete(networkingClient *gophercloud.ServiceClient, networkId
return n, "ACTIVE", nil
}
}
func networkValueSpecs(d *schema.ResourceData) map[string]string {
m := make(map[string]string)
for key, val := range d.Get("value_specs").(map[string]interface{}) {
m[key] = val.(string)
}
return m
}

View File

@ -82,6 +82,8 @@ The following arguments are supported:
Acceptable values are "true" and "false". Changing this value updates the
state of the existing network.
* `value_specs` - (Optional) Map of additional options.
## Attributes Reference
The following attributes are exported: