使用Terraform的Workspace功能构建AWS环境的方法

这是上一次的延续。
这是为了根据环境而分支资源名称的功能。

Usage: terraform workspace

  Create, change and delete Terraform workspaces.

Subcommands:
    delete    Delete a workspace
    list      List Workspaces
    new       Create a new workspace
    select    Select a workspace
    show      Show the name of the current workspace
    開発環境・本番環境の2つを作成します。

请运行 bin/terraform_aws.sh 脚本,并在 dev 环境中创建一个新的工作区。

Created and switched to workspace "dev"!

You're now on a new, empty workspace. Workspaces isolate their state,
so if you run "terraform plan" Terraform will not see any existing state
for this configuration.`

用中国口语将以下内容翻译成中文,只需要一个选项:
$ sh bin/terraform_aws.sh workspace new prod

$ sh bin/terraform_aws.sh 申请新的生产环境工作区

Created and switched to workspace "prod"!

You're now on a new, empty workspace. Workspaces isolate their state,
so if you run "terraform plan" Terraform will not see any existing state
for this configuration.`

    環境の切り替え方法について

执行以下的命令并在dev工作区选择dev。

Switched to workspace "dev".

利用环境变量来切换资源名称。

${terraform.workspace}

以下是本家站点的文档网页链接:
https://www.terraform.io/docs/state/workspaces.html

广告
将在 10 秒后关闭
bannerAds