8000 provider GenerateResourceConfig by jbardin · Pull Request #37515 · hashicorp/terraform · GitHub
[go: up one dir, main page]

Skip to content

Conversation

jbardin
Copy link
Member
@jbardin jbardin commented Aug 28, 2025

Core implementation of the GenerateResourceConfig protocol, allowing providers to create the instance configuration value when importing new resources.

Most of the work here is refactoring the config generation code, to finish separating the HCL generation from the config generation, allowing Terraform to ask the provider to create the appropriate values rather than using internal heuristics. This does require another call for each and every resource instance, but because importing with config generation is not a primary workflow, the overall overhead is minimal.

The change adds two pieces to the protocol, a GenerateResourceConfig RPC, and the accompanying flag in ServerCapabilities. While it is a net new call which we can detect the existence of at runtime, because the call needs to be conditional in the core code it is more convenient to know ahead of time what the server capabilities are rather than creating a special error type for the internal interface. Using capabilities also gives the framework authors the more flexibility when implementing this for muxed providers, since they could update the protocol before finishing implementation.

@jbardin jbardin force-pushed the jbardin/generate-config branch from 71acb15 to dbf4fe3 Compare August 29, 2025 19:00
@jbardin jbardin added the no-changelog-needed Add this to your PR if the change does not require a changelog entry label Aug 29, 2025
The Resource struct didn't really match the data structure. Refactor
this to make it easier to break up the config generation calls so we can
pass in final config from the provider.
Now that the refactoring is complete, we can actually call the provider
to generate the config value. The schema fetching and method arguments
are still a mess, but that was the case before too, and we can take time
to clean up the call chain later.
@jbardin jbardin force-pushed the jbardin/generate-config branch from dbf4fe3 to 97ebb6c Compare August 29, 2025 19:12
@jbardin jbardin requested a review from dsa0x August 29, 2025 19:16
@jbardin jbardin marked this pull request as ready for review August 29, 2025 19:16
@jbardin jbardin requested a review from a team as a code owner August 29, 2025 19:16
@jbardin jbardin removed the no-changelog-needed Add this to your PR if the change does not require a changelog entry label Aug 29, 2025
State: state,
}

resp := provider.GenerateResourceConfig(req)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the provider includes values that should not be in config, e.g computed or sensitive attributes? Do we historically do a second validation check of providers' value manipulation, or can we rely on the plugin framework to have validated that?

Copy link
Member Author
@jbardin jbardin Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, that validation just hasn't been written yet ;) We've always tended to double up on these validations, because the framework isn't technically required for providers. The provider developers want it in the framework so that testing can catch problems before actual integration.

@jbardin jbardin merged commit 1cb7d18 into main Sep 5, 2025
7 of 8 checks passed
@jbardin jbardin deleted the jbardin/generate-config branch September 5, 2025 20:31
@cveld
Copy link
cveld commented Sep 25, 2025

@jbardin interesting move! What we would like to see is whenever we run a plan and terraform proposes resources to be created, to run an a cycle to validate whether the resources already exist. This should render a separate imports.tf which then can be amended.

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.

3 participants
0