provider/openstack: Support Import of OpenStack FWaaS Resources (#7471)

This commit is contained in:
Joe Topjian 2016-07-03 09:37:35 -06:00 committed by Paul Stack
parent 421bda23b0
commit 8d8becdfdb
6 changed files with 103 additions and 4 deletions

View File

@ -0,0 +1,29 @@
package openstack
import (
"testing"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccOpenStackFWFirewallV1_importBasic(t *testing.T) {
resourceName := "openstack_fw_firewall_v1.accept_test"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckFWFirewallV1Destroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testFirewallConfig,
},
resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})
}

View File

@ -0,0 +1,29 @@
package openstack
import (
"testing"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccOpenStackFWPolicyV1_importBasic(t *testing.T) {
resourceName := "openstack_fw_policy_v1.accept_test"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckFWPolicyV1Destroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testFirewallPolicyConfigAddRules,
},
resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})
}

View File

@ -0,0 +1,29 @@
package openstack
import (
"testing"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccOpenStackFWRuleV1_importBasic(t *testing.T) {
resourceName := "openstack_fw_rule_v1.accept_test"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckFWRuleV1Destroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testFirewallRuleConfig,
},
resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})
}

View File

@ -17,6 +17,9 @@ func resourceFWFirewallV1() *schema.Resource {
Read: resourceFWFirewallV1Read,
Update: resourceFWFirewallV1Update,
Delete: resourceFWFirewallV1Delete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"region": &schema.Schema{
@ -105,11 +108,12 @@ func resourceFWFirewallV1Read(d *schema.ResourceData, meta interface{}) error {
}
firewall, err := firewalls.Get(networkingClient, d.Id()).Extract()
if err != nil {
return CheckDeleted(d, err, "firewall")
}
log.Printf("[DEBUG] Read OpenStack Firewall %s: %#v", d.Id(), firewall)
d.Set("name", firewall.Name)
d.Set("description", firewall.Description)
d.Set("policy_id", firewall.PolicyID)

View File

@ -16,6 +16,9 @@ func resourceFWPolicyV1() *schema.Resource {
Read: resourceFWPolicyV1Read,
Update: resourceFWPolicyV1Update,
Delete: resourceFWPolicyV1Delete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"region": &schema.Schema{
@ -111,16 +114,18 @@ func resourceFWPolicyV1Read(d *schema.ResourceData, meta interface{}) error {
}
policy, err := policies.Get(networkingClient, d.Id()).Extract()
if err != nil {
return CheckDeleted(d, err, "FW policy")
}
log.Printf("[DEBUG] Read OpenStack Firewall Policy %s: %#v", d.Id(), policy)
d.Set("name", policy.Name)
d.Set("description", policy.Description)
d.Set("shared", policy.Shared)
d.Set("audited", policy.Audited)
d.Set("tenant_id", policy.TenantID)
d.Set("rules", policy.Rules)
return nil
}

View File

@ -15,6 +15,9 @@ func resourceFWRuleV1() *schema.Resource {
Read: resourceFWRuleV1Read,
Update: resourceFWRuleV1Update,
Delete: resourceFWRuleV1Delete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"region": &schema.Schema{
@ -123,14 +126,14 @@ func resourceFWRuleV1Read(d *schema.ResourceData, meta interface{}) error {
}
rule, err := rules.Get(networkingClient, d.Id()).Extract()
if err != nil {
return CheckDeleted(d, err, "FW rule")
}
log.Printf("[DEBUG] Read OpenStack Firewall Rule %s: %#v", d.Id(), rule)
d.Set("protocol", rule.Protocol)
d.Set("action", rule.Action)
d.Set("name", rule.Name)
d.Set("description", rule.Description)
d.Set("ip_version", rule.IPVersion)