provider/openstack: Support Import of OpenStack FWaaS Resources (#7471)
This commit is contained in:
parent
421bda23b0
commit
8d8becdfdb
|
@ -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"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
|
@ -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"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
|
@ -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"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
|
@ -17,6 +17,9 @@ func resourceFWFirewallV1() *schema.Resource {
|
||||||
Read: resourceFWFirewallV1Read,
|
Read: resourceFWFirewallV1Read,
|
||||||
Update: resourceFWFirewallV1Update,
|
Update: resourceFWFirewallV1Update,
|
||||||
Delete: resourceFWFirewallV1Delete,
|
Delete: resourceFWFirewallV1Delete,
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"region": &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()
|
firewall, err := firewalls.Get(networkingClient, d.Id()).Extract()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return CheckDeleted(d, err, "firewall")
|
return CheckDeleted(d, err, "firewall")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("[DEBUG] Read OpenStack Firewall %s: %#v", d.Id(), firewall)
|
||||||
|
|
||||||
d.Set("name", firewall.Name)
|
d.Set("name", firewall.Name)
|
||||||
d.Set("description", firewall.Description)
|
d.Set("description", firewall.Description)
|
||||||
d.Set("policy_id", firewall.PolicyID)
|
d.Set("policy_id", firewall.PolicyID)
|
||||||
|
|
|
@ -16,6 +16,9 @@ func resourceFWPolicyV1() *schema.Resource {
|
||||||
Read: resourceFWPolicyV1Read,
|
Read: resourceFWPolicyV1Read,
|
||||||
Update: resourceFWPolicyV1Update,
|
Update: resourceFWPolicyV1Update,
|
||||||
Delete: resourceFWPolicyV1Delete,
|
Delete: resourceFWPolicyV1Delete,
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"region": &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()
|
policy, err := policies.Get(networkingClient, d.Id()).Extract()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return CheckDeleted(d, err, "FW policy")
|
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("name", policy.Name)
|
||||||
d.Set("description", policy.Description)
|
d.Set("description", policy.Description)
|
||||||
d.Set("shared", policy.Shared)
|
d.Set("shared", policy.Shared)
|
||||||
d.Set("audited", policy.Audited)
|
d.Set("audited", policy.Audited)
|
||||||
d.Set("tenant_id", policy.TenantID)
|
d.Set("tenant_id", policy.TenantID)
|
||||||
|
d.Set("rules", policy.Rules)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,9 @@ func resourceFWRuleV1() *schema.Resource {
|
||||||
Read: resourceFWRuleV1Read,
|
Read: resourceFWRuleV1Read,
|
||||||
Update: resourceFWRuleV1Update,
|
Update: resourceFWRuleV1Update,
|
||||||
Delete: resourceFWRuleV1Delete,
|
Delete: resourceFWRuleV1Delete,
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"region": &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()
|
rule, err := rules.Get(networkingClient, d.Id()).Extract()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return CheckDeleted(d, err, "FW rule")
|
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("protocol", rule.Protocol)
|
||||||
d.Set("action", rule.Action)
|
d.Set("action", rule.Action)
|
||||||
|
|
||||||
d.Set("name", rule.Name)
|
d.Set("name", rule.Name)
|
||||||
d.Set("description", rule.Description)
|
d.Set("description", rule.Description)
|
||||||
d.Set("ip_version", rule.IPVersion)
|
d.Set("ip_version", rule.IPVersion)
|
||||||
|
|
Loading…
Reference in New Issue