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

Add local values support #1525

Merged
merged 1 commit into from
Oct 2, 2022
Merged

Add local values support #1525

merged 1 commit into from
Oct 2, 2022

Conversation

wata727
Copy link
Member

@wata727 wata727 commented Sep 23, 2022

Fixes #571

As a result of the #1510 refactoring, it's easier to add support for local values 🎉

Previously, the type of reference in the expression determined whether it could be evaluated or not, so it's hard to support local values that might resolve to unsupportable named values in a step of evaluation. However, unsupported named values are now evaluated to unknown, so static local values are resolved to final values, and unsupported named values are resolved to unknown values.

variable "foo" {
  default = "variable value"
}

locals {
  static   = "static value"
  variable = var.foo
  local    = local.static
  unknown  = aws_instance.main.arn
}

local.static   # => "static value"
local.variable # => "variable value"
local.local    # => "static value"
local.unknown  # => unknown

Note that the internal implementation takes a different approach than Terraform. Terraform references state for resolving local values.
https://github.com/hashicorp/terraform/blob/v1.3.0/internal/terraform/evaluate.go#L334

TFLint cannot refer to the state, so it simply evaluates the local value's expression and recursively get cty.Value. Note that this implementation will fall into an infinite loop if the expression contains circular references. So we need a mechanism to detect circular references from the graph, just like Terraform.

@wata727 wata727 force-pushed the add_support_local_values branch from 7c8bc52 to 21f7fd9 Compare September 24, 2022 10:19
@wata727 wata727 force-pushed the add_support_local_values branch 2 times, most recently from 402886b to 544e997 Compare October 1, 2022 14:10
@wata727 wata727 force-pushed the add_support_local_values branch from 544e997 to 951c40b Compare October 2, 2022 07:39
@wata727 wata727 marked this pull request as ready for review October 2, 2022 07:39
@wata727 wata727 merged commit f3a3cd2 into master Oct 2, 2022
@wata727 wata727 deleted the add_support_local_values branch October 2, 2022 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

TFLint skips expressions that reference static local values
1 participant