FrontPage

概要

  • クラウド環境自動構築システム

雑多

terraform for-in: https://www.hashicorp.com/blog/hashicorp-terraform-0-12-preview-for-and-for-each/

template_file https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/file

data sourceはresourceと似たような振る舞いをしますが、唯一違うのはレシピ上の定義の変更がクラウド上のリソースに変更を及ぼさないことです。data sourceの定義はクラウド上にリソースを作成するのではなく、指定したargumentをもとにクラウド上のリソースの実体の情報を取得して他のresourceと同じように扱います。

data "aws_vpc" "selected" {

 id = "${var.vpc_id}"

} data sourceの定義でargumentに渡すIDは既存のリソースのIDです。data sourceが定義された状態でrefreshコマンドを実行するとstateにその指定されたリソースの情報が反映されます。data sourceの定義に変更を加えた場合には、クラウド上のリソースに変更が加えられるのではなく、そのdata sourceが参照するリソースが指定されたものに入れ替わります。

基本的には、Terraformで管理できない範囲のリソースや意図的に管理から外しているリソースを見かけ上Terraformの管理下にあるように扱うために用います。

variable

varにしか依存指定なしので、varの中にtemplatefile関数を用いて map<systemname, string>を埋め込むといい https://stackoverflow.com/questions/55555963/how-to-create-a-terraform-with-if-else-elsif-statement https://www.terraform.io/docs/configuration/functions/templatefile.html?_ga=2.258495818.1113678221.1595828410-1316403826.1595828410

/* In your variables.tf */ variable "region_mapping" {

 description = "mapping for cross-region replication"
 default = {
   "us-east-1" = "us-east-2",
   "us-west-1" = "us-west-2"
 }

}

/* Then create use lookup to get the replication region from the deployment region */ resource "example" "example" {

 region = "${lookup(var.region_mapping, var.region)}"

}


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2021-06-09 (水) 00:45:55 (1045d)