Skip to content

Fix TF_TOKEN_<host> env var lookup for auth - #76

Merged
shwetamurali merged 4 commits into
mainfrom
shweta/match_lowercase
Jul 14, 2026
Merged

Fix TF_TOKEN_<host> env var lookup for auth#76
shwetamurali merged 4 commits into
mainfrom
shweta/match_lowercase

Conversation

@shwetamurali

@shwetamurali shwetamurali commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Description

tfctl documents that it honors Terraform's TF_TOKEN_app_terraform_io env var for auth, but it never actually matched. When building the lookup name, terraformTokenEnvVar uppercased the hostname, so it searched for TF_TOKEN_APP_TERRAFORM_IO instead of the standard lowercase TF_TOKEN_app_terraform_io. Since env var names are case-sensitive, the standard Terraform-style variable was silently ignored.

This aligns the name-building with Terraform CLI's TF_TOKEN_<host> scheme:

  • hostname stays lowercase (as normalized)
  • hyphens encode as double underscores (__)
  • periods encode as single underscores (_)

Testing

  • AddedTestTerraformTokenEnvVar

PR Checklist

  • Run npx changie new or install changie to prepare a new changelog entry for the next set of release notes.
  • Ensure any command changes are sensitive to these global flags:
    • --json — Force machine readable output to stdout. Does not apply to stderr.
    • --markdown — Force markdown output to stdout. Does not apply to stderr.
    • --dry-run — Don't make any actual writes or other mutations. Describe what would have changed to stderr.
    • --quiet — Don't render output to stdout.
  • Get the logging interface from the context and add debug logging for interesting conditions and nonfatal situations.
  • Run make gen/screenshot if the root command output changes.
  • Add the Autocomplete field to positional arguments and flags to assist shell autocomplete.

PCI review checklist

  • I have documented a clear reason for, and description of, the change I am making.

  • If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.

  • If applicable, I've documented the impact of any changes to security controls.

    Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.

@shwetamurali
shwetamurali marked this pull request as ready for review July 9, 2026 20:32

@ctrombley ctrombley left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good! I think I found an edge case, there are more details in the comment.

name: "mixed-case hostname is normalized to lowercase",
hostname: "App.Terraform.IO",
expected: "TF_TOKEN_app_terraform_io",
},

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I noticed that when using a port we can still get mixed-case hostnames. Here's a test case to reproduce:

Suggested change
},
},
{
name: "mixed-case hostname with port is normalized to lowercase",
hostname: "App.Terraform.IO:8443",
expected: "TF_TOKEN_app_terraform_io_8443",
},

expected: "",
},
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you add a test case from NormalizeHostname that uses unicode characters, as documented in this section of the terraform docs? and make sure it works the same way? It allows dashes to be in the env variable OR as a double underscore.

@ctrombley ctrombley left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good, thanks @shwetamurali!

@shwetamurali
shwetamurali merged commit 3ce3de6 into main Jul 14, 2026
2 checks passed
@shwetamurali
shwetamurali deleted the shweta/match_lowercase branch July 14, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants