Open iganari opened 4 years ago
3 つ以上
locals {
vm_settings = [
{
name = "takagi-01"
zone = "asia-northeast1-a"
machine_type = "n1-standard-1"
},
{
name = "takagi-02"
zone = "asia-northeast1-b"
machine_type = "n1-standard-2"
},
{
name = "takagi-03"
zone = "asia-northeast1-c"
machine_type = "n1-standard-4"
},
]
}
resource "google_compute_instance" "takagi_yatu" {
for_each = {for vm in local.vm_settings : vm.name => vm}
name = each.value["name"]
zone = each.value["zone"]
machine_type = each.value["machine_type"]
...(以下省略)...
}
普通の key/value もやる
locals {
adobe_bucket_filter = {
prd = {
"hoge" = "hoge"
"hage" = "hage"
}
stg = {
"fuga" = "fuga"
"debu" = "debu"
}
dev = {
"neko" = "neko"
"inu" = "inu"
}
}
}
resource "google_logging_metric" "adobe_bucket_create_object" {
for_each = local.adobe_bucket_filter[terraform.workspace]
name = each.key
filter = each.value
metric_descriptor {
metric_kind = "DELTA"
value_type = "INT64"
}
}
### GAE の TOP 画面の死活監視
locals {
frontend_check_settings_2 = {
dev = {
display_name = "dev-frontend-healthcheck-2"
project_id = "iganari-dev"
},
stg = {
display_name = "stg-frontend-healthcheck-2"
project_id = "iganari-stg"
},
prd = {
display_name = "prd-frontend-healthcheck-2"
project_id = "iganari-prd"
},
}
}
### GAE の TOP 画面の死活監視
resource "google_monitoring_uptime_check_config" "iganari_gae-frontend_2_dev" {
depends_on = [google_project_service.iganari_monitoring]
for_each = local.frontend_check_settings_2
display_name = each.value.display_name
period = "60s"
timeout = "5s"
selected_regions = [
"ASIA_PACIFIC",
"USA"
]
http_check {
path = "/"
port = "443"
use_ssl = true
validate_ssl = true
}
monitored_resource {
type = "uptime_url"
labels = {
project_id = each.value.project_id
host = "${each.value.project_id}.appspot.com"
}
}
}
locals {
frontend_check_settings_2 = {
dev-frontend-healthcheck-2 = {
project_id = "iganari-dev"
},
stg-frontend-healthcheck-2 = {
project_id = "iganari-stg"
},
prd-frontend-healthcheck-2 = {
project_id = "iganari-prd"
},
}
}
### GAE の TOP 画面の死活監視
resource "google_monitoring_uptime_check_config" "iganari_gae-frontend_2_dev" {
depends_on = [google_project_service.iganari_monitoring]
for_each = local.frontend_check_settings_2
display_name = each.key
period = "60s"
timeout = "5s"
selected_regions = [
"ASIA_PACIFIC",
"USA"
]
http_check {
path = "/"
port = "443"
use_ssl = true
validate_ssl = true
}
monitored_resource {
type = "uptime_url"
labels = {
project_id = each.value.project_id
host = "${each.value.project_id}.appspot.com"
}
}
}
となる
なお、 ① と ② は同じ結果になる
とにかく便利