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

Allow use of ${terraform.workspace} in tests #99

Conversation

richardTowers
Copy link
Contributor

I'm working on a plugin which checks that resource names include
${terraform.workspace} (if it's set) -
https://github.com/richardTowers/tflint-ruleset-workspaces/

Currently it's not possible to test this functionality, because (unlike
tflint) tflint-plugin-sdk doesn't support the ${terraform.workspace}
expression.

Fixing #64
would be nicer, but as this is quite self contained I think it's okay to
add this feature to the TestRunner.

I'm working on a plugin which checks that resource names include
`${terraform.workspace}` (if it's set) -
https://github.com/richardTowers/tflint-ruleset-workspaces/

Currently it's not possible to test this functionality, because (unlike
tflint) tflint-plugin-sdk doesn't support the `${terraform.workspace}`
expression.

Fixing terraform-linters#64
would be nicer, but as this is quite self contained I think it's okay to
add this feature to the TestRunner.
richardTowers added a commit to richardTowers/tflint-ruleset-workspaces that referenced this pull request Jan 23, 2021
@@ -187,9 +188,16 @@ func (r *Runner) EvaluateExpr(expr hcl.Expression, ret interface{}, wantTy *cty.
for _, variable := range r.tfconfig.Module.Variables {
variables[variable.Name] = variable.Default
}
workspace, success := os.LookupEnv("TERRAFORM_WORKSPACE")
Copy link
Member

Choose a reason for hiding this comment

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

According to the official behavior, TF_WORKSPACE may be better.
https://www.terraform.io/docs/cli/config/environment-variables.html#tf_workspace

Copy link
Member

@wata727 wata727 left a comment

Choose a reason for hiding this comment

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

Nice 👏

@wata727 wata727 merged commit 530c035 into terraform-linters:master Jan 24, 2021
richardTowers added a commit to richardTowers/tflint-plugin-sdk that referenced this pull request Feb 6, 2021
This is just used in the test runner, but we may as well be consistent
with the variable used in terraform and mainline tflint.

As suggested here: terraform-linters#99 (comment)
As per the docs here: https://www.terraform.io/docs/cli/config/environment-variables.html#tf_workspace
wata727 pushed a commit that referenced this pull request Feb 7, 2021
This is just used in the test runner, but we may as well be consistent
with the variable used in terraform and mainline tflint.

As suggested here: #99 (comment)
As per the docs here: https://www.terraform.io/docs/cli/config/environment-variables.html#tf_workspace
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.

None yet

2 participants