Cloud/Terraform

Terraform - Amazon Machin Image(AMI) 생성

잇(IT) 2022. 7. 9. 21:47

provider "aws" {
  region = "ap-northeast-2"
}

data "aws_instances" "test" {
  filter {
    name = "tag:Name"
    values = ["web-*"]
  }
}

resource "aws_ami_from_instance" "example" {
  for_each           = toset(data.aws_instances.test.ids)
  name               = each.value
  source_instance_id = each.value
  tags = {
    Name = "web-${each.key}"
  }
}

- 위와 같이 AMI가 생성되는 것을 확인 할 수 있다.

728x90