Skip to content

TF_CLI_ARGS incorrectly splices workspace commands #21913

@dnitsch

Description

@dnitsch

Terraform Version

Terraform version: 0.12.3  
Go runtime version: go1.12.4

Terraform Configuration Files

not an error with hcl

...

Debug Output

2019/06/26 16:49:09 [INFO] Terraform version: 0.12.3
2019/06/26 16:49:09 [INFO] Go runtime version: go1.12.4
2019/06/26 16:49:09 [INFO] CLI args: []string{"/terraform/versions/terraform-0.12.3", "workspace", "select", "dev-my-workspace"}
2019/06/26 16:49:09 [DEBUG] Attempting to open CLI config file: /Users/dusannitschneider/.terraformrc
2019/06/26 16:49:09 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2019/06/26 16:49:09 [INFO] TF_CLI_ARGS value: "-var-file=../../../config/some_project_variables.tfvars -var=\"stage=dev\" -var=\"some_fqdn=gd-my-workspace.dev.some.domain.org\" -var=\"another_fqdn=am-my-workspace.dev.some.domain.org\""
2019/06/26 16:49:09 [INFO] CLI command args: []string{"workspace", "select", "-var-file=../../../config/some_project_variables.tfvars", "-var=stage=dev", "-var=some_fqdn=gd-my-workspace.dev.some.domain.org", "-var=another_fqdn=am-my-workspace.dev.some.domain.org", "dev-my-workspace"}

Crash Output

Expected Behavior

Switched to workspace "dev-my-workspace".

Actual Behavior

Usage: terraform workspace select NAME [DIR]

Select a different Terraform workspace.

Steps to Reproduce

terraform workspace select dev-my-workspace && terraform apply -auto-approve=true

NB: you can reproduce with any single -arg passed in to export TF_CLI_ARGS="-var="foo=bar"

Additional Context

We mainly use TF only inside automation and would like to upgrade to 12.

Based on this #17094 (comment) - what is the future roadmap for the product or best practice going forward as we use a combination of TF_VAR_name and TF_CLI_ARGS will one of these be deprecated or be given preference over the other.

Off topic (and potentially opinion based), but with regards to the -var-file=... parameter for large estates where many components rely only on a subset of globally declared defaults - can/should these be migrated to TF_VAR_ type instantiation for specific executions or can undeclared variables be used directly inside resources now (as of 12)?

References

There is an open PR, which might go some way to fixing this, though not quite looked into the method

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions