Add mock_provider support for ephemeral resources - #38928
Open
chpag wants to merge 6 commits into
Open
Conversation
modified: internal/configs/mock_provider_test.go modified: internal/providers/mock.go modified: internal/terraform/context_apply_overrides_test.go modified: internal/terraform/node_resource_apply_instance.go modified: internal/terraform/node_resource_ephemeral.go modified: internal/terraform/node_resource_plan_instance.go
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
Add mock provider support for ephemeral resources, including mock definitions, overrides, and runtime handling.
This allows mocked providers to participate in ephemeral resource workflows instead of failing with “not supported” errors, and lets ephemeral resources honor overrides in both plan and apply flows.
What changed
Add ephemeral resource support to mock provider config decoding (
ìnternal/configs/mock_provider.go):MockDatanow storesMockEphemeralResourcesalongside mocked resources and data sources.decodeMockDataBody()now accepts:mock_ephemeraloverride_ephemeraldecodeMockResourceBlock()now mapsmock_ephemeralblocks toaddrs.EphemeralResourceMode.decodeOverrideEphemeralBlock()to ensureoverride_ephemeraltargets only ephemeral resources.MockData.Merge()now merges ephemeral mock data and reports duplicate ephemeral mock definitions consistently.Implement ephemeral behavior in the mock provider runtime (
ìnternal/provider/mock.go)ValidateEphemeralResourceConfig()now delegates to the wrapped provider rather than returning a hardcoded unsupported error.OpenEphemeralResource()now uses the ephemeral schema and optional mocked defaults fromMockEphemeralResources(internal/configs/mock_provider.go) to produce a result.RenewEphemeralResource()is now a no-op for mocked ephemeral resources.CloseEphemeralResource()]is also a no-op.Support overrides for ephemeral resource execution (
internal/terraform/node_resource/ephemeral.goephemeralResourceInputnow includes anoverrideattribute.NodePlannableResourceInstance.ephemeralResourceExecute()(internal/terraform/node_resource_plan_instance.go)NodeApplyableResourceInstance.ephemeralResourceExecute()(internal/terraform/node_resource_apply_instance.go)ephemeralResourceOpen()now checks for an override before calling the provider, computes the overridden value, marks it ephemeral, and registers it directly.Test coverage
internal/configs/mock_provider_test.goadds merge coverage for mocked ephemeral resources.internal/terraform/context_apply_overrides_test.goadds an ephemeral_override case and extends the test provider schema with an ephemeral resource type.AllowRootEphemeralOutputsand skipping ephemeral outputs from state assertions, since they are not persisted in state.Fixes #38608
Target Release
1.17.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
AI Usage
This PR was developed with assistance from IBM Bob (IBM) as a coding assistant. It help me identify after the first change in
intennal/providers/mock.goandinternal/configs/mock_provider.go, where other change are required, and what code need to be change to have it fully working and testing. Then I review it, and writing this PR