Partial/Progressive Configuration Changes
Problem
For a while now I've been wringing my hands over the issue of using computed resource properties in parts of the Terraform config that are needed during the refresh and apply phases, where the values are likely to not be known yet. The two primary situations that I and others have run into are: - Interpolating into provider configuration blocks, as I described in #2976. This is allowed by Terraform but fails in unintuitive ways when a chicken-and-egg problem arises. - Interpolating into the `count` modifier on resource blocks, as described in #1497. Currently this permits only variables, but having it configurable from resource attributes would be desirable. After a number of false-starts trying to find a way to make this work better in Terraform, I believe I've found a design that builds on concepts already present in Terraform, and that makes only small changes to the Terraform workflow. I arrived at this solution by "paving the cowpaths" after watching my coworkers and I work around the issue in various ways. --- The crux of the proposal is to alter Terraform's workflow to support the idea of _partial application_, allowing Terraform to apply a complicated configuration over several passes and converging on the desired configuration. So from the user's perspective, it would look something like this: [code block] For a particularly-complicated configuration there may be three or more apply/plan cycles, but eventually the configuration should converge. `terraform appl
Error Output
error occured on one of the resource operations: the state is updated to reflect what _was_ applied, and then Terraform exits with a nonzero status.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Implement Partial Application Workflow for Terraform
The issue arises from Terraform's inability to handle computed resource properties during the refresh and apply phases, leading to chicken-and-egg problems when interpolating these values into provider configurations and resource counts. This results in failed apply operations when the necessary values are not yet known.
Awaiting Verification
Be the first to verify this fix
- 1
Define Partial Application Logic
Modify the Terraform core to introduce a partial application mechanism that allows multiple passes of planning and applying configurations. This should include a state management system that can track intermediate states and allow for re-evaluation of resources based on newly available computed properties.
N/AN/A - 2
Update Resource Configuration Handling
Enhance the resource configuration handling to allow for computed attributes to be referenced in provider configurations and resource counts. This involves extending the interpolation logic to support a two-phase evaluation where the first pass gathers necessary computed values.
N/AN/A - 3
Implement State Tracking for Intermediate Values
Create a mechanism within the Terraform state file to store intermediate computed values after each apply phase. This will allow subsequent apply phases to access these values and continue the configuration process without failing due to missing data.
N/AN/A - 4
Test Partial Application Workflow
Develop a suite of tests to validate the new partial application workflow. This should include scenarios with complex dependencies and computed properties to ensure that the workflow converges on the desired state without errors.
N/AN/A - 5
Document Changes and Best Practices
Update Terraform documentation to reflect the new partial application capabilities, providing users with best practices on how to structure their configurations to leverage this new feature effectively.
N/AN/A
Validation
To confirm the fix worked, create a complex Terraform configuration that requires computed properties in provider configurations and resource counts. Execute the 'terraform apply' command and ensure that the configuration converges successfully over multiple passes without errors.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep