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

Validate tag_names for lowercase and other api validation rules #743

Conversation

brandonc
Copy link
Collaborator

Today, we print a warning if you use upcase letters in your tfe_workspace tag_names. Trouble is, you don't see these warnings until after you've already created the offending tag name and only if you have TF_LOG level set to warn.

The API will accept uppercase tag names, but will silently downcase them, which introduces a problem for uppercase config tag names, because from that time on, the case change is detected as drift. This proactive enforcement will protect users from unexpected drift on the next apply:

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # tfe_workspace.deleteme will be created
  + resource "tfe_workspace" "deleteme" {
      + allow_destroy_plan            = true
      + auto_apply                    = false
      + execution_mode                = "remote"
      + file_triggers_enabled         = true
      + force_delete                  = false
      + global_remote_state           = (known after apply)
      + id                            = (known after apply)
      + name                          = "deleteme"
      + operations                    = (known after apply)
      + organization                  = "hashicorp"
      + project_id                    = (known after apply)
      + queue_all_runs                = true
      + remote_state_consumer_ids     = (known after apply)
      + speculative_enabled           = true
      + structured_run_output_enabled = true
      + tag_names                     = [
          + "Hello-World",
        ]
      + terraform_version             = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

tfe_workspace.deleteme: Creating...
tfe_workspace.deleteme: Creation complete after 1s [id=ws-WJipFZUjydzfwvPw]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
~/hashicorp/example-tfe-workspace
$ terraform apply
tfe_workspace.deleteme: Refreshing state... [id=ws-WJipFZUjydzfwvPw]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # tfe_workspace.deleteme will be updated in-place
  ~ resource "tfe_workspace" "deleteme" {
        id                            = "ws-WJipFZUjydzfwvPw"
        name                          = "deleteme"
      ~ tag_names                     = [
          + "Hello-World",
          - "hello-world",
        ]
        # (17 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value:

Closes #529

Description

Describe why you're making this change.

Remember to:

Testing plan

  1. Create workspace config. Try adding invalid tags (containing uppercase characters for instance)
  2. See tests to show examples of invalid tags

Example config:

resource "tfe_workspace" "deleteme" {
  name = "deleteme"
  organization = "hashicorp"
  tag_names = ["Hello"]
}

The API will accept uppercase tag names, but will silently downcase them, which introduces a problem for uppercase config tag names, because from that time on, the case change is detected as drift. This proactive enforcement will protect users from unexpected drift on the next apply.

Closes #529
@brandonc brandonc requested a review from a team as a code owner December 23, 2022 21:35
Copy link
Contributor

@Uk1288 Uk1288 left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉

@brandonc brandonc merged commit fc1257f into main Jan 4, 2023
@brandonc brandonc deleted the TF-3547-uppercase-tag-names-on-tfe-workspace-drift-because-the-api-transforms-them-to-lowercase branch January 4, 2023 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants