by shigemk2

当面は技術的なことしか書かない

Terraform local変数

何度も宣言できる

locals {
  # Ids for multiple sets of EC2 instances, merged together
  instance_ids = concat(aws_instance.blue.*.id, aws_instance.green.*.id)
}

locals {
  # Common tags to be assigned to all resources
  common_tags = {
    Service = local.service_name
    Owner   = local.owner
  }
}

なお構造体なローカル変数で中身の違う構造体を定義したらエラーになる

locals {
  # Common tags to be assigned to all resources
  common_tags = {
    Service = local.service_name
    Owner   = local.owner
  }
}

locals {
  # Common tags to be assigned to all resources
  common_tags = {
    User = local.user_name
  }
}

developer.hashicorp.com