[Terraform]Terraform技巧:direnv; Backend, State, Workspace

使用direnv来解决自动AWS Profile导入

  1. 先设置AWS profile
  2. 安装direnv
  3. 在所需目录下新加.envrc文件, 里面放比方:
export AWS_PROFILE=hzhu-nmdev
export TF_VAR_trendmicro_policy_id=3601
  1. 最后别忘了在.gitignore里添加**/.envrc,ignore所有.envrc。双*的作用是"to match directories anywhere in the repository."

References:
direnv
Automatically Switch AWS Profiles When Entering Your Git Repos
.gitignore

使用Backend同步Statefile

Workspaces

Terraform Enterprise: Understanding Workspaces and Modules