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

provider/google: Changed network argument in google_compute_instance_group as optional #13493

Merged
merged 7 commits into from
Jun 7, 2017

Conversation

tmshn
Copy link
Contributor

@tmshn tmshn commented Apr 9, 2017

If you want to add an instance group to a backend service, the network filed of the instance group must be set.
Formerly this field is set based on the network where instances are in (this is computed by Google API). It means; if you create the empty instance group, the network field will be empty, and you cannot add it to a backend service.

In this PR, I changed network field in google_compute_instance_group from the computed attribute to the configurable optional argument.
Now user can specify network the group is in and add it to a backend service.

Copy link
Contributor

@danawillow danawillow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @tmshn! I have a few small pieces of feedback, but this is nice and simple and should be able to be merged pretty quickly :)

@@ -128,6 +130,10 @@ func resourceComputeInstanceGroupCreate(d *schema.ResourceData, meta interface{}
instanceGroup.NamedPorts = getNamedPorts(v.([]interface{}))
}

if v, ok := d.GetOk("network"); ok {
instanceGroup.Network = v.(string)
Copy link
Contributor

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.

@@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: can you rename this to something like testAccComputeInstanceGroup_networkExists? Check functions (in my opinion) should be more boolean-like in name to make it clear that it's a check and not a config.

name = "%s-empty-with-network"
network = "%s"
zone = "us-central1-c"
named_port {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indentation

@tmshn
Copy link
Contributor Author

tmshn commented May 2, 2017

@danawillow Hey, sorry for the late reaction, but I fixed the points you reviewed! 👍 So could you check again?

Actually the first point, the one about the network parameter to take name rather than URL, will be backward incompatible; users who expect network argument to be URL should change its usage.
Is it OK? I'm happy to do extra work if needed.

@danawillow
Copy link
Contributor

Oh, good point about backwards incompatibility- I think you're right, sorry to lead you down the wrong path.

@tmshn tmshn force-pushed the google_instancegroup_network branch from 18ba343 to 036535d Compare May 5, 2017 06:10
@tmshn tmshn force-pushed the google_instancegroup_network branch from 036535d to 086059f Compare May 5, 2017 06:26
@tmshn
Copy link
Contributor Author

tmshn commented May 5, 2017

@danawillow No problem! I dropped the last commit (and bit modified the next last one).

"GCLOUD_PROJECT",
"CLOUDSDK_CORE_PROJECT",
}
var networkUrl = fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s", multiEnvSearch(projs), networkName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't feel very basic anymore. Mind creating a new test for this? I also think creating the network from within the test would be nicer than relying on the default network and having to read the project from the environment.

@tmshn
Copy link
Contributor Author

tmshn commented May 20, 2017

@danawillow Divided the test for the network 👍

@@ -201,6 +227,44 @@ func testAccComputeInstanceGroup_named_ports(n string, np map[string]int64, inst
}
}

func testAccComputeInstanceGroup_hasCorrectNetwork(n_ig string, n_nw string, instanceGroup *compute.InstanceGroup) resource.TestCheckFunc {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style nit: I'm not a huge fan of mixing types of cases- let's leave everything camelCase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but what does "everything" mean? "Every function names" including the ones I didn't modify? Or just "every letter" of this function name?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I just meant the variables (n_ig, etc.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, yeah, I got it 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 💪 28f0d5e


resource "google_compute_instance_group" "with_instance" {
description = "Terraform test instance group"
name = "%[1]s-with-insntance"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: instance

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry! Fixed -> 4aa065c

@danawillow
Copy link
Contributor

TF_ACC=1 go test ./builtin/providers/google -v -run=TestAccComputeInstanceGroup -timeout 120m
=== RUN   TestAccComputeInstanceGroup_basic
--- PASS: TestAccComputeInstanceGroup_basic (136.93s)
=== RUN   TestAccComputeInstanceGroup_update
--- PASS: TestAccComputeInstanceGroup_update (165.93s)
=== RUN   TestAccComputeInstanceGroup_outOfOrderInstances
--- PASS: TestAccComputeInstanceGroup_outOfOrderInstances (116.40s)
=== RUN   TestAccComputeInstanceGroup_network
--- PASS: TestAccComputeInstanceGroup_network (198.64s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/google	618.011s

@danawillow danawillow merged commit 0b6518a into hashicorp:master Jun 7, 2017
@ghost
Copy link

ghost commented Apr 11, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants