provider/openstack: Support Import of OpenStack Networking Resources (#7661)
Router-based resources are not included. They will be added later.
This commit is contained in:
parent
5fc1b6870a
commit
bc5a8b827f
|
@ -0,0 +1,29 @@
|
||||||
|
package openstack
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAccOpenStackNetworkingFloatingIPV2_importBasic(t *testing.T) {
|
||||||
|
resourceName := "openstack_networking_floatingip_v2.foo"
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckNetworkingV2FloatingIPDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccNetworkingV2FloatingIP_basic,
|
||||||
|
},
|
||||||
|
|
||||||
|
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 TestAccOpenStackNetworkingNetworkV2_importBasic(t *testing.T) {
|
||||||
|
resourceName := "openstack_networking_network_v2.foo"
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckNetworkingV2NetworkDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccNetworkingV2Network_basic,
|
||||||
|
},
|
||||||
|
|
||||||
|
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 TestAccOpenStackNetworkingPortV2_importBasic(t *testing.T) {
|
||||||
|
resourceName := "openstack_networking_port_v2.foo"
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckNetworkingV2PortDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccNetworkingV2Port_basic,
|
||||||
|
},
|
||||||
|
|
||||||
|
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 TestAccOpenStackNetworkingSecGroupRuleV2_importBasic(t *testing.T) {
|
||||||
|
resourceName := "openstack_networking_secgroup_rule_v2.sr_foo"
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckNetworkingV2SecGroupRuleDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccNetworkingV2SecGroupRule_basic,
|
||||||
|
},
|
||||||
|
|
||||||
|
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 TestAccOpenStackNetworkingSecGroupV2_importBasic(t *testing.T) {
|
||||||
|
resourceName := "openstack_networking_secgroup_v2.foo"
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckNetworkingV2SecGroupDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccNetworkingV2SecGroup_basic,
|
||||||
|
},
|
||||||
|
|
||||||
|
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 TestAccOpenStackNetworkingSubnetV2_importBasic(t *testing.T) {
|
||||||
|
resourceName := "openstack_networking_subnet_v2.subnet_1"
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckNetworkingV2SubnetDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccNetworkingV2Subnet_basic,
|
||||||
|
},
|
||||||
|
|
||||||
|
resource.TestStep{
|
||||||
|
ResourceName: resourceName,
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
|
ImportStateVerifyIgnore: []string{"region"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
|
@ -20,6 +20,9 @@ func resourceNetworkingFloatingIPV2() *schema.Resource {
|
||||||
Read: resourceNetworkFloatingIPV2Read,
|
Read: resourceNetworkFloatingIPV2Read,
|
||||||
Update: resourceNetworkFloatingIPV2Update,
|
Update: resourceNetworkFloatingIPV2Update,
|
||||||
Delete: resourceNetworkFloatingIPV2Delete,
|
Delete: resourceNetworkFloatingIPV2Delete,
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"region": &schema.Schema{
|
"region": &schema.Schema{
|
||||||
|
|
|
@ -19,6 +19,9 @@ func resourceNetworkingNetworkV2() *schema.Resource {
|
||||||
Read: resourceNetworkingNetworkV2Read,
|
Read: resourceNetworkingNetworkV2Read,
|
||||||
Update: resourceNetworkingNetworkV2Update,
|
Update: resourceNetworkingNetworkV2Update,
|
||||||
Delete: resourceNetworkingNetworkV2Delete,
|
Delete: resourceNetworkingNetworkV2Delete,
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"region": &schema.Schema{
|
"region": &schema.Schema{
|
||||||
|
|
|
@ -18,6 +18,9 @@ func resourceNetworkingPortV2() *schema.Resource {
|
||||||
Read: resourceNetworkingPortV2Read,
|
Read: resourceNetworkingPortV2Read,
|
||||||
Update: resourceNetworkingPortV2Update,
|
Update: resourceNetworkingPortV2Update,
|
||||||
Delete: resourceNetworkingPortV2Delete,
|
Delete: resourceNetworkingPortV2Delete,
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"region": &schema.Schema{
|
"region": &schema.Schema{
|
||||||
|
|
|
@ -2,7 +2,6 @@ package openstack
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
@ -14,38 +13,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccNetworkingV2Port_basic(t *testing.T) {
|
func TestAccNetworkingV2Port_basic(t *testing.T) {
|
||||||
region := os.Getenv(OS_REGION_NAME)
|
|
||||||
|
|
||||||
var network networks.Network
|
var network networks.Network
|
||||||
var port ports.Port
|
var port ports.Port
|
||||||
var subnet subnets.Subnet
|
var subnet subnets.Subnet
|
||||||
|
|
||||||
var testAccNetworkingV2Port_basic = fmt.Sprintf(`
|
|
||||||
resource "openstack_networking_network_v2" "foo" {
|
|
||||||
region = "%s"
|
|
||||||
name = "network_1"
|
|
||||||
admin_state_up = "true"
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "openstack_networking_subnet_v2" "foo" {
|
|
||||||
region = "%s"
|
|
||||||
name = "subnet_1"
|
|
||||||
network_id = "${openstack_networking_network_v2.foo.id}"
|
|
||||||
cidr = "192.168.199.0/24"
|
|
||||||
ip_version = 4
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "openstack_networking_port_v2" "foo" {
|
|
||||||
region = "%s"
|
|
||||||
name = "port_1"
|
|
||||||
network_id = "${openstack_networking_network_v2.foo.id}"
|
|
||||||
admin_state_up = "true"
|
|
||||||
fixed_ip {
|
|
||||||
subnet_id = "${openstack_networking_subnet_v2.foo.id}"
|
|
||||||
ip_address = "192.168.199.23"
|
|
||||||
}
|
|
||||||
}`, region, region, region)
|
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
|
@ -64,35 +35,10 @@ func TestAccNetworkingV2Port_basic(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccNetworkingV2Port_noip(t *testing.T) {
|
func TestAccNetworkingV2Port_noip(t *testing.T) {
|
||||||
region := os.Getenv(OS_REGION_NAME)
|
|
||||||
|
|
||||||
var network networks.Network
|
var network networks.Network
|
||||||
var port ports.Port
|
var port ports.Port
|
||||||
var subnet subnets.Subnet
|
var subnet subnets.Subnet
|
||||||
|
|
||||||
var testAccNetworkingV2Port_noip = fmt.Sprintf(`
|
|
||||||
resource "openstack_networking_network_v2" "foo" {
|
|
||||||
region = "%s"
|
|
||||||
name = "network_1"
|
|
||||||
admin_state_up = "true"
|
|
||||||
}
|
|
||||||
resource "openstack_networking_subnet_v2" "foo" {
|
|
||||||
region = "%s"
|
|
||||||
name = "subnet_1"
|
|
||||||
network_id = "${openstack_networking_network_v2.foo.id}"
|
|
||||||
cidr = "192.168.199.0/24"
|
|
||||||
ip_version = 4
|
|
||||||
}
|
|
||||||
resource "openstack_networking_port_v2" "foo" {
|
|
||||||
region = "%s"
|
|
||||||
name = "port_1"
|
|
||||||
network_id = "${openstack_networking_network_v2.foo.id}"
|
|
||||||
admin_state_up = "true"
|
|
||||||
fixed_ip {
|
|
||||||
subnet_id = "${openstack_networking_subnet_v2.foo.id}"
|
|
||||||
}
|
|
||||||
}`, region, region, region)
|
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
|
@ -162,3 +108,46 @@ func testAccCheckNetworkingV2PortExists(t *testing.T, n string, port *ports.Port
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var testAccNetworkingV2Port_basic = fmt.Sprintf(`
|
||||||
|
resource "openstack_networking_network_v2" "foo" {
|
||||||
|
name = "network_1"
|
||||||
|
admin_state_up = "true"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "openstack_networking_subnet_v2" "foo" {
|
||||||
|
name = "subnet_1"
|
||||||
|
network_id = "${openstack_networking_network_v2.foo.id}"
|
||||||
|
cidr = "192.168.199.0/24"
|
||||||
|
ip_version = 4
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "openstack_networking_port_v2" "foo" {
|
||||||
|
name = "port_1"
|
||||||
|
network_id = "${openstack_networking_network_v2.foo.id}"
|
||||||
|
admin_state_up = "true"
|
||||||
|
fixed_ip {
|
||||||
|
subnet_id = "${openstack_networking_subnet_v2.foo.id}"
|
||||||
|
ip_address = "192.168.199.23"
|
||||||
|
}
|
||||||
|
}`)
|
||||||
|
|
||||||
|
var testAccNetworkingV2Port_noip = fmt.Sprintf(`
|
||||||
|
resource "openstack_networking_network_v2" "foo" {
|
||||||
|
name = "network_1"
|
||||||
|
admin_state_up = "true"
|
||||||
|
}
|
||||||
|
resource "openstack_networking_subnet_v2" "foo" {
|
||||||
|
name = "subnet_1"
|
||||||
|
network_id = "${openstack_networking_network_v2.foo.id}"
|
||||||
|
cidr = "192.168.199.0/24"
|
||||||
|
ip_version = 4
|
||||||
|
}
|
||||||
|
resource "openstack_networking_port_v2" "foo" {
|
||||||
|
name = "port_1"
|
||||||
|
network_id = "${openstack_networking_network_v2.foo.id}"
|
||||||
|
admin_state_up = "true"
|
||||||
|
fixed_ip {
|
||||||
|
subnet_id = "${openstack_networking_subnet_v2.foo.id}"
|
||||||
|
}
|
||||||
|
}`)
|
||||||
|
|
|
@ -18,6 +18,9 @@ func resourceNetworkingSecGroupRuleV2() *schema.Resource {
|
||||||
Create: resourceNetworkingSecGroupRuleV2Create,
|
Create: resourceNetworkingSecGroupRuleV2Create,
|
||||||
Read: resourceNetworkingSecGroupRuleV2Read,
|
Read: resourceNetworkingSecGroupRuleV2Read,
|
||||||
Delete: resourceNetworkingSecGroupRuleV2Delete,
|
Delete: resourceNetworkingSecGroupRuleV2Delete,
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"region": &schema.Schema{
|
"region": &schema.Schema{
|
||||||
|
@ -143,11 +146,14 @@ func resourceNetworkingSecGroupRuleV2Read(d *schema.ResourceData, meta interface
|
||||||
return CheckDeleted(d, err, "OpenStack Security Group Rule")
|
return CheckDeleted(d, err, "OpenStack Security Group Rule")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d.Set("direction", security_group_rule.Direction)
|
||||||
|
d.Set("ethertype", security_group_rule.EtherType)
|
||||||
d.Set("protocol", security_group_rule.Protocol)
|
d.Set("protocol", security_group_rule.Protocol)
|
||||||
d.Set("port_range_min", security_group_rule.PortRangeMin)
|
d.Set("port_range_min", security_group_rule.PortRangeMin)
|
||||||
d.Set("port_range_max", security_group_rule.PortRangeMax)
|
d.Set("port_range_max", security_group_rule.PortRangeMax)
|
||||||
d.Set("remote_group_id", security_group_rule.RemoteGroupID)
|
d.Set("remote_group_id", security_group_rule.RemoteGroupID)
|
||||||
d.Set("remote_ip_prefix", security_group_rule.RemoteIPPrefix)
|
d.Set("remote_ip_prefix", security_group_rule.RemoteIPPrefix)
|
||||||
|
d.Set("security_group_id", security_group_rule.SecGroupID)
|
||||||
d.Set("tenant_id", security_group_rule.TenantID)
|
d.Set("tenant_id", security_group_rule.TenantID)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,9 @@ func resourceNetworkingSecGroupV2() *schema.Resource {
|
||||||
Create: resourceNetworkingSecGroupV2Create,
|
Create: resourceNetworkingSecGroupV2Create,
|
||||||
Read: resourceNetworkingSecGroupV2Read,
|
Read: resourceNetworkingSecGroupV2Read,
|
||||||
Delete: resourceNetworkingSecGroupV2Delete,
|
Delete: resourceNetworkingSecGroupV2Delete,
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"region": &schema.Schema{
|
"region": &schema.Schema{
|
||||||
|
@ -91,6 +94,7 @@ func resourceNetworkingSecGroupV2Read(d *schema.ResourceData, meta interface{})
|
||||||
|
|
||||||
d.Set("description", security_group.Description)
|
d.Set("description", security_group.Description)
|
||||||
d.Set("tenant_id", security_group.TenantID)
|
d.Set("tenant_id", security_group.TenantID)
|
||||||
|
d.Set("name", security_group.Name)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,9 @@ func resourceNetworkingSubnetV2() *schema.Resource {
|
||||||
Read: resourceNetworkingSubnetV2Read,
|
Read: resourceNetworkingSubnetV2Read,
|
||||||
Update: resourceNetworkingSubnetV2Update,
|
Update: resourceNetworkingSubnetV2Update,
|
||||||
Delete: resourceNetworkingSubnetV2Delete,
|
Delete: resourceNetworkingSubnetV2Delete,
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"region": &schema.Schema{
|
"region": &schema.Schema{
|
||||||
|
@ -190,6 +193,8 @@ func resourceNetworkingSubnetV2Read(d *schema.ResourceData, meta interface{}) er
|
||||||
d.Set("gateway_ip", s.GatewayIP)
|
d.Set("gateway_ip", s.GatewayIP)
|
||||||
d.Set("dns_nameservers", s.DNSNameservers)
|
d.Set("dns_nameservers", s.DNSNameservers)
|
||||||
d.Set("host_routes", s.HostRoutes)
|
d.Set("host_routes", s.HostRoutes)
|
||||||
|
d.Set("enable_dhcp", s.EnableDHCP)
|
||||||
|
d.Set("network_id", s.NetworkID)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue