LoginSignup
0
0

More than 3 years have passed since last update.

Terraform: 環境ごと(dev, productionなど)の設定値をworkspacesと組み合わせて切り替えられるようにする

Last updated at Posted at 2019-05-25

なぜ

Terraformのworkspacesの機能を使うと、複数環境を切り替えられるようになる。
環境によって切り替えたい設定が場合にどうしたら良いか。

GitHubのissueにいい感じの方法が書いてった。

どうやって

下記のような内容でファイルを作成する。

vars.tf
locals {

  env = {
    defaults = {
      project_name = "project_default"
      region_name = "region-default"
    }

    staging = {
      project_name = "project-staging"
    }

    production = {
      region_name = "region-production"
    }
  }

  config = "${merge(local.env["defaults"], local.env[terraform.workspace])}"
}

使う側は、"${local.config["project_name]}"のようにする。

この例では、workspace名は、"staging"もしくは"production"となっている必要がある。

参考

0
0
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
0