-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
provider/google: Changed network argument in google_compute_instance_group as optional #13493
Changes from 1 commit
bc66484
fe1c0d6
b8c6c40
086059f
c65eca2
4aa065c
28f0d5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,19 +14,29 @@ import ( | |
func TestAccComputeInstanceGroup_basic(t *testing.T) { | ||
var instanceGroup compute.InstanceGroup | ||
var instanceName = fmt.Sprintf("instancegroup-test-%s", acctest.RandString(10)) | ||
projs := []string{ | ||
"GOOGLE_PROJECT", | ||
"GCLOUD_PROJECT", | ||
"CLOUDSDK_CORE_PROJECT", | ||
} | ||
var network = fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/networks/default", multiEnvSearch(projs)) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccComputeInstanceGroup_destroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccComputeInstanceGroup_basic(instanceName), | ||
Config: testAccComputeInstanceGroup_basic(instanceName, network), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccComputeInstanceGroup_exists( | ||
"google_compute_instance_group.basic", &instanceGroup), | ||
testAccComputeInstanceGroup_exists( | ||
"google_compute_instance_group.empty", &instanceGroup), | ||
testAccComputeInstanceGroup_exists( | ||
"google_compute_instance_group.empty-with-network", &instanceGroup), | ||
testAccComputeInstanceGroup_network( | ||
"google_compute_instance_group.empty-with-network", network, &instanceGroup), | ||
), | ||
}, | ||
}, | ||
|
@@ -201,7 +211,34 @@ func testAccComputeInstanceGroup_named_ports(n string, np map[string]int64, inst | |
} | ||
} | ||
|
||
func testAccComputeInstanceGroup_basic(instance string) string { | ||
func testAccComputeInstanceGroup_network(n string, network string, instanceGroup *compute.InstanceGroup) resource.TestCheckFunc { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: can you rename this to something like |
||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("Not found: %s", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("No ID is set") | ||
} | ||
|
||
config := testAccProvider.Meta().(*Config) | ||
|
||
instanceGroup, err := config.clientCompute.InstanceGroups.Get( | ||
config.Project, rs.Primary.Attributes["zone"], rs.Primary.ID).Do() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if instanceGroup.Network != network { | ||
return fmt.Errorf("network incorrect: actual=%s vs expected=%s", instanceGroup.Network, network) | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testAccComputeInstanceGroup_basic(instance, network string) string { | ||
return fmt.Sprintf(` | ||
resource "google_compute_instance" "ig_instance" { | ||
name = "%s" | ||
|
@@ -245,7 +282,22 @@ func testAccComputeInstanceGroup_basic(instance string) string { | |
name = "https" | ||
port = "8443" | ||
} | ||
}`, instance, instance, instance) | ||
} | ||
|
||
resource "google_compute_instance_group" "empty-with-network" { | ||
description = "Terraform test instance group empty-with-network" | ||
name = "%s-empty-with-network" | ||
network = "%s" | ||
zone = "us-central1-c" | ||
named_port { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: indentation |
||
name = "http" | ||
port = "8080" | ||
} | ||
named_port { | ||
name = "https" | ||
port = "8443" | ||
} | ||
}`, instance, instance, instance, instance, network) | ||
} | ||
|
||
func testAccComputeInstanceGroup_update(instance string) string { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other terraform resources, we have the network parameter be the name of the network and then do a lookup. For consistency, I think we should do that here too. See https://github.com/hashicorp/terraform/blob/master/builtin/providers/google/resource_compute_instance.go#L479 for an example.