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

don't error on eval of missing instances #35895

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
don't error on eval of missing instances
While in most cases a missing instance during evaluation would be a bug
in terraform, the insertion of postconditions into instance planning has
created a situation where not all instances will be available when
GetResource is called. We do have a special context for evaluating self
alone, but postconditions also need to have the module context available
too.

We may be able to come up with some other way to create an evaluation
context which handles self more selectively, but that looks like a large
change for a situation which should not otherwise happen. If this were
to mask a legitimate error, the fact that an unexpected DyanamicVal were
encountered will raise the problem again, and we can correlate that with
the logged warning.
  • Loading branch information
jbardin committed Oct 23, 2024
commit 987d4f78608f542cb3044a14daa59d41a375b9dd
17 changes: 8 additions & 9 deletions internal/terraform/evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,15 +681,14 @@ func (d *evaluationStateData) GetResource(addr addrs.Resource, rng tfdiags.Sourc
// and need to be replaced by the planned value here.
if is.Current.Status == states.ObjectPlanned {
if change == nil {
// If the object is in planned status then we should not get
// here, since we should have found a pending value in the plan
// above instead.
diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Missing pending object in plan",
Detail: fmt.Sprintf("Instance %s is marked as having a change pending but that change is not recorded in the plan. This is a bug in Terraform; please report it.", instAddr),
Subject: &config.DeclRange,
})
// FIXME: This is usually an unfortunate case where we need to
// lookup an individual instance referenced via "self" for
// postconditions which we know exists, but because evaluation
// must always get the resource in aggregate some instance
// changes may not yet be registered.
instances[key] = cty.DynamicVal
// log the problem for debugging, since it may be a legitimate error we can't catch
log.Printf("[WARN] instance %s is marked as having a change pending but that change is not recorded in the plan", instAddr)
continue
}
instances[key] = change.After
Expand Down