Skip to content

Add mock_provider support for ephemeral resources - #38928

Open
chpag wants to merge 6 commits into
hashicorp:mainfrom
chpag:feat/mock-provider-ephemeral-resources
Open

Add mock_provider support for ephemeral resources#38928
chpag wants to merge 6 commits into
hashicorp:mainfrom
chpag:feat/mock-provider-ephemeral-resources

Conversation

@chpag

@chpag chpag commented Jul 27, 2026

Copy link
Copy Markdown

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):

  • MockData now stores MockEphemeralResources alongside mocked resources and data sources.
  • decodeMockDataBody() now accepts:
    • mock_ephemeral
    • override_ephemeral
  • decodeMockResourceBlock()now maps mock_ephemeral blocks to addrs.EphemeralResourceMode.
  • Added decodeOverrideEphemeralBlock() to ensure override_ephemeral targets 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 from MockEphemeralResources(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.go

  • ephemeralResourceInput now includes an override attribute.
  • That override is passed from:
    • 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.go adds an ephemeral_override case and extends the test provider schema with an ephemeral resource type.
  • The override tests also account for ephemeral outputs by enabling AllowRootEphemeralOutputs and skipping ephemeral outputs from state assertions, since they are not persisted in state.

Fixes #38608

Target Release

1.17.x

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

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.go and internal/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

chpag and others added 3 commits July 21, 2026 16:50
	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
@chpag
chpag requested a review from a team as a code owner July 27, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test framework: add ephemeral resource support to mock_provider

1 participant