ozbillwang / terraform-best-practices

Terraform Best Practices for AWS users
1.76k stars 357 forks source link

Re: Run terraform command with var-file #6

Closed michaeldeman closed 4 years ago

michaeldeman commented 4 years ago

In the field I have seen mixed opinions about using terraform workspaces. Is there a reason you are not recommending that, and instead using per-environment configuration files?

One nice thing about workspaces, is that all the outputs on per-environment basis are cascaded down to other teams that are consuming resources or other enterprise-wide configurations.

ozbillwang commented 4 years ago

i am not fan of terraform Workspaces. If I am going to use it, i will use terragrunt directly.

If you have any suggestions about workspaces, maybe you can raise PR to improve it.

ozbillwang commented 4 years ago

I remembered, several reasons why I don't use workspaces.

  1. Workspaces are hard to be managed in CICD. I can't find a nice way to make sure a workspace is exist or not without any scriptings.

I have to write an if-else condition to make sure the workspace is exist, otherwise, I need create it.

  1. The real path of workspace in s3 bucket is not clear.

some developers will be confused if they want to review the real tfstate file later.

Seems this is not a problem for me, i will close this issue.

ozbillwang commented 2 months ago

terraform cli support to set workspace and create the Terraform workspace if it doesn't exist with -or-create

terraform workspace select -or-create <workspace_name>

Now, it is useful. I will update the document