provider/openstack: gophercloud migration: networking secgroup
This commit is contained in:
parent
2f957e24fe
commit
f2ba380794
|
@ -9,8 +9,8 @@ import (
|
|||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/security/rules"
|
||||
"github.com/gophercloud/gophercloud"
|
||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules"
|
||||
)
|
||||
|
||||
func resourceNetworkingSecGroupRuleV2() *schema.Resource {
|
||||
|
@ -106,17 +106,29 @@ func resourceNetworkingSecGroupRuleV2Create(d *schema.ResourceData, meta interfa
|
|||
}
|
||||
|
||||
opts := rules.CreateOpts{
|
||||
Direction: d.Get("direction").(string),
|
||||
EtherType: d.Get("ethertype").(string),
|
||||
SecGroupID: d.Get("security_group_id").(string),
|
||||
PortRangeMin: d.Get("port_range_min").(int),
|
||||
PortRangeMax: d.Get("port_range_max").(int),
|
||||
Protocol: d.Get("protocol").(string),
|
||||
RemoteGroupID: d.Get("remote_group_id").(string),
|
||||
RemoteIPPrefix: d.Get("remote_ip_prefix").(string),
|
||||
TenantID: d.Get("tenant_id").(string),
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("direction"); ok {
|
||||
direction := resourceNetworkingSecGroupRuleV2DetermineDirection(v.(string))
|
||||
opts.Direction = direction
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("ethertype"); ok {
|
||||
ethertype := resourceNetworkingSecGroupRuleV2DetermineEtherType(v.(string))
|
||||
opts.EtherType = ethertype
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("protocol"); ok {
|
||||
protocol := resourceNetworkingSecGroupRuleV2DetermineProtocol(v.(string))
|
||||
opts.Protocol = protocol
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Create OpenStack Neutron security group: %#v", opts)
|
||||
|
||||
security_group_rule, err := rules.Create(networkingClient, opts).Extract()
|
||||
|
@ -185,13 +197,51 @@ func resourceNetworkingSecGroupRuleV2Delete(d *schema.ResourceData, meta interfa
|
|||
return err
|
||||
}
|
||||
|
||||
func resourceNetworkingSecGroupRuleV2DetermineDirection(v string) rules.RuleDirection {
|
||||
var direction rules.RuleDirection
|
||||
switch v {
|
||||
case "ingress":
|
||||
direction = rules.DirIngress
|
||||
case "egress":
|
||||
direction = rules.DirEgress
|
||||
}
|
||||
|
||||
return direction
|
||||
}
|
||||
|
||||
func resourceNetworkingSecGroupRuleV2DetermineEtherType(v string) rules.RuleEtherType {
|
||||
var etherType rules.RuleEtherType
|
||||
switch v {
|
||||
case "IPv4":
|
||||
etherType = rules.EtherType4
|
||||
case "IPv6":
|
||||
etherType = rules.EtherType6
|
||||
}
|
||||
|
||||
return etherType
|
||||
}
|
||||
|
||||
func resourceNetworkingSecGroupRuleV2DetermineProtocol(v string) rules.RuleProtocol {
|
||||
var protocol rules.RuleProtocol
|
||||
switch v {
|
||||
case "tcp":
|
||||
protocol = rules.ProtocolTCP
|
||||
case "udp":
|
||||
protocol = rules.ProtocolUDP
|
||||
case "icmp":
|
||||
protocol = rules.ProtocolICMP
|
||||
}
|
||||
|
||||
return protocol
|
||||
}
|
||||
|
||||
func waitForSecGroupRuleDelete(networkingClient *gophercloud.ServiceClient, secGroupRuleId string) resource.StateRefreshFunc {
|
||||
return func() (interface{}, string, error) {
|
||||
log.Printf("[DEBUG] Attempting to delete OpenStack Security Group Rule %s.\n", secGroupRuleId)
|
||||
|
||||
r, err := rules.Get(networkingClient, secGroupRuleId).Extract()
|
||||
if err != nil {
|
||||
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
|
||||
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
|
||||
if !ok {
|
||||
return r, "ACTIVE", err
|
||||
}
|
||||
|
@ -203,7 +253,7 @@ func waitForSecGroupRuleDelete(networkingClient *gophercloud.ServiceClient, secG
|
|||
|
||||
err = rules.Delete(networkingClient, secGroupRuleId).ExtractErr()
|
||||
if err != nil {
|
||||
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
|
||||
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
|
||||
if !ok {
|
||||
return r, "ACTIVE", err
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@ import (
|
|||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/security/groups"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/security/rules"
|
||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups"
|
||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules"
|
||||
)
|
||||
|
||||
func TestAccNetworkingV2SecGroupRule_basic(t *testing.T) {
|
||||
|
|
|
@ -8,8 +8,8 @@ import (
|
|||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/security/groups"
|
||||
"github.com/gophercloud/gophercloud"
|
||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups"
|
||||
)
|
||||
|
||||
func resourceNetworkingSecGroupV2() *schema.Resource {
|
||||
|
@ -131,7 +131,7 @@ func waitForSecGroupDelete(networkingClient *gophercloud.ServiceClient, secGroup
|
|||
|
||||
r, err := groups.Get(networkingClient, secGroupId).Extract()
|
||||
if err != nil {
|
||||
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
|
||||
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
|
||||
if !ok {
|
||||
return r, "ACTIVE", err
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ func waitForSecGroupDelete(networkingClient *gophercloud.ServiceClient, secGroup
|
|||
|
||||
err = groups.Delete(networkingClient, secGroupId).ExtractErr()
|
||||
if err != nil {
|
||||
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
|
||||
errCode, ok := err.(*gophercloud.ErrUnexpectedResponseCode)
|
||||
if !ok {
|
||||
return r, "ACTIVE", err
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
|
||||
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/security/groups"
|
||||
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups"
|
||||
)
|
||||
|
||||
func TestAccNetworkingV2SecGroup_basic(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue