본문 바로가기

퍼블릭 클라우드

[Terraform] 테라폼 리소스 태그 지정(tags) -1

반응형

테라폼 리소스 태그 지정(tags)

VPC 모듈

vpc.tf 편집

$ vim vpc.tf
######
# locals
######
locals {
  default_tags = {
  CreateUser = "terraform"
  Owner = "sangchul"
  Project = "blog"
  Service = "network"
  }
}

######
# VPC
######
resource "aws_vpc" "this" {
  cidr_block = var.cidr_block
  enable_dns_hostnames = var.enable_dns_hostnames
  enable_dns_support = var.enable_dns_support
  instance_tenancy = var.instance_tenancy
  lifecycle {
    ignore_changes = [ tags.CreatedDate ]
  }
  tags = merge(
    local.default_tags,
    var.customer_tags
  )
}

VPC 모듈 변수

vars.tf 편집

$ vim vars.tf
...
variable "customer_tags" {
  description = "태그"
  default = ""
}

메인 모듈

main.tf 편집

$ vim main.tf
#####VPC
module "vpc" {
  source = "../../../modules/vpc/"
  aws_region = "us-east-1"
...
  instance_tenancy = "default"
  enable_dns_hostnames = "true"
  enable_dns_support = "true"
...
  azs = ["us-east-1a", "us-east-1c"]

  customer_tags = {
    Name = "va-vpc99",
    Environment = "env-prod",
    Role = "vpc",
    Service = "network",
    CreatedDate = timestamp()
  }
}

 

 

728x90
반응형