mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-09 03:28:29 +00:00
Add a test that multiple nics work in google_compute_instance. (#289)
* Add a test that multiple nics works in google_compute_instance. * Add note that multiple nics is in Beta.
This commit is contained in:
parent
5e9a071879
commit
a4e1083fd1
|
@ -673,6 +673,28 @@ func TestAccComputeInstance_forceChangeMachineTypeManually(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccComputeInstance_multiNic(t *testing.T) {
|
||||||
|
var instance compute.Instance
|
||||||
|
instanceName := fmt.Sprintf("terraform-test-%s", acctest.RandString(10))
|
||||||
|
networkName := fmt.Sprintf("terraform-test-%s", acctest.RandString(10))
|
||||||
|
subnetworkName := fmt.Sprintf("terraform-test-%s", acctest.RandString(10))
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccComputeInstance_multiNic(instanceName, networkName, subnetworkName),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckComputeInstanceExists("google_compute_instance.foobar", &instance),
|
||||||
|
testAccCheckComputeInstanceHasMultiNic(&instance),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckComputeInstanceUpdateMachineType(n string) resource.TestCheckFunc {
|
func testAccCheckComputeInstanceUpdateMachineType(n string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
@ -998,6 +1020,16 @@ func testAccCheckComputeInstanceHasAddress(instance *compute.Instance, address s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeInstanceHasMultiNic(instance *compute.Instance) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
if len(instance.NetworkInterfaces) < 2 {
|
||||||
|
return fmt.Errorf("only saw %d nics", len(instance.NetworkInterfaces))
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testAccComputeInstance_basic_deprecated_network(instance string) string {
|
func testAccComputeInstance_basic_deprecated_network(instance string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_compute_instance" "foobar" {
|
resource "google_compute_instance" "foobar" {
|
||||||
|
@ -1785,3 +1817,38 @@ resource "google_compute_disk" "foobar" {
|
||||||
}
|
}
|
||||||
`, instance, disk)
|
`, instance, disk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccComputeInstance_multiNic(instance, network, subnetwork string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
resource "google_compute_instance" "foobar" {
|
||||||
|
name = "%s"
|
||||||
|
machine_type = "n1-standard-1"
|
||||||
|
zone = "us-central1-a"
|
||||||
|
|
||||||
|
boot_disk {
|
||||||
|
initialize_params{
|
||||||
|
image = "debian-8-jessie-v20160803"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
network_interface {
|
||||||
|
subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.name}"
|
||||||
|
access_config { }
|
||||||
|
}
|
||||||
|
|
||||||
|
network_interface {
|
||||||
|
network = "default"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_compute_network" "inst-test-network" {
|
||||||
|
name = "%s"
|
||||||
|
}
|
||||||
|
resource "google_compute_subnetwork" "inst-test-subnetwork" {
|
||||||
|
name = "%s"
|
||||||
|
ip_cidr_range = "10.0.0.0/16"
|
||||||
|
region = "us-central1"
|
||||||
|
network = "${google_compute_network.inst-test-network.self_link}"
|
||||||
|
}
|
||||||
|
`, instance, network, subnetwork)
|
||||||
|
}
|
||||||
|
|
|
@ -71,8 +71,7 @@ The following arguments are supported:
|
||||||
* `zone` - (Required) The zone that the machine should be created in.
|
* `zone` - (Required) The zone that the machine should be created in.
|
||||||
|
|
||||||
* `network_interface` - (Required) Networks to attach to the instance. This can
|
* `network_interface` - (Required) Networks to attach to the instance. This can
|
||||||
be specified multiple times for multiple networks, but GCE is currently
|
be specified multiple times; multiple `network_interface` support is in Beta. Structure is documented below.
|
||||||
limited to just 1. Structure is documented below.
|
|
||||||
|
|
||||||
- - -
|
- - -
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user