Skip to content

Commit

Permalink
terraform: Propagate apply-time variables from plan to apply
Browse files Browse the repository at this point in the history
We need to remember which ephemeral values were set during planning so that
we can require them to be set again (possibly to a different value) during
the apply step.
  • Loading branch information
apparentlymart committed May 10, 2024
1 parent cb5006f commit 23ebf2d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/terraform/context_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,15 @@ func (c *Context) applyGraph(plan *plans.Plan, config *configs.Config, opts *App
SourceType: ValueFromPlan,
}
}
// Apply-time variables need to be merged in too.
// FIXME: We should check that all of these match declared variables and
// that all of them are declared as ephemeral, because all non-ephemeral
// variables are supposed to come exclusively from plan.VariableValues.
if opts != nil {
for n, vv := range opts.SetVariables {
variables[n] = vv
}
}
if diags.HasErrors() {
return nil, walkApply, diags
}
Expand Down
1 change: 1 addition & 0 deletions internal/terraform/context_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ The -target option is not for routine use, and is provided only for exceptional
if len(varMarks) > 0 {
plan.VariableMarks = varMarks
}
plan.ApplyTimeVariables = applyTimeVariables
plan.TargetAddrs = opts.Targets
} else if !diags.HasErrors() {
panic("nil plan but no errors")
Expand Down

0 comments on commit 23ebf2d

Please sign in to comment.