Skip to content

Conversation

@DanielMSchmidt
Copy link
Contributor

Variables can be deprecated through the deprecated attribute. If set the variable will emit a diagnostic if a values is passed to it. This entails both root level and module variables.

Outputs can be deprecated through the deprecated attribute as well. If set wherever the value is used a diagnostic will be emitted. Root level outputs can not be deprecated. The only acceptable usage of a deprecated output is another deprecated output (forwarding the deprecation to the module user).

If modules not under your control have deprecation warnings you can add a suppress_deprecations_warnigns attribute to the module call in question to silence any deeply nested warnings.

For the full end-to-end implementation see #37795, this PR splits up that work into more reviewable chunks.

Fixes #

Target Release

1.15.x

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

@DanielMSchmidt DanielMSchmidt requested a review from a team as a code owner December 11, 2025 12:49
This struct tracks and validates deprecations in the context of a
graph walk. We need a struct to keep track of the module calls that
opt-out of deprecation warnings.
@DanielMSchmidt DanielMSchmidt force-pushed the add-deprecation-surpression-tracking branch from 5402a27 to 008e320 Compare December 11, 2025 12:49
Variables can be deprecated through the `deprecated` attribute. If set the variable
will emit a diagnostic if a values is passed to it. This entails both root level and
module variables.

Outputs can be deprecated through the `deprecated` attribute as well. If set wherever
the value is used a diagnostic will be emitted. Root level outputs can not be deprecated.
The only acceptable usage of a deprecated output is another deprecated output (forwarding
the deprecation to the module user).

If modules not under your control have deprecation warnings you can add a `suppress_deprecations_warnigns`
attribute to the module call in question to silence any deeply nested warnings.
@DanielMSchmidt DanielMSchmidt force-pushed the deprecations-in-variables-and-outputs branch from 82b8b89 to 4c5d964 Compare December 11, 2025 12:49
// cty.Value to a map[string]cty.Value for compatibility with other calls.
func evaluateForEachExpression(expr hcl.Expression, ctx EvalContext, allowUnknown bool) (forEach map[string]cty.Value, known bool, diags tfdiags.Diagnostics) {
return newForEachEvaluator(expr, ctx, allowUnknown).ResourceValue()
func evaluateForEachExpression(expr hcl.Expression, ctx EvalContext, module addrs.Module, allowUnknown bool) (forEach map[string]cty.Value, known bool, diags tfdiags.Diagnostics) {
Copy link
Member

Choose a reason for hiding this comment

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

I think the EvalContext has all the information? ctx.Path() returns the currently evaluated ModuleInstance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Depending on when the evaluation is called ctx.Path() was returning nil sometimes, leading to strange behavior. Passing the module in seemed to give more predictable results, but I could try it again if we don't like the added API surface.

Copy link
Member

Choose a reason for hiding this comment

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

null is a valid value for the root module instance, because RootModuleInstance is just the zero value of ModuleInstance. The Path() method will panic if it's not configured correctly.

If something is returning the wrong path, that is a problem somewhere, but I would more likely suspect it to be a test problem with the mock context.

}

// We don't care about the returned value here, only the diagnostics
module := addrs.RootModule // TODO: FIXME
Copy link
Member

Choose a reason for hiding this comment

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

FIXME? ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should really add a linter for new TODOs and FIXMEs :D

@DanielMSchmidt DanielMSchmidt force-pushed the add-deprecation-surpression-tracking branch 2 times, most recently from 8b295d5 to 2746850 Compare December 12, 2025 13:36
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.

2 participants