Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to generate partial plan, omitting resources that can't be determined until apply #28167

Closed
sgrimm opened this issue Mar 22, 2021 · 2 comments
Labels
enhancement new new issue not yet triaged

Comments

@sgrimm
Copy link

sgrimm commented Mar 22, 2021

Current Terraform Version

v0.13.4

But this also applies to more recent versions.

Use-cases

Given a dependency graph of resources where some of the resources in the middle of the graph have count or for_each parameters, the goal is to be able to create all the specified resources without having to manually inspect error messages and run terraform plan -target. It should be possible for a CI system or other automated process to successfully create all the new resources without human intervention.

Attempted Solutions

It is possible to hack around specific instances of the "value depends on resource attributes that cannot be determined until apply" error using tricks like adding [*] suffixes to string values, but those hacks only work in some cases and often have undesirable side effects such as modifying the types of expressions (changing strings to lists, etc.)

Proposal

Add an option to terraform plan to output a plan to create or modify all the resources that can be unambiguously determined, and omit the ambiguous ones with a warning message. Exit with a unique exit code if there were resources omitted from the plan because they depended on not-yet-created resources.

It will then be possible to write a wrapper that detects the fact that a partial plan has been generated and generates another one after applying the partial one.

Exiting with a nonzero exit code serves two purposes: it's a way for tools to detect partial plans, and it should ensure that existing tools that expect terraform plan to fail if it can't generate a complete plan will not get confused by partial plans even if a user configures them to run terraform plan with the new option.

A possible failure mode will be if there is a configuration error that can only be detected after the partial plan is applied and the resources have been created. However, that's no worse than the current situation where you wouldn't discover such an error until after running terraform plan -target and applying the targeted plan by hand.

References

There have been lots of issues related to this use case, for example #26755 .

@sgrimm sgrimm added enhancement new new issue not yet triaged labels Mar 22, 2021
@jbardin
Copy link
Member

jbardin commented Mar 23, 2021

Hi @sgrimm,

If I understand correctly here, this is one of the possible paths for handing #4149 (aka "Progressive Apply"), which I have referred to in other contexts as "automatic targeting".

I agree this is a useful path to explore, and in concept seems perfectly possible. Having attempting an implementation in the past I can say that it is far more complex than it sounds, but I also did not see any blockers preventing it from being a possibility in the future. Since we are tracking the use case in #4149 already, I'm going to close this out and link the two issues.

Thanks!

@jbardin jbardin closed this as completed Mar 23, 2021
@ghost
Copy link

ghost commented Apr 23, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators Apr 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement new new issue not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants