Last active
March 25, 2023 05:57
-
-
Save royki/97d8cc51eddf196416f8b8fc9c88d84d to your computer and use it in GitHub Desktop.
Packer template to build aws ami
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package_update: true | |
package_upgrade: true | |
groups: | |
- docker | |
users: | |
- name: ubuntu | |
groups: docker | |
- name: telegraf | |
groups: docker | |
cloud_config_modules: | |
- locale | |
- runcmd | |
packages: | |
- apt-transport-https | |
- ca-certificates | |
- curl | |
- gnupg | |
- gnupg-agent | |
- lsb-release | |
- software-properties-common | |
- unattended-upgrades | |
- curl | |
write_files: | |
- content: | | |
#!/bin/bash | |
# Setup directories and files | |
set -x | |
set -e | |
mkdir -p /home/ubuntu/docker-stack/configs | |
mkdir -p /home/ubuntu/docker-stack/chainspec | |
path: /tmp/create_directories.sh | |
permissions: "0755" | |
- content: | | |
#!/bin/bash | |
set -x | |
set -e | |
# Install docker & docker-compose | |
mkdir -m 0755 -p /etc/apt/keyrings | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg | |
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ | |
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
apt update -y | |
apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y | |
path: /tmp/install_docker.sh | |
permissions: "0755" | |
- content: | | |
#!/bin/sh | |
echo PubkeyAcceptedKeyTypes=+ssh-rsa >> /etc/ssh/sshd_config; | |
service ssh reload | |
path: /tmp/configure_ssh.sh | |
permissions: "0755" | |
runcmd: | |
- [ /bin/update-crypto-policies, --set, LEGACY ] | |
# - sh /tmp/configure_ssh.sh | |
- sh /tmp/create_directories.sh | |
- sh /tmp/install_docker.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "amazon-ebs" "aws-ami" { | |
ami_name = "aws-ami-01" | |
instance_type = "t2.micro" | |
ssh_username = "ubuntu" | |
region = "us-west-1" | |
temporary_key_pair_type = "ed25519" | |
user_data_file = "../scripts/cloud-config.yml" | |
source_ami_filter { | |
filters = { | |
name = "ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*" | |
root-device-type = "ebs" | |
virtualization-type = "hvm" | |
architecture = "x86_64" | |
} | |
most_recent = true | |
owners = ["099720109477"] | |
} | |
ami_block_device_mappings { | |
device_name = "/dev/sda1" | |
volume_size = "60" | |
volume_type = "gp2" | |
} | |
tags = { | |
Env = "prod" | |
Name = "AMI-xxxx" | |
packer = "true" | |
} | |
} | |
# a build block invokes sources and runs provisioning steps on them. | |
build { | |
sources = ["source.amazon-ebs.aws-ami"] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment