Commit graph

36 commits

Author SHA1 Message Date
Radek Simko
0fe906fa8c make copyrightfix 2026-02-17 13:56:34 +00:00
Kristin Laemmert
869058f995
chore: add default events to the MockProvider's InvokeAction response (#37961)
Some checks are pending
build / Build for windows_amd64 (push) Blocked by required conditions
build / Build for freebsd_arm (push) Blocked by required conditions
build / Build for linux_arm (push) Blocked by required conditions
build / Build for darwin_arm64 (push) Blocked by required conditions
build / Build for linux_arm64 (push) Blocked by required conditions
build / Build for windows_arm64 (push) Blocked by required conditions
build / Build Docker image for linux_386 (push) Blocked by required conditions
build / Build Docker image for linux_amd64 (push) Blocked by required conditions
build / Build Docker image for linux_arm (push) Blocked by required conditions
build / Build Docker image for linux_arm64 (push) Blocked by required conditions
build / Build e2etest for linux_386 (push) Blocked by required conditions
build / Build e2etest for windows_386 (push) Blocked by required conditions
build / Build e2etest for darwin_amd64 (push) Blocked by required conditions
build / Build e2etest for linux_amd64 (push) Blocked by required conditions
build / Build e2etest for windows_amd64 (push) Blocked by required conditions
build / Build e2etest for linux_arm (push) Blocked by required conditions
build / Build e2etest for darwin_arm64 (push) Blocked by required conditions
build / Build e2etest for linux_arm64 (push) Blocked by required conditions
build / Run e2e test for linux_386 (push) Blocked by required conditions
build / Run e2e test for windows_386 (push) Blocked by required conditions
build / Run e2e test for darwin_amd64 (push) Blocked by required conditions
build / Run e2e test for linux_amd64 (push) Blocked by required conditions
build / Run e2e test for windows_amd64 (push) Blocked by required conditions
build / Run e2e test for linux_arm (push) Blocked by required conditions
build / Run e2e test for linux_arm64 (push) Blocked by required conditions
build / Run terraform-exec test for linux amd64 (push) Blocked by required conditions
Quick Checks / Unit Tests (push) Waiting to run
Quick Checks / Race Tests (push) Waiting to run
Quick Checks / End-to-end Tests (push) Waiting to run
Quick Checks / Code Consistency Checks (push) Waiting to run
2025-12-03 08:06:24 -05:00
Sarah French
4420c4dcc0
PSS: Update the workspace new subcommand to work with PSS, add E2E and integration tests for using workspace commands with PSS. (#37855)
* feat: Update the `workspace new` subcommand to work with PSS, add E2E testing

* refactor: Replace instances of `ioutil` with `os` while looking at the workspace command

* docs: Update code comments in `workspace new` command

* test: Update E2E test using PSS with workspace commands to assert state files are created by given commands

* test: Include `workspace show` in happy path E2E test using PSS

* fix: Allow DeleteState RPC to include the id of the state to delete

* test: Include `workspace delete` in happy path E2E test using PSS

* fix: Avoid assignment to nil map in mock provider during WriteStateBytes

* test: Add integration test for workspace commands when using PSS

We still need an E2E test for this, to ensure that the GRPC-related packages pass all the expected data between core and the provider.

* test: Update test to reflect changes in the test fixture configuration

* docs: Fix code comment

* test: Change test to build its own Terraform binary with experiments enabled

* refactor: Replace use of `newMeta` with reuse of Meta that we re-set the UI value on
2025-11-19 12:50:43 +00:00
Sarah French
6b73f710f8
PSS: Implement initialisation of new working directory (or use of -reconfigure flag) while using state_store (#37732)
* Minor fixes in diagnostics

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.

* Rename test to make it specific to use of backend block in config

* Update initBackend to accept whole initArgs collection

* Only process --backend-config data, when setting up a `backend`, if that data isn't empty

* Simplify how mock provider factories are made in tests

* Update mock provider's default logic to track and manage existing workspaces

* Add `ProviderSchema` method to `Pluggable` structs. This allows calling code to access the provider schema when using provider configuration data.

* Add function for converting a providerreqs.Version to a hashicorp/go-version Version.

This is needed for using locks when creating the backend state file.

* Implement initial version of init new working directories using `stateStore_C_s`. Default to creating the default workspace if no workspaces exist.

* Update test fixtures to match the hashicorp/test mock provider used in PSS tests

* Allow tests to obtain locks that include `testingOverrides` providers.

The `testingOverrides` field will only be set in tests, so this should not impact end users.

* Add tests showing TF can initialize a working directory for the first time (and do the same when forced by -reconfigure flag). Remove replaced tests.

* Add -create-default-workspace flag, to be used to disable creating the default workspace by default when -input=false (i.e for use in CI). Refactor creation of default workspace logic. Add tests.

* Allow reattached providers to be used during init for PSS

* Rename variable to `backendHash` so relation to `backend` is clearer

* Allow `(m *Meta) Backend` to return warning diagnostics

* Protect against nil testingOverrides in providerFactoriesFromLocks

* Add test case seeing what happens if default workspace selected, doesn't exist, but other workspaces do exist.

The consequences here are due to using `selectWorkspace` in `stateStore_C_s`, matching what's done in `backend_C_r_s`.

* Address code consistency check failure on PR

* Refactor use of mock in test that's experiencing EOF error...

* Remove test that requires test to supply input for user prompt

This test passes when run in isolation but fails when run alongside other tests, even when skipping all other tests using `testStdinPipe`. I don't think the value of this test is great enough to start changing how we test stdin input.

* Allow -create-default-workspace to be used regardless of whether input is enabled or disabled

* Add TF_SKIP_CREATE_DEFAULT_WORKSPACE environment variable

* Responses to feedback, including making testStdinPipe helper log details of errors copying data to stdin.

Note: We cannot call t.Fatal from a non-test goroutine.

* Use Errorf instead

* Allow backend state files to not include version data when a builtin or reattached provider is in use.

* Add clarifying comment about re-attached providers when finding the matching entry in required_providers

* Report that the default workspace was created to the view

* Refactor: use error comparison via `errors.Is` to identify when no workspaces exist.

* Move handling of TF_ENABLE_PLUGGABLE_STATE_STORAGE into init's ParseInit func.

* Validate that PSS-related flags can only be used when experiments are enabled, enforce coupling of PSS-related flags when in use.

* Slight rewording of output message about default workspace

* Update test to assert new output about default workspace
2025-10-15 10:44:21 +01:00
Sarah French
17445f6c5f
PSS: Add chunk size negotiation to savedStateStore method, update mock provider for tests. (#37726)
* Add SetStateStoreChunkSize to the mock provider for tests

* Implement configurable state chunk size

* Add chunk size negotiation to `savedStateStore`, update happy path test to assert it's set

* Update `savedStateStore` to return diagnostic if a nil factory is passed in, add unhappy path tests

* Fix test error message

* Apply suggestions from code review

Co-authored-by: Radek Simko <radeksimko@users.noreply.github.com>

* Fix rename

---------

Co-authored-by: Radek Simko <radek.simko@gmail.com>
Co-authored-by: Radek Simko <radeksimko@users.noreply.github.com>
2025-10-06 16:03:57 +01:00
Radek Simko
922fdb2382
Implement LockState & UnlockState provider methods (#37711) 2025-10-03 10:02:02 +01:00
Radek Simko
51fc4c161f
PSS: Implement ReadStateBytes + WriteStateBytes (#37440)
* Implement ReadStateBytes + WriteStateBytes

* [WIP] -  Testing ReadStateBytes and WriteStateBytes (#37464)

* Fix nil pointer error

* Add WIP test for ReadStateBytes

* Move test mock to separate testing file

* Update mock to send unexpected EOF when there's a problem returning data and it's not a true EOF

* Add test case for when length != expected length

* Add test for when trying to read state from a store type that doesn't exist

* Change symbol names to lowercase

* Add ability to force a diagnostic to be returned from `mockReadStateBytesClient`'s `Recv` method

* Add test showing error diagnostics raised by the ReadStateBytes client are returned

* Add missing header

* Simplify mock by using an embedded type

* Rename `mockOpts` to `mockReadStateBytesOpts`

* Update existing tests to assert what arguments are passed to the RPC method call

* Add mock WriteStateBytesClient which uses `go.uber.org/mock/gomock` to enable assertions about calls to Send

* Add a test for WriteStateBytes that makes assertions about calls to the Send method

* Update test case to explicitly test writing data smaller than the chunk size

* Implement chunking in WriteStateBytes, add test case to assert expected chunking behaviour

* Add generated mock for Provider_WriteStateBytesClient in protocol v6

* Update tests to use new `MockProvider_WriteStateBytesClient`, remove handwritten mock

* Update code comments in test

* Add tests for diagnostics and errors returned during WriteStateBytes

* Add generated mock for Provider_ReadStateBytesClient in protocol v6, replace old mock

* Add test case for grpc errors in ReadStateBytes, fix how error is returned

* Typo in comment

* Add missing warning test, rename some test cases

* Update proto file definition of Read/WriteStateBytes RPCs (#37529)

* Update Read/WriteStateBytes RPCs to match https://github.com/hashicorp/terraform-plugin-go/pull/531

* Run `make protobuf`

* Run `make generate`

* Update use of `proto.ReadStateBytes_ResponseChunk` in tests

* Fix how diagnostics are handled alongside EOF error, update ReadStateBytes test

* More fixes - test setup was incorrect

I think? I assume that a response would be returned full of zero-values when EOF is encountered.

* WIP - avoid crash if chunk is nil

* Sarah's updates to radek/pss-read-write (#37642)

* Update code to not expect a chunk when EOF encountered

* Return early if any grpc errors are encountered during ReadStateBytes

* Close the stream with CloseSend once everything's read without error. Add test case about handling grpc errors from CloseSend.

* Fix test case about warnings: We would expect to receive a chunk with data alongside the warning and have a normal closing of the stream after EOF

* Add log line, remove unneeded type info

* Implement configurable state chunk size

* handle metadata in WriteStateBytes correctly

* validate chunk sizes received from provider

* ReadStateBytes: avoid early return on warnings

---------

Co-authored-by: Sarah French <15078782+SarahFrench@users.noreply.github.com>
2025-09-26 17:03:02 +01:00
James Bardin
1cb7d1859f
Merge pull request #37515 from hashicorp/jbardin/generate-config
provider GenerateResourceConfig
2025-09-05 16:31:23 -04:00
Kristin Laemmert
00da430883
very minor fixups for test convenience (#37555)
* very minor fixups for test convenience
* cleanup mock provider's actions
2025-09-05 09:59:54 -04:00
James Bardin
97ebb6cf38 GenerateResourceConfig test 2025-08-29 15:11:56 -04:00
James Bardin
cc74e2eb20 udpate provider mocks 2025-08-29 15:00:30 -04:00
Kristin Laemmert
4fadc32a9e
Action Validate Graph (#37514)
* action validation preparation: add NodeAbstractAction

I decided to (loosely) follow the NodeResourceAbstract pattern so that, in the next commit, I can configure the validate walk to create a NodeValidatableAction vs the default nodeExpandActionDeclaration. I am putting this in a separate commit for easier review, to show that this did not impact the current implementation.
2025-08-29 10:01:32 -04:00
Kristin Laemmert
0374f04424
Add ValidateActionConfig to provider interface, protocol & internal implementations (#37345)
* Add ValidateActionConfig to provider interface and protocol

* Update internal/provider-simple-v6/provider.go

Co-authored-by: Daniel Schmidt <danielmschmidt92@gmail.com>

---------

Co-authored-by: Daniel Schmidt <danielmschmidt92@gmail.com>
2025-07-18 14:14:44 -04:00
Daniel Schmidt
ac132d1b15 add provider implementation for actions 2025-07-10 16:06:44 +02:00
Sarah French
39f7920387
PSS: Add packages for presenting a provider as an instance of backend.Backend (#37291)
* Add code to 'wrap' a provider implementation so that it can behave like a backend.Backend

* Add code for creating a state manager that will interact with a provider via grpc to interact with state

* Remove prototyping code

* Update old implementation of PrepareConfig on Pluggable to match new RPC names

* Implement Configure method on Pluggable

* Implement Workspaces and DeleteWorkspace methods on Pluggable

* Prevent construction of a pluggable with missing data, add godoc comment to NewPluggable

* Add godoc comment to ConfigSchema

* Refactor how we create a state manager for interacting with PSS

Now we reuse the remote.State struct and all the pre-existing logic there. We still wrap the provider interface to enable use of gRPC methods, but that's now done using the remote.Client interface.

* Rename file

* Move file into the remote package

* Rename file and package to `pluggable`

* Add test for the only method implemented fully on `grpcClient` : Delete

* Add tests for `NewPluggable`

* Add tests for (Pluggable).ConfigSchema method, make minor fixes

* Change mocks: hardcoded response or logic should return before default logic in method.

* Add tests for (Pluggable).PrepareConfig method

* Add tests for (Pluggable).Configure method

* Add tests for (Pluggable).Workspaces method

* Add tests for (Pluggable).DeleteWorkspace method

* Fix rebase

* Run `make syncdeps`

* Add headers

* Add missing comments

* No need to implement ClientForcePusher

* Apply feedback from review, make small tweaks to test failure messages
2025-07-09 18:22:12 +01:00
Sarah French
0f8e77a50f
PSS: Add GetStates and DeleteState RPCs to plugin protocol v6 (#37288)
* Add GetStates RPC method to Plugin Protocol v6

* Add DeleteState RPC method to Plugin Protocol v6

* Add methods to provider-simple

* Fix error messages

* Apply suggestions from code review

Co-authored-by: Radek Simko <radeksimko@users.noreply.github.com>

* Change how GetStates RPC returns the list of state names

* Change GetStates implementation to use new data type

* `make protobuf` to accommodate new code comments

---------

Co-authored-by: Radek Simko <radeksimko@users.noreply.github.com>
2025-07-07 10:40:45 +01:00
Samsondeen
3d3439e00e
Testing list blocks with the gRPC Provider (#37236) 2025-06-18 11:16:29 +02:00
Samsondeen
f57642d1a6
tf test: parallelize teardown operations (#37220) 2025-06-13 10:12:26 +02:00
Daniel Banck
cb58a15f3d
Implement ListResource RPC (TF-25509) (#37092)
* Implement ListResource RPC via callbacks

* Implement ListResource with iterators

* Change `ListResourceResponse` to slice

* Turn ListResourceResponse into a struct

* Add a limit for ListResource

* explicitly cancel stream when listing resources

---------

Co-authored-by: Samsondeen Dare <samsondeen.dare@hashicorp.com>
2025-06-04 09:40:10 +02:00
Radek Simko
643266dc90
Add initial state store protocol skeleton (#37197)
* Add initial state store protocol skeleton

Introduce ValidateStateStoreConfig + ConfigureStateStore
Update GetProviderSchema + GetMetadata (for mux)

* address PR feedback
2025-06-03 13:52:35 +00:00
Daniel Banck
44ae7da18e
Update Plugin Protocol for List and Implement ValidateListResourceConfig (#37007)
* Minor auto-formatting changes

* Add list RPC and schema protobuf definitions

* make protobuf

* make generate

* Add ValidateListResourceConfig implementation
2025-05-19 10:20:52 +02:00
Radek Simko
6f8b5e49c9
providers/testing: Remove unused *TypeName fields (#36813) 2025-04-01 13:25:46 +00:00
Daniel Schmidt
fec6e4b552 send resource identities to provider calls 2025-03-12 09:18:55 +01:00
Daniel Banck
b2b42c0fb4
Store resource identities in state (TF-23255) (#36464)
* Persist resource identity in Terraform state

* make syncdeps

* Move identity schema merging closer to the protocol

* mock GetResourceIdentitySchemas

* Fix identity refresh tests

* Add more tests

* Change grcpwrap upgrade identity

* Review feedback

* Remove unnecessary version conversion

* Check if GetResourceIdentitySchemas RPC call is implemented

* Update function signature docs

* Adapt protocol changes

* Check unimplemented error for identities in GetSchema
2025-03-11 20:58:44 +01:00
Daniel Banck
10c9b64007
Rename schema.Block to Body (#36629) 2025-03-04 16:33:43 +01:00
Sarah French
e5d4a51ee4
Validate write-only attributes returned from providers during the UpgradeResourceState RPC (#36305)
* Check for non-null WO attrs when a state upgrade takes place

* wip: testing new validation

* update test and let it pass

* Add change file

* fix failing test

* Add comments about some of the gotchas we encountered

* Delete change file

* Remove comment

---------

Co-authored-by: Radek Simko <radek.simko@gmail.com>
2025-01-14 14:02:59 +00:00
Daniel Schmidt
17581e4c48
ephemeral: validate provider responses for write-only attributes 2024-12-12 10:56:40 +01:00
Daniel Schmidt
970ff7f6ec
ephemeral: providers are responsible for setting write-only attributes to null 2024-12-12 10:56:40 +01:00
James Bardin
cca1fd95e5 can't check Close call in mocked ephemeral provider
We can't enforce the check of the close flag in mocked ephemeral
resources, since multiple instances could call the close method while
other instances are running.
2024-10-30 13:58:44 -04:00
James Bardin
0c5fae9e3c ephemeral e2e test provider 2024-09-30 16:20:03 -04:00
James Bardin
94687676a3 add basic grpc wrapper implemenation 2024-09-30 10:51:04 -04:00
James Bardin
9c3dc8f73a ephemeral protocol rename
Add `Resource` to all the ephemeral protocol symbols to make them
consistent with existing naming conventions.
2024-09-20 11:08:53 -04:00
James Bardin
c70a885afb missing ValidateEphemeralResourceConfig from interface 2024-09-19 10:02:45 -04:00
James Bardin
316f48ec10 ephemeral in mock provider 2024-09-13 08:55:48 -04:00
James Bardin
bd45e5b740 mock provider transform can error
Not all paths might be apply-able when transforming this cty.Value in
the provider implementation. The generic PlanResourceChange mock
implementation can get by for now without dealing with complex nested
values. Tests that need something specific will add a
PlanResourceChangeFn.
2024-04-03 10:24:10 -04:00
Liam Cervante
f0b61090a2
Move the testing MockProvider into a dedicated shared package (#34681)
* move the testing MockProvider into a dedicated shared package

* address comments

* fix new changes
2024-02-16 10:35:29 +01:00