PSS: Allow users of Terraform in automation to trust the state storage provider when initialising a state store for the first time#38461
Open
SarahFrench wants to merge 6 commits into
Conversation
5a1efbd to
20196f6
Compare
Base automatically changed from
pss/TF-33680-interactive-confirm-pss-providers
to
main
May 12, 2026 14:42
20196f6 to
fb4ec20
Compare
…nitialisation tests
…alidation that the value ends in the expected file extension and that file exists. Validating that the lock file contains necessary information will have to be later in the init command, as we don't have knowledge of the configuration in the arguments package (rightly!)
…cks as an argument This helps prepare for the change in the next commit, which alters those locks depending on flags.
…tore provider when terraform is run in automation. Raise an error if it was needed but absent
fb4ec20 to
2878910
Compare
3 tasks
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.
Description
Closes https://hashicorp.atlassian.net/browse/TF-36258
This PR follows #38395 and adds equivalent features for when Terraform is run in automation (i.e input is disabled).
Summary: during
initTerraform needs to know that the provider it's going to start using for PSS is trusted, as the provider will be downloaded and used in the same operation. In interactive modes of using Terraform the user will be prompted to approve/reject a provider. In automation a different approach is needed. Then, Terraform will expect to be able to find a dependency lock file describing the new provider (version) that it's about to use. This could be via a dependency lock file that's supplied via a CLI flag and isn't necessarily the file in the working directory.Usage
If Terraform is run in automation using a configuration that's in version control then every
initis a 'first init' that creates the backend state for the first time. If there is a dependency lock file committed in the VCS that describes the provider used for PSS then Terraform will treat the state storage provider as trusted.If PSS is being added to a project for the first time then the provider will not be described in the lock file yet; trust needs to be established on first use. Establishing that trust in an interactive setting means approving a prompt prior to downloading, using, and recording that provider in a lock file.
In an automated setting, we cannot prompt. Instead, we expect a user to supply a separate dependency lock file describing the provider to use for PSS to Terraform. This can be supplied via a new CLI flag, i.e. this lock file can be separate from the project's preexisting .terraform.hcl.lock file. If the lock for the state storage provider is supplied through a separate file then that lock will be added to the project's preexisting .terraform.hcl.lock file after a successful init operation.
NOTE: for systems where practitioners don't commit a dependency lock file to VCS they would need to supply the separate dependency lock file on every init.
Workflow
Just like how setting up a mirror or pre-approved list of providers to use requires some one-off pre-work, showing prior trust in a state store provider requires some (interactive) pre work to create an artefact that's reusable to show that trust has been established.
1. Practitioner initialises a Terraform project with minimal config describing how they'd like to use PSS in other production configurations. This is done manually, so they get an interactive prompt for approval and create a lock file describing the downloaded provider.
Example minimal config - enables checking that configuration is correct and compatible with a specified version of a provider.
Resulting .terraform.lock.hcl file from the manually-run init:
2. Practitioner copies that .terraform.lock.hcl artefact to a location that can be used in their automation environment.
3. Projects being initialised with PSS for the first time (no prior state) in automation are initialised using the command
terraform init -state-provider-lock=<path-to-reused-lock-file>.* That file shows prior trust of that provider version, so the init completes without error.
Target 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