자동화된 이미지 빌더(클라우드 이미지 및 컨테이너 이미지 빌더)
https://learn.hashicorp.com/tutorials/packer/get-started-install-cli?in=packer/aws-get-started
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo yum -y install packer
이미지를 빌드하기 위한 선언과 명령으로 구성된 파일
.pkr.hcl
.pkr.json
mkdir -p packer/aws-ubuntu
cd packer/aws-ubuntu
aws-ubuntu.pkr.hcl
packer {
required_plugins {
amazon = {
version = ">= 0.0.1"
source = "github.com/hashicorp/amazon"
}
}
}
source "amazon-ebs" "ubuntu" {
ami_name = "learn-packer-linux-aws"
instance_type = "t2.micro"
region = "us-west-2"
source_ami_filter {
filters = {
name = "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*"
root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = ["099720109477"]
}
ssh_username = "ubuntu"
}
build {
name = "learn-packer"
sources = [
"source.amazon-ebs.ubuntu"
]
provisioner "shell" {
environment_vars = [
"FOO=hello world",
]
inline = [
"echo Installing Redis",
"sleep 30",
"sudo apt-get update",
"sudo apt-get install -y redis-server",
"echo \"FOO is $FOO\" > example.txt",
]
}
}
packer init .
packer fmt .
packer validate .
packer build .
#DB Subnet
resource "azurerm_subnet" "DBsubnet" {
name = "DBsubnet"
resource_group_name = azurerm_resource_group.rg.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = ["10.0.2.0/24"]
service_endpoints = ["Microsoft.Storage"]
delegation {
name = "fs"
service_delegation {
name = "Microsoft.DBforMySQL/flexibleServers"
actions = [
"Microsoft.Network/virtualNetworks/subnets/join/action",
]
}
}
}
# Private DNS Zone
resource "azurerm_private_dns_zone" "wp" {
name = "wp.mysql.database.azure.com"
resource_group_name = azurerm_resource_group.rg.name
}
resource "azurerm_private_dns_zone_virtual_network_link" "wplink" {
name = "dbVnetZone.com"
private_dns_zone_name = azurerm_private_dns_zone.wp.name
virtual_network_id = azurerm_virtual_network.vnet.id
resource_group_name = azurerm_resource_group.rg.name
}
resource "azurerm_mysql_flexible_server" "flexibleServer" {
name = ""
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
administrator_login = ""
administrator_password = ""
delegated_subnet_id = azurerm_subnet.DBsubnet.id
private_dns_zone_id = azurerm_private_dns_zone.wp.id
sku_name = "GP_Standard_D2ds_v4"
version = "8.0.21"
depends_on = [azurerm_private_dns_zone_virtual_network_link.wplink]
}