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 support for using labels on compute_instance #150

Merged
merged 1 commit into from
Jun 28, 2017

Conversation

selmanj
Copy link
Contributor

@selmanj selmanj commented Jun 21, 2017

Note that the configuration for testAccComputeInstance_update was modified as it was unsetting a value that forced a new instance to be created instead of updated (specifically the metadata_startup_script key).

Part of #17.

@selmanj selmanj requested a review from danawillow June 21, 2017 23:04
@tpoindessous
Copy link
Contributor

Hi

first, I want to thank you for your work. I'm trying to use labels in gcp_compute_snapshot data resource and I will look at your code.

At first sight, it seems that your function func resourceInstanceLabels could be more generic and maybe be useful for other resources.

Is it possible for you, please, to look at this and try to add this function in a more generic file ?

Maybe your other function in _test file could be also used by other people ?

What do you think about this ?

Thank you.

Thomas

if v, ok := d.GetOk("labels"); ok {
labelMap := v.(map[string]interface{})
for k, v := range labelMap {
vstr := 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.

nit: I think it's just as readable to do labels[k] = v.(string)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

whoops, yeah, not sure why there's an extra variable there. Will fix

@@ -795,6 +797,24 @@ func testAccCheckComputeInstanceTag(instance *compute.Instance, n string) resour
}
}

func testAccCheckComputeInstanceLabel(instance *compute.Instance, key string, value string) 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.

Hmm, this checks that a single label exists but doesn't check that there aren't labels we don't expect to be there. Do you think this is sufficient or should it take the key/value map and compare that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could add that but I'm not sure it's something that could happen... Although it might make the test syntax cleaner later down the road.

At some point I think our tests would benefit from building a terraform config up programmatically via a builder or something similar; this would end up making the tests a lot more explicit (currently a lot of information is hidden in the 'config' function). If we had that, then testing the entire map would be a lot easier...

Something like:

	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckComputeInstanceDestroy,
		Steps: []resource.TestStep{
			resource.TestStep{
				Config: NewInstanceBuilder(instanceName).WithLabels(myLabels).Build(),
				Check: resource.ComposeTestCheckFunc(
					testAccCheckComputeInstanceExists(
						"google_compute_instance.foobar", &instance),
					testAccCheckComputeInstanceHasLabels(&instance, myLabels),
				),
			},
		},

@@ -46,6 +46,7 @@ resource "google_compute_instance" "default" {
foo = "bar"
}


Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this extra newline got added

@danawillow
Copy link
Contributor

@tpoindessous I mostly agree with you, although I'm not sure where those functions should live. Honestly I think they should be in core somewhere, since unpacking a map[string]interface{} into a map[string]string (or an []interface{} into a []string, which is another one I've seen around a bunch) is something that would be useful across providers.

As for the test one, that particular function itself can't be used by other tests because it's relying specifically on an instance being passed in, but the idea behind it could probably be generalized, sure. I'm not going to block merging on either of these changes since they could pretty easily be done in a follow-up PR by you or @selmanj, but Joe if you want to do them in this one I'm not going to stop you either.

@tpoindessous
Copy link
Contributor

Hi

yes, I agree with you, features first :)

We could change that later, when we will have several usages of Labels.

Thanks for your work, it will be very useful !

@selmanj selmanj force-pushed the add_labels_to_compute_instance branch from 1f9b0d3 to e3c2706 Compare June 26, 2017 18:08
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.

LGTM, thanks!

@selmanj selmanj merged commit 1137ee7 into hashicorp:master Jun 28, 2017
@selmanj selmanj deleted the add_labels_to_compute_instance branch June 28, 2017 16:44
@rileykarson rileykarson mentioned this pull request Jul 27, 2017
negz pushed a commit to negz/terraform-provider-google that referenced this pull request Oct 17, 2017
…nstance

Add support for using labels on compute_instance
chrisst pushed a commit to chrisst/terraform-provider-google that referenced this pull request Nov 9, 2018
…nstance

Add support for using labels on compute_instance
@ghost
Copy link

ghost commented Mar 31, 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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 31, 2020
flozzone pushed a commit to flozzone/terraform-provider-google that referenced this pull request Oct 17, 2024
flozzone pushed a commit to flozzone/terraform-provider-google that referenced this pull request Oct 17, 2024
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.

4 participants