Skip to content

Rule for upper-case in labels blocks #413

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

Open
wyardley opened this issue Apr 4, 2025 · 2 comments
Open

Rule for upper-case in labels blocks #413

wyardley opened this issue Apr 4, 2025 · 2 comments

Comments

@wyardley
Copy link

wyardley commented Apr 4, 2025

Labels blocks for most / all services will allow you to define a label like:

resource "google_pubsub_topic" "foo" {
  name = "foo"
  labels = {
    Team = "Foobar"
  }
}

This will plan fine, but then bail on apply with an error like:

Error: Error creating Topic: googleapi: Error 400: You have passed an invalid argument to the service (argument=Invalid labels: Invalid field "labels"; key "Team" does not conform to regular expression "[\p{Ll}\p{Lo}][\p{Ll}\p{Lo}\p{N}_-]{0,62}"; first character "T" is not a non-uppercased letter (Unicode character class Ll or Lo)).

I spot-checked another resource type, and saw the same behavior.

While TPG could also probably do better validation, might be good to have a tflint error for it?

@wata727
Copy link
Member

wata727 commented Apr 16, 2025

This is a good suggestion, but as discussed in hashicorp/terraform-provider-google#22246, it is important to note that the label format is not uniform across all services.
That said, this does seem like a common problem in many cases, so it might be worth introducing your own no-upper-case rule.

@wyardley
Copy link
Author

The comments here seem to imply that there are at least some rules that are supposed to be observed, at least within the two major categories.

Even if the rules have to be limited to subsets of resources that follow the same conventions, seems to me like it could be useful if a) the restrictions don't change often and b) if it's not too burdensome to find the rules for some / most labels.

Either way, tflint could choose to be more opinionated (i.e., having a rule to flag upper case labels, or labels over a certain length, or whatever), even if there were a corner case where Google's APIs would technically allow them)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants