Merge pull request #9834 from fatmcgav/openstack_firewall_rule_v1_add_value_specs
provider/openstack: Add 'value_specs' option to 'openstack_fw_rule_v1' resource
This commit is contained in:
commit
c3d6bdd440
|
@ -74,6 +74,11 @@ func resourceFWRuleV1() *schema.Resource {
|
||||||
Optional: true,
|
Optional: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
"value_specs": &schema.Schema{
|
||||||
|
Type: schema.TypeMap,
|
||||||
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,18 +95,21 @@ func resourceFWRuleV1Create(d *schema.ResourceData, meta interface{}) error {
|
||||||
ipVersion := resourceFWRuleV1DetermineIPVersion(d.Get("ip_version").(int))
|
ipVersion := resourceFWRuleV1DetermineIPVersion(d.Get("ip_version").(int))
|
||||||
protocol := resourceFWRuleV1DetermineProtocol(d.Get("protocol").(string))
|
protocol := resourceFWRuleV1DetermineProtocol(d.Get("protocol").(string))
|
||||||
|
|
||||||
ruleConfiguration := rules.CreateOpts{
|
ruleConfiguration := RuleCreateOpts{
|
||||||
Name: d.Get("name").(string),
|
rules.CreateOpts{
|
||||||
Description: d.Get("description").(string),
|
Name: d.Get("name").(string),
|
||||||
Protocol: protocol,
|
Description: d.Get("description").(string),
|
||||||
Action: d.Get("action").(string),
|
Protocol: protocol,
|
||||||
IPVersion: ipVersion,
|
Action: d.Get("action").(string),
|
||||||
SourceIPAddress: d.Get("source_ip_address").(string),
|
IPVersion: ipVersion,
|
||||||
DestinationIPAddress: d.Get("destination_ip_address").(string),
|
SourceIPAddress: d.Get("source_ip_address").(string),
|
||||||
SourcePort: d.Get("source_port").(string),
|
DestinationIPAddress: d.Get("destination_ip_address").(string),
|
||||||
DestinationPort: d.Get("destination_port").(string),
|
SourcePort: d.Get("source_port").(string),
|
||||||
Enabled: &enabled,
|
DestinationPort: d.Get("destination_port").(string),
|
||||||
TenantID: d.Get("tenant_id").(string),
|
Enabled: &enabled,
|
||||||
|
TenantID: d.Get("tenant_id").(string),
|
||||||
|
},
|
||||||
|
MapValueSpecs(d),
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[DEBUG] Create firewall rule: %#v", ruleConfiguration)
|
log.Printf("[DEBUG] Create firewall rule: %#v", ruleConfiguration)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package openstack
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
|
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
|
||||||
|
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules"
|
||||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips"
|
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips"
|
||||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers"
|
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers"
|
||||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
|
"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
|
||||||
|
@ -69,6 +70,27 @@ func (opts RouterCreateOpts) ToRouterCreateMap() (map[string]interface{}, error)
|
||||||
return BuildRequest(opts, "router")
|
return BuildRequest(opts, "router")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RuleCreateOpts represents the attributes used when creating a new firewall rule.
|
||||||
|
type RuleCreateOpts struct {
|
||||||
|
rules.CreateOpts
|
||||||
|
ValueSpecs map[string]string `json:"value_specs,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToRuleCreateMap casts a CreateOpts struct to a map.
|
||||||
|
// It overrides rules.ToRuleCreateMap to add the ValueSpecs field.
|
||||||
|
func (opts RuleCreateOpts) ToRuleCreateMap() (map[string]interface{}, error) {
|
||||||
|
b, err := BuildRequest(opts, "firewall_rule")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if m := b["firewall_rule"].(map[string]interface{}); m["protocol"] == "any" {
|
||||||
|
m["protocol"] = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return b, nil
|
||||||
|
}
|
||||||
|
|
||||||
// SubnetCreateOpts represents the attributes used when creating a new subnet.
|
// SubnetCreateOpts represents the attributes used when creating a new subnet.
|
||||||
type SubnetCreateOpts struct {
|
type SubnetCreateOpts struct {
|
||||||
subnets.CreateOpts
|
subnets.CreateOpts
|
||||||
|
|
|
@ -73,6 +73,8 @@ The following arguments are supported:
|
||||||
wants to create a firewall rule for another tenant. Changing this creates a
|
wants to create a firewall rule for another tenant. Changing this creates a
|
||||||
new firewall rule.
|
new firewall rule.
|
||||||
|
|
||||||
|
* `value_specs` - (Optional) Map of additional options.
|
||||||
|
|
||||||
## Attributes Reference
|
## Attributes Reference
|
||||||
|
|
||||||
The following attributes are exported:
|
The following attributes are exported:
|
||||||
|
|
Loading…
Reference in New Issue