LoginSignup
0
1

More than 5 years have passed since last update.

Terraformを使ってAWS環境を構築するやり方(Workspace機能)

Last updated at Posted at 2018-07-07

前回の続きになります。
環境ごとにリソース名の分岐するための機能です。

コマンド説明
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つを作成します。

$ sh bin/terraform_aws.sh workspace new 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

コマンドログ
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.`

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

$ sh bin/terraform_aws.sh workspace select dev

コマンドログ
Switched to workspace "dev".

環境変数を使って、リソース名を切り替えます。

${terraform.workspace}

本家サイトドキュメント
https://www.terraform.io/docs/state/workspaces.html

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1