-
Notifications
You must be signed in to change notification settings - Fork 10.1k
PSS: Swap to gating the experimental feature using configuration, instead of CLI flags #38007
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
base: main
Are you sure you want to change the base?
Conversation
internal/command/init.go
Outdated
| rootMod, _ := c.loadSingleModuleWithTests(path, initArgs.TestsDirectory) | ||
| // We purposefully ignore any diagnostics returned here. They will be encountered downstream, | ||
| // when the 'run' logic below is executed. If we return early due to error diagnostics here we | ||
| // will break the order that errors are expected to be raised in. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a problem with this approach- loading config isn't idempotent.
When you parse HCL files using (p *Parser) ParseHCL from hashicorp/hcl it stores the parsed file in an internal map. Any diagnostics raised from parsing the file the first time are only returned when the file is first parsed. If you re-parse the same file the old parsed data is returned with no associated diagnostics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This problem was apparent through TestInit_invalidSyntaxBackendAttribute failing - the diagnostics we expect in the test get lost between the 1st and 2nd time the config is parsed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah the hclparse package is clear:
// Any diagnostics for parsing a file are only returned once on the first
// call to parse that file. Callers are expected to collect up diagnostics
// and present them together, so returning diagnostics for the same file
// multiple times would create a confusing result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've addressed this in 987e8ab
5f53184 to
987e8ab
Compare
| // TODO(SarahFrench/radeksimko): Once PSS's experiment is over, remove use of arguments and | ||
| // restore parsing of config to always happen here in this code instead of calling code. | ||
| if rootModEarly == nil { | ||
| rootModEarly, earlyConfDiags = c.loadSingleModuleWithTests(path, initArgs.TestsDirectory) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I don't expect a nil rootModEarly to be passed in, unless there's a future refactor that alters the calling code. Mainly I changed the code here in this way to allow the new method arguments to be used but still leave the appropriate position in the method body marked with that TODO comment.
5ce1bd8 to
0865512
Compare
1cb8ea2 to
b6bb055
Compare
…nt `pluggable_state_stores`. This is defined via configuration, instead of the old CLI flag `-enable-pluggable-state-storage-experiment` This commit removes the old `-enable-pluggable-state-storage-experiment` flag and the equivalent `TF_ENABLE_PLUGGABLE_STATE_STORAGE` ENV. All tests are updated to no longer provide that flag or ENV, and instead all the test fixture configurations are updated to include `experiments = [pluggable_state_stores]`
…state_stores` experiment isn't declared in the config.
Prior to this change the strings.Contains assertion was only receiving a string representing the warning, and the error diagnostic was no longer being asserted against.
…tCommand) Run`, instead pass config and diags into downstream code.
…t lists in the terraform block.
b6bb055 to
88c71b7
Compare
Description
Currently the PSS feature is gated by a combination of:
-enable-pluggable-state-storage-experiment=trueto be passed toinitcommands, to choose an experimental version of the commandstate_storeblock.There is also error feedback telling users when either of 1 or 2 are missing.
This PR changes this, so that the experiment is controlled by configuration instead of a CLI flag.
This makes testing the feature easier, as adding the experiment to the configuration occurs once and can be forgotten. Using the CLI flag requires users to remember it is needed each time they run
init, which adds friction and in the past it has been confusing to diagnose errors when the flag is missing.Now users will need configuration like this (plus an experimental build of TF) to use PSS:
Things to note during review
The flag
-enable-pluggable-state-storage-experiment=truewas used in the past because Terraform needed to know if the experimental feature should be used early in the init command before configuration was parsed. Flags are present immediately and allow early logic to decide what to do. With the changes in this PR we now need to parse configuration to learn which experiments are named in the configuration. This happens here, before the fork in the logic between old-init behaviour and new-/experimental-init behaviour:terraform/internal/command/init.go
Lines 59 to 69 in 987e8ab
Note the code comment about why we need to retain the diagnostics returned here, instead of trusting that the same diagnostics will be encountered when files are parsed in downstream logic. We cannot return any errors here because that'll change the return order of different types of errors that are possible in init: "init will error out with an invalid version constraint, even if there are other invalid configuration constructs" (see
TestInit_checkRequiredVersionFirst).When I previously did this:
terraform/internal/command/init.go
Lines 59 to 68 in 812a33d
it resulted in test failures due to the ignored diagnostics being lost completely.
Target Release
1.15.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