Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test that multiple nics work in google_compute_instance. #289

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions google/resource_compute_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -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 {
return fmt.Sprintf(`
resource "google_compute_instance" "foobar" {
Expand Down Expand Up @@ -1785,3 +1817,38 @@ resource "google_compute_disk" "foobar" {
}
`, 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)
}
3 changes: 1 addition & 2 deletions website/docs/r/compute_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ The following arguments are supported:
* `zone` - (Required) The zone that the machine should be created in.

* `network_interface` - (Required) Networks to attach to the instance. This can
be specified multiple times for multiple networks, but GCE is currently
limited to just 1. Structure is documented below.
be specified multiple times; multiple `network_interface` support is in Beta. Structure is documented below.

- - -

Expand Down