Tf 34724 terraform stacks cli should be easier to use with non standard hosts tfe#38896
Open
lakshyaa-nathan-15 wants to merge 4 commits into
Conversation
Created ReadCredentialHostsInOrder to return hostnames from credentials.tfrc.json in file order instead of map order. Added focused tests for missing/empty files, single and multiple hosts, ordering guarantees, and invalid-host filtering.
Adds hostname resolution logic for stacks that prefers TF_STACKS_HOSTNAME, then TF_CLOUD_HOSTNAME, then infers from the credentials file when there is exactly one host.
| tfdiags.Warning, | ||
| "No hostname environment variable set, using hostname from credentials file", | ||
| fmt.Sprintf("No hostname environment variable set. Using %q from your credentials file. Set TF_STACKS_HOSTNAME or TF_CLOUD_HOSTNAME to override.", displayHostname), | ||
| )) |
Member
There was a problem hiding this comment.
I actually don't think we need the warning here, only when there are more than 1. I think we can think of a single entry as the happy path 👍
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Improves hostname resolution for the Stacks plugin by automatically inferring the target hostname from the local credentials file (
credentials.tfrc.json) when no explicit hostname environment variable is set.Previously, the
StacksCommandonly checked theTF_STACKS_HOSTNAMEenvironment variable and fell back to the default hostname (app.terraform.io) if it was unset. This meant users running Terraform Enterprise (TFE) instances needed to always remember to set the environment variable explicitly.Changes
The new resolution logic follows this priority order:
TF_STACKS_HOSTNAME- used directly if set.TF_CLOUD_HOSTNAME- used if set andTF_STACKS_HOSTNAMEis notCheck for credentials file override
a. Single entry in credentials.tfrc.json - if exactly one hostname is present in the credentials file, it is used automatically with a warning message
b. Single entry in custom credentials file - if exactly one hostname is present in the credentials file, it is used automatically with a warning message
Multiple entries in credentials file - an error diagnostic is returned because the intended host is ambiguous; the user must set
TF_STACKS_HOSTNAMEorTF_CLOUD_HOSTNAMEto disambiguate.Default hostname - falls back to
app.terraform.iowhen no credentials are present.Additional changes:
ReadCredentialHostsInOrder(and internalreadCredentialHostsInOrderFile) tointernal/command/cliconfig. This function parses the credentials file using a JSON decoder so that the original declaration order of hostnames is preservedTF_STACKS_HOSTNAMEorTF_CLOUD_HOSTNAME.Testing
Added/updated tests covering:
TF_STACKS_HOSTNAMEset explicitlyTF_CLOUD_HOSTNAMEfallbackReadCredentialHostsInOrderpreserving declaration orderTarget Release
1.16.x
Rollback Plan
Changes to Security Controls
Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.
CHANGELOG entry