Merge pull request #6844 from jtopjian/openstack-instance-network-fnr

provider/openstack: Rebuild On Network Changes
This commit is contained in:
Joe Topjian 2016-05-28 15:10:26 -06:00
commit 6430d790e7
3 changed files with 69 additions and 5 deletions

View File

@ -114,26 +114,31 @@ func resourceComputeInstanceV2() *schema.Resource {
"uuid": &schema.Schema{ "uuid": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
ForceNew: true,
Computed: true, Computed: true,
}, },
"name": &schema.Schema{ "name": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
ForceNew: true,
Computed: true, Computed: true,
}, },
"port": &schema.Schema{ "port": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
ForceNew: true,
Computed: true, Computed: true,
}, },
"fixed_ip_v4": &schema.Schema{ "fixed_ip_v4": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
ForceNew: true,
Computed: true, Computed: true,
}, },
"fixed_ip_v6": &schema.Schema{ "fixed_ip_v6": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
ForceNew: true,
Computed: true, Computed: true,
}, },
"floating_ip": &schema.Schema{ "floating_ip": &schema.Schema{

View File

@ -557,6 +557,53 @@ func TestAccComputeV2Instance_accessIPv4(t *testing.T) {
}) })
} }
func TestAccComputeV2Instance_ChangeFixedIP(t *testing.T) {
var instance1_1 servers.Server
var instance1_2 servers.Server
var testAccComputeV2Instance_ChangeFixedIP_1 = fmt.Sprintf(`
resource "openstack_compute_instance_v2" "instance_1" {
name = "instance_1"
security_groups = ["default"]
network {
uuid = "%s"
fixed_ip_v4 = "10.0.0.24"
}
}`,
os.Getenv("OS_NETWORK_ID"))
var testAccComputeV2Instance_ChangeFixedIP_2 = fmt.Sprintf(`
resource "openstack_compute_instance_v2" "instance_1" {
name = "instance_1"
security_groups = ["default"]
network {
uuid = "%s"
fixed_ip_v4 = "10.0.0.25"
}
}`,
os.Getenv("OS_NETWORK_ID"))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeV2InstanceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeV2Instance_ChangeFixedIP_1,
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.instance_1", &instance1_1),
),
},
resource.TestStep{
Config: testAccComputeV2Instance_ChangeFixedIP_2,
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.instance_1", &instance1_2),
testAccCheckComputeV2InstanceInstanceIDsDoNotMatch(&instance1_1, &instance1_2),
),
},
},
})
}
func testAccCheckComputeV2InstanceDestroy(s *terraform.State) error { func testAccCheckComputeV2InstanceDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config) config := testAccProvider.Meta().(*Config)
computeClient, err := config.computeV2Client(OS_REGION_NAME) computeClient, err := config.computeV2Client(OS_REGION_NAME)
@ -726,6 +773,15 @@ func testAccCheckComputeV2InstanceFloatingIPAttach(
} }
return fmt.Errorf("Floating IP %s was not attached to instance %s", fip.ID, instance.ID) return fmt.Errorf("Floating IP %s was not attached to instance %s", fip.ID, instance.ID)
}
}
func testAccCheckComputeV2InstanceInstanceIDsDoNotMatch(
instance1, instance2 *servers.Server) resource.TestCheckFunc {
return func(s *terraform.State) error {
if instance1.ID == instance2.ID {
return fmt.Errorf("Instance was not recreated.")
}
return nil
} }
} }

View File

@ -267,16 +267,19 @@ The following arguments are supported:
The `network` block supports: The `network` block supports:
* `uuid` - (Required unless `port` or `name` is provided) The network UUID to * `uuid` - (Required unless `port` or `name` is provided) The network UUID to
attach to the server. attach to the server. Changing this creates a new server.
* `name` - (Required unless `uuid` or `port` is provided) The human-readable * `name` - (Required unless `uuid` or `port` is provided) The human-readable
name of the network. name of the network. Changing this creates a new server.
* `port` - (Required unless `uuid` or `name` is provided) The port UUID of a * `port` - (Required unless `uuid` or `name` is provided) The port UUID of a
network to attach to the server. network to attach to the server. Changing this creates a new server.
* `fixed_ip_v4` - (Optional) Specifies a fixed IPv4 address to be used on this * `fixed_ip_v4` - (Optional) Specifies a fixed IPv4 address to be used on this
network. network. Changing this creates a new server.
* `fixed_ip_v6` - (Optional) Specifies a fixed IPv6 address to be used on this
network. Changing this creates a new server.
* `floating_ip` - (Optional) Specifies a floating IP address to be associated * `floating_ip` - (Optional) Specifies a floating IP address to be associated
with this network. Cannot be combined with a top-level floating IP. See with this network. Cannot be combined with a top-level floating IP. See