diff --git a/builtin/providers/openstack/resource_openstack_fw_firewall_v1.go b/builtin/providers/openstack/resource_openstack_fw_firewall_v1.go index d43313763..b411cdc49 100644 --- a/builtin/providers/openstack/resource_openstack_fw_firewall_v1.go +++ b/builtin/providers/openstack/resource_openstack_fw_firewall_v1.go @@ -5,10 +5,10 @@ import ( "log" "time" + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" - "github.com/rackspace/gophercloud" - "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls" ) func resourceFWFirewallV1() *schema.Resource { @@ -231,7 +231,7 @@ func waitForFirewallDeletion(networkingClient *gophercloud.ServiceClient, id str log.Printf("[DEBUG] Get firewall %s => %#v", id, fw) if err != nil { - httpStatus := err.(*gophercloud.UnexpectedResponseCodeError) + httpStatus := err.(*gophercloud.ErrUnexpectedResponseCode) log.Printf("[DEBUG] Get firewall %s status is %d", id, httpStatus.Actual) if httpStatus.Actual == 404 { diff --git a/builtin/providers/openstack/resource_openstack_fw_firewall_v1_test.go b/builtin/providers/openstack/resource_openstack_fw_firewall_v1_test.go index e5b814fd1..1def9f478 100644 --- a/builtin/providers/openstack/resource_openstack_fw_firewall_v1_test.go +++ b/builtin/providers/openstack/resource_openstack_fw_firewall_v1_test.go @@ -5,10 +5,10 @@ import ( "testing" "time" + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" - "github.com/rackspace/gophercloud" - "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls" ) func TestAccFWFirewallV1_basic(t *testing.T) { @@ -51,7 +51,7 @@ func testAccCheckFWFirewallV1Destroy(s *terraform.State) error { if err == nil { return fmt.Errorf("Firewall (%s) still exists.", rs.Primary.ID) } - httpError, ok := err.(*gophercloud.UnexpectedResponseCodeError) + httpError, ok := err.(*gophercloud.ErrUnexpectedResponseCode) if !ok || httpError.Actual != 404 { return httpError } @@ -84,7 +84,7 @@ func testAccCheckFWFirewallV1Exists(n, expectedName, expectedDescription string, // if we get a 404 error. Fail on any other error. found, err = firewalls.Get(networkingClient, rs.Primary.ID).Extract() if err != nil { - httpError, ok := err.(*gophercloud.UnexpectedResponseCodeError) + httpError, ok := err.(*gophercloud.ErrUnexpectedResponseCode) if !ok || httpError.Actual != 404 { time.Sleep(time.Second) continue diff --git a/builtin/providers/openstack/resource_openstack_fw_policy_v1.go b/builtin/providers/openstack/resource_openstack_fw_policy_v1.go index 339f7fd2b..13033afa3 100644 --- a/builtin/providers/openstack/resource_openstack_fw_policy_v1.go +++ b/builtin/providers/openstack/resource_openstack_fw_policy_v1.go @@ -5,9 +5,9 @@ import ( "log" "time" + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies" "github.com/hashicorp/terraform/helper/schema" - "github.com/rackspace/gophercloud" - "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/fwaas/policies" ) func resourceFWPolicyV1() *schema.Resource { @@ -186,7 +186,7 @@ func resourceFWPolicyV1Delete(d *schema.ResourceData, meta interface{}) error { break } - httpError, ok := err.(*gophercloud.UnexpectedResponseCodeError) + httpError, ok := err.(*gophercloud.ErrUnexpectedResponseCode) if !ok || httpError.Actual != 409 { return err } diff --git a/builtin/providers/openstack/resource_openstack_fw_policy_v1_test.go b/builtin/providers/openstack/resource_openstack_fw_policy_v1_test.go index 1e76e410d..633f0207b 100644 --- a/builtin/providers/openstack/resource_openstack_fw_policy_v1_test.go +++ b/builtin/providers/openstack/resource_openstack_fw_policy_v1_test.go @@ -5,10 +5,10 @@ import ( "testing" "time" + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" - "github.com/rackspace/gophercloud" - "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/fwaas/policies" ) func TestAccFWPolicyV1_basic(t *testing.T) { @@ -80,7 +80,7 @@ func testAccCheckFWPolicyV1Destroy(s *terraform.State) error { if err == nil { return fmt.Errorf("Firewall policy (%s) still exists.", rs.Primary.ID) } - httpError, ok := err.(*gophercloud.UnexpectedResponseCodeError) + httpError, ok := err.(*gophercloud.ErrUnexpectedResponseCode) if !ok || httpError.Actual != 404 { return httpError } @@ -113,7 +113,7 @@ func testAccCheckFWPolicyV1Exists(n, name, description string, ruleCount int) re // if we get a 404 error. Fail on any other error. found, err = policies.Get(networkingClient, rs.Primary.ID).Extract() if err != nil { - httpError, ok := err.(*gophercloud.UnexpectedResponseCodeError) + httpError, ok := err.(*gophercloud.ErrUnexpectedResponseCode) if !ok || httpError.Actual != 404 { time.Sleep(time.Second) continue diff --git a/builtin/providers/openstack/resource_openstack_fw_rule_v1.go b/builtin/providers/openstack/resource_openstack_fw_rule_v1.go index e336a60eb..391880498 100644 --- a/builtin/providers/openstack/resource_openstack_fw_rule_v1.go +++ b/builtin/providers/openstack/resource_openstack_fw_rule_v1.go @@ -4,9 +4,10 @@ import ( "fmt" "log" + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules" "github.com/hashicorp/terraform/helper/schema" - "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/fwaas/policies" - "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/fwaas/rules" ) func resourceFWRuleV1() *schema.Resource { @@ -86,13 +87,14 @@ func resourceFWRuleV1Create(d *schema.ResourceData, meta interface{}) error { } enabled := d.Get("enabled").(bool) + ipVersion := resourceFWRuleV1DetermineIPVersion(d.Get("ip_version").(int)) ruleConfiguration := rules.CreateOpts{ Name: d.Get("name").(string), Description: d.Get("description").(string), Protocol: d.Get("protocol").(string), Action: d.Get("action").(string), - IPVersion: d.Get("ip_version").(int), + IPVersion: ipVersion, SourceIPAddress: d.Get("source_ip_address").(string), DestinationIPAddress: d.Get("destination_ip_address").(string), SourcePort: d.Get("source_port").(string), @@ -101,6 +103,11 @@ func resourceFWRuleV1Create(d *schema.ResourceData, meta interface{}) error { TenantID: d.Get("tenant_id").(string), } + if v, ok := d.GetOk("ip_version"); ok { + ipVersion := resourceFWRuleV1DetermineIPVersion(v.(int)) + ruleConfiguration.IPVersion = ipVersion + } + log.Printf("[DEBUG] Create firewall rule: %#v", ruleConfiguration) rule, err := rules.Create(networkingClient, ruleConfiguration).Extract() @@ -156,39 +163,54 @@ func resourceFWRuleV1Update(d *schema.ResourceData, meta interface{}) error { opts := rules.UpdateOpts{} if d.HasChange("name") { - opts.Name = d.Get("name").(string) + v := d.Get("name").(string) + opts.Name = &v } + if d.HasChange("description") { - opts.Description = d.Get("description").(string) + v := d.Get("description").(string) + opts.Description = &v } + if d.HasChange("protocol") { - opts.Protocol = d.Get("protocol").(string) + v := d.Get("protocol").(string) + opts.Protocol = &v } + if d.HasChange("action") { - opts.Action = d.Get("action").(string) + v := d.Get("action").(string) + opts.Action = &v } + if d.HasChange("ip_version") { - opts.IPVersion = d.Get("ip_version").(int) + v := d.Get("ip_version").(int) + ipVersion := resourceFWRuleV1DetermineIPVersion(v) + opts.IPVersion = &ipVersion } + if d.HasChange("source_ip_address") { - sourceIPAddress := d.Get("source_ip_address").(string) - opts.SourceIPAddress = &sourceIPAddress + v := d.Get("source_ip_address").(string) + opts.SourceIPAddress = &v } + if d.HasChange("destination_ip_address") { - destinationIPAddress := d.Get("destination_ip_address").(string) - opts.DestinationIPAddress = &destinationIPAddress + v := d.Get("destination_ip_address").(string) + opts.DestinationIPAddress = &v } + if d.HasChange("source_port") { - sourcePort := d.Get("source_port").(string) - opts.SourcePort = &sourcePort + v := d.Get("source_port").(string) + opts.SourcePort = &v } + if d.HasChange("destination_port") { - destinationPort := d.Get("destination_port").(string) - opts.DestinationPort = &destinationPort + v := d.Get("destination_port").(string) + opts.DestinationPort = &v } + if d.HasChange("enabled") { - enabled := d.Get("enabled").(bool) - opts.Enabled = &enabled + v := d.Get("enabled").(bool) + opts.Enabled = &v } log.Printf("[DEBUG] Updating firewall rules: %#v", opts) @@ -216,7 +238,7 @@ func resourceFWRuleV1Delete(d *schema.ResourceData, meta interface{}) error { } if rule.PolicyID != "" { - err := policies.RemoveRule(networkingClient, rule.PolicyID, rule.ID) + _, err := policies.RemoveRule(networkingClient, rule.PolicyID, rule.ID).Extract() if err != nil { return err } @@ -224,3 +246,16 @@ func resourceFWRuleV1Delete(d *schema.ResourceData, meta interface{}) error { return rules.Delete(networkingClient, d.Id()).Err } + +func resourceFWRuleV1DetermineIPVersion(ipv int) gophercloud.IPVersion { + // Determine the IP Version + var ipVersion gophercloud.IPVersion + switch ipv { + case 4: + ipVersion = gophercloud.IPv4 + case 6: + ipVersion = gophercloud.IPv6 + } + + return ipVersion +} diff --git a/builtin/providers/openstack/resource_openstack_fw_rule_v1_test.go b/builtin/providers/openstack/resource_openstack_fw_rule_v1_test.go index 677e7cd01..8ca8b0cec 100644 --- a/builtin/providers/openstack/resource_openstack_fw_rule_v1_test.go +++ b/builtin/providers/openstack/resource_openstack_fw_rule_v1_test.go @@ -6,10 +6,10 @@ import ( "testing" "time" + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" - "github.com/rackspace/gophercloud" - "github.com/rackspace/gophercloud/openstack/networking/v2/extensions/fwaas/rules" ) func TestAccFWRuleV1_basic(t *testing.T) { @@ -88,7 +88,7 @@ func testAccCheckFWRuleV1Destroy(s *terraform.State) error { if err == nil { return fmt.Errorf("Firewall rule (%s) still exists.", rs.Primary.ID) } - httpError, ok := err.(*gophercloud.UnexpectedResponseCodeError) + httpError, ok := err.(*gophercloud.ErrUnexpectedResponseCode) if !ok || httpError.Actual != 404 { return httpError } @@ -121,7 +121,7 @@ func testAccCheckFWRuleV1Exists(n string, expected *rules.Rule) resource.TestChe // if we get a 404 error. Fail on any other error. found, err = rules.Get(networkingClient, rs.Primary.ID).Extract() if err != nil { - httpError, ok := err.(*gophercloud.UnexpectedResponseCodeError) + httpError, ok := err.(*gophercloud.ErrUnexpectedResponseCode) if !ok || httpError.Actual != 404 { time.Sleep(time.Second) continue