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

Support labels for google cloud resources #17

Closed
hashibot opened this issue Jun 13, 2017 · 22 comments
Closed

Support labels for google cloud resources #17

hashibot opened this issue Jun 13, 2017 · 22 comments

Comments

@hashibot
Copy link

This issue was originally opened by @JorritSalverda as hashicorp/terraform#3546. It was migrated here as part of the provider split. The original body of the issue is below.


According to http://googlecloudplatform.blogspot.nl/2015/10/using-labels-to-organize-Google-Cloud-Platform-resources.html you can now use key/value pairs to label your resources.

It seem to be tags that have key=value format, but if I try that I get the following error, so apparently it's handled differently through the gcloud api.

Reason: invalid, Message: Invalid value for field 'tags.items[0]': 'environment=prod'.  Must be a match of regex '(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?)'

Please add support for this as it will allow us to use this to label our resources for better cost reporting.

@hashibot
Copy link
Author

This comment was originally opened by @JorritSalverda as hashicorp/terraform#3546 (comment). It was migrated here as part of the provider split. The original comment is below.


Judging from the info in the article it's a replacement for tags, but tags that previously existed are shown as value-less keys, which first led me to believe it used the tags system, but it's separately set with

curl --request POST --header "Authorization: Bearer your-oauth-token" --header 'Content-Type: application/json' --data '{"labels": {"env": "canary"}, "labelFingerprint": "abcdefghij="}' https://www.googleapis.com/compute/alpha/projects/your-project-id/zones/your-zone/instances/your-instance/setLabels

@hashibot
Copy link
Author

This comment was originally opened by @lwander as hashicorp/terraform#3546 (comment). It was migrated here as part of the provider split. The original comment is below.


Unfortunately this seems to only be available in the beta API. I'll have to see what might break if we move from v1 to beta.

Have you considered using the metadata instance attribute? It supports key value pairs and is documented here

@hashibot
Copy link
Author

This comment was originally opened by @JorritSalverda as hashicorp/terraform#3546 (comment). It was migrated here as part of the provider split. The original comment is below.


I've tested using metadata for it, but it's not what they use below the covers and doesn't unlock the new features. I can wait for the feature to go out of beta though.

@hashibot
Copy link
Author

This comment was originally opened by @lwander as hashicorp/terraform#3546 (comment). It was migrated here as part of the provider split. The original comment is below.


I'm asking the SetLabel team internally to see if they have an estimate for when it will leave beta.

@hashibot
Copy link
Author

This comment was originally opened by @devth as hashicorp/terraform#3546 (comment). It was migrated here as part of the provider split. The original comment is below.


  1. Any update on when this will reach GA?
  2. Will labels be available on all resource types?

@hashibot
Copy link
Author

This comment was originally opened by @dvianello as hashicorp/terraform#3546 (comment). It was migrated here as part of the provider split. The original comment is below.


Hey!

Any update on this? It would be a brilliant way for us to track costs across different deployments...

@hashibot
Copy link
Author

This comment was originally opened by @zbikmarc as hashicorp/terraform#3546 (comment). It was migrated here as part of the provider split. The original comment is below.


Regarding to official documentation of Google Cloud Platform labels are no more in beta
https://cloud.google.com/compute/docs/labeling-resources (see URL in example)

@hashibot
Copy link
Author

This comment was originally opened by @tpoindessous as hashicorp/terraform#3546 (comment). It was migrated here as part of the provider split. The original comment is below.


Hi

@lwander , can you remove the upstream label please ?

Labels update on resource need to provide right fingerprint. It would be great to have common functions, that we could use in resource and datasource files.

Thanks !

@tpoindessous
Copy link
Contributor

It's now available since #142

But it would be nice to have common functions.

Thanks

@danawillow
Copy link
Contributor

Hey @tpoindessous, I'm not sure what you mean by common functions, but @selmanj is working on adding support for labels, generally.

@tpoindessous
Copy link
Contributor

Hi

I was thinking about helpers functions, which everyone can use instead of rewriting code for using labels.

For example, I'm trying to add a new datasource for snapshot and I added support for searching by labels in my fork

	labels := d.Get("labels").(map[string]interface{})
	log.Printf("[DEBUG] Labels %s", labels)

	if len(labels) > 0 {
		filter := ""
		log.Printf("[DEBUG] Labels length : %d", len(labels))
		for k, v := range labels {
			log.Printf("[DEBUG] Label key : '%s', value : '%s'", k, v)
			filter = fmt.Sprintf("%s(labels.%s eq %s)", filter, k, v)
		}
		log.Printf("[DEBUG] Labels filter : %s", filter)
		snapshotList, err := config.clientCompute.Snapshots.List(project).Filter(filter).Do()
		if err != nil {
			return fmt.Errorf("Snapshot, error while Listing with filter '%s' ", filter)
		}
		log.Printf("[DEBUG] SnapshotList length : %d", len(snapshotList.Items))

		if len(snapshotList.Items) > 1 {
			return fmt.Errorf("Snapshot : too many snapshots found with these tags")
		} else if len(snapshotList.Items) == 0 {
			return fmt.Errorf("Snapshot : no snapshot found with these tags")
		} else {
			d.Set("name", snapshotList.Items[0].Name)
		}
	}

It would be useful to reduce code by using helpers functions.

Thanks for your work and your future work ;)

Thomas

@selmanj
Copy link
Contributor

selmanj commented Jun 22, 2017

@tpoindessous I, too, don't like repeating myself. I'll use a helper function for sure here to reduce duplication. Thanks for the suggestion!

@zbikmarc
Copy link
Contributor

zbikmarc commented Jul 7, 2017

It's awesome that there is labels support for compute_instances! But are there any plans of extending labels support to other resources in near future?

@tpoindessous
Copy link
Contributor

tpoindessous commented Jul 7, 2017 via email

@danawillow danawillow removed their assignment Aug 17, 2017
@selmanj
Copy link
Contributor

selmanj commented Aug 18, 2017

Added label support to google_compute_image in #339

@zbikmarc
Copy link
Contributor

zbikmarc commented Sep 26, 2017

Any plans to add it to google_compute_instance_template in near future?
It looks like it is supported over API at least: https://googlecloudplatform.uservoice.com/forums/302595-compute-engine/suggestions/20145226-allow-settings-labels-in-instance-template

@selmanj
Copy link
Contributor

selmanj commented Sep 26, 2017

@zbikmarc Yes, it's planned. I'll prioritize that resource when I get a chance.

@selmanj
Copy link
Contributor

selmanj commented Oct 5, 2017

Opened #515

@selmanj
Copy link
Contributor

selmanj commented Oct 13, 2017

Closing for now. Labels have been added to:

  • compute_disk
  • compute_gobal_forwarding_rule
  • compute_image
  • compute_instance
  • compute_instance_template
  • compute_snapshot

Feel free to file subsequent issues if you find any other resources that need labels.

@selmanj selmanj closed this as completed Oct 13, 2017
@stefanthorpe
Copy link

stefanthorpe commented Apr 24, 2018

Is it possible to add label support for

  • sql_database_instance

@rosbo
Copy link
Contributor

rosbo commented Apr 24, 2018

Hi,

I filed a separate issue (#1372) to track this. Thanks for reporting.

@ghost
Copy link

ghost commented Nov 18, 2018

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 Nov 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants