Commit graph

4 commits

Author SHA1 Message Date
Sarah French
efb2a1c567
PSS: Let the init command recognise when there are no changes in configuration. (#37777)
* Pull determining of PSS provider's version from current locks into a separate method

* Add code for identifying when config and provider version match existing backend state (i.e. no changes)

* Update test - locks are now needed before it hits expected error diag return

* Add test showing successful init when no config changes are detected.

* Update `getStateStorageProviderVersion` to return nil versions for builtin and re-attached providers.

This makes comparison easier when determining if config has changed since last init.

* Add test coverage for `getStateStorageProviderVersion`

* Move testing fixtures around, preparing for different types of changed state_store config changes being tested

* Add test showing that changing the state_store config is detected as a change, but handling this scenario isn't implemented yet

* Update hashes in test fixture backend state file to be accurate

Previously dummy values were fine, but as tests using hashes to identify changes these values need to be accurate!

* Update existing test cases so that Terraform uses the same test provider version as described in the backend state file fixture for the test.

* Add test showing that changing the PSS provider's config is detected as a change, but handling this scenario isn't implemented yet

* Add test showing that swapping to a different state storage implementation in the same provider is detected as a change, but handling this scenario isn't implemented yet

* Add test showing that changing the provider used for PSS is detected as a change, but handling this scenario isn't implemented yet

* Add test showing that upgrading a provider is detected as a change, but handling this scenario isn't implemented yet

* Update test to use v1.2.3 for consistency with other tests

Just to avoid any confusion if copy-pasting happens in future.

* More corrections to existing test fixtures - unset config should be null, and replace dummy hash values with correct values.

* Fix test for using -reconfigure with state_store; the default workspace would already exist in this scenario

* Update TestInit_stateStore_configUnchanged to assert that init was a no-op for backend state

* Remove unused fixture

* Remove test that's replaced by new tests in command/init_test.go

* Replace old references to deleted "state-store-changed" test fixture & update test to not expect a value for region attr in provider config

* Make test fixture coupling a little more understandable

* Refactor detection of no need to migrate into a function

* Add TODO about more involved provider version change tests

We will allow downgrades to succeed as long as the schema version number is unchanged

* Update (configs.StateStore)Hash method to return a single hash that's impacted by: state store config, provider config, state store type, provider source

* Update calling code and test helper code to reflect that the nested provider block no longer has its own hash

* Remove test; there is now a single hash that SHOULD be affected by the provider block!

* Also use provider name, from config, in hash

* Update tests to reflect changes in how hashes are made

* Remove unused `stateStoreConfigNeedsMigration` function

* Remove duplicate isProviderReattached function.

* Fixes to affected tests

* Allow provider version to impact the state storage hash, update impacted tests and test fixtures

* Update tests that now require locks data to be present in test setup

* Update comment for accuracy

* Fixes to other test fixtures - remove excess hash field, set hash to 0 to indicate they're not set accurately.

* Make upgrade test actually use upgrade code path

* Add lock files to test fixture directories that represent a project that's had a successful prior init using PSS
2025-10-20 16:51:45 +01:00
Sarah French
312f296c2d
PSS: Add savedStateStore method to Meta (#37558)
* Add test coverage for Meta's `savedBackend` method

* Add new Meta `savedStateStore` method and test coverage

* Streamline test - remove unneeded assertions and update comments

* Remove marks from config before configuring the provider

* Remove marks from config before configuring the state store

* Add test case for savedStateStore to assert marks aren't passed

* Fix call to ConfigureStateStore

* Show that tests pass despite not trying to remove marks

* Allow Config methods to add marks when reading pluggable state store config from the backend state file

* This code is now necessary to let the tests pass

* Stop adding marks to PSS-related config when it's parsed from the backend state file

* Stop removing marks that aren't there

* Remove unnecessary test related to marks
2025-10-03 18:47:35 +01:00
Sarah French
61a7914dd9
Add test helper to create mock provider that contains a state store (#37556)
* Add a helper for mocking a provider with a state store

* Update tests to use the new helper

* Update other test fixtures for consistency

The related tests pass before and after this change

* Update testing helper to return the underlying type, not the interface
2025-09-04 10:51:49 +01:00
Sarah French
d1e412fcf0
PSS: Add initial (incomplete) version of code changes to the init command for using pluggable state storage (#37321)
* Store the FQN of the provider used in PSS in representations of the parsed config.

This can only be done once modules have been parsed and the required providers data is available. There are multiple places where config is parsed, into either Config or Module structs, so this needs to be implemented in multiple places.

* Update affected tests, improve error diagnostic

* Begin enabling method to return a backend.Backend made using state_store config.

State store config can now be received via BackendOpts and there is rough validation of whether the config makes sense (does the provider offer a store with the given name?).

* Update code's logic to include possibility of a state store being in use

At this point there are no cases that actually handle the state store scenarios though!

* Add empty cases for handle all broad init scenarios involving PSS

* Update default case's error to report state store variables

* Improve how we resolve the builtin terraform provider's address

* Add test that hits the code path for adding a state store to a new (or implied local) project

* Add test for use of `-reconfigure` flag; show that it hits the code path for adding a state store for the first time

* Add test that hits the code path for removing use of a state store, migrating to (implied) local backend

* Add test that hits the code path for changing a state store's configuration

* Update existing test names to be backend-specific

* Add tests that hits the code path for migrating between PSS and backends

* Consolidate PSS-related tests at end of the file

* Fix log text

* Add test showing that using variables is disallowed with state_store and nested provider blocks

* Update test name

* Fix test cases

* Add TODOs so we remember to remove experiments from tests

* Update state store-related tests to use 	t.Cleanup

* Remove use of `testChdir`
2025-07-18 14:08:18 +01:00