This commit is contained in:
havelight-ee
2023-09-04 15:36:46 +09:00
parent 2c9c339281
commit 1711f8cbbb
5 changed files with 81 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
filename="docker-ubuntu.pkr.hcl"
filename="docker-amazon.pkr.hcl"
echo "packer init ${filename}"
echo "packer fmt ${filename}"

View File

@@ -0,0 +1,49 @@
packer {
required_plugins {
amazon = {
version = ">= 0.0.2"
source = "github.com/hashicorp/amazon"
}
}
}
variable "ami_prefix" {
type = string
default = "kubernetes-amazonlinux"
}
locals {
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
}
# source 블록에는 실제 빌드할 이미지에 대한 스펙을 정의
source "amazon-ebs" "kubernetes-amazonlinux" {
ami_name = "${var.ami_prefix}-${local.timestamp}"
instance_type = "t3.small"
region = "ap-northeast-2"
source_ami_filter {
filters = {
image-id = "ami-0eb14fe5735c13eb5"
root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = ["137112412989"]
}
tags = {
source_ami_name = "{{ .SourceAMIName }}"
}
ssh_username = "ec2-user"
}
build {
name = "datasaker-packer"
sources = ["source.amazon-ebs.kubernetes-amazonlinux"]
provisioner "ansible" {
playbook_file = "../ansible/kubernetes_roles.yaml"
user = "ec2-user"
extra_arguments = ["--become"]
ansible_env_vars = ["ANSIBLE_HOST_KEY_CHECKING=False"]
}
}