Created
June 12, 2024 22:19
-
-
Save thomasvincent/cf0f484d745ca17f71999a22e4ba4028 to your computer and use it in GitHub Desktop.
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
variable "aws_access_key" { | |
type = string | |
description = "AWS access key ID" | |
sensitive = true // Mark as sensitive for security | |
} | |
variable "aws_secret_key" { | |
type = string | |
description = "AWS secret access key" | |
sensitive = true // Mark as sensitive for security | |
} | |
variable "aws_region" { | |
type = string | |
description = "AWS region to build in" | |
default = env("AWS_DEFAULT_REGION") | |
} | |
variable "gcloud_project_id" { | |
type = string | |
description = "Google Cloud project ID" | |
default = env("TF_VAR_project_name") // Assuming Terraform integration | |
} | |
variable "gcloud_zone" { | |
type = string | |
description = "Google Cloud zone" | |
default = "europe-west1-b" | |
} | |
# --- Sources --- | |
source "amazon-ebs" "ubuntu" { | |
access_key = var.aws_access_key | |
secret_key = var.aws_secret_key | |
region = var.aws_region | |
source_ami_filter { | |
filters = { | |
"virtualization-type" = "hvm" | |
"name" = "*ubuntu-focal-20.04-amd64-server-*" | |
"root-device-type" = "ebs" | |
} | |
owners = ["099720109477"] | |
most_recent = true | |
} | |
instance_type = "t2.micro" | |
ssh_username = "ubuntu" | |
ami_name = "docker-swarm-${timestamp()}" // Ensure unique name | |
} | |
source "googlecompute" "ubuntu" { | |
project_id = var.gcloud_project_id | |
source_image = "ubuntu-2004-focal-v20230914" // Updated to a more recent image | |
image_name = "docker-swarm-${timestamp()}" // Ensure unique name | |
ssh_username = "ubuntu" | |
zone = var.gcloud_zone | |
} | |
source "virtualbox-iso" "ubuntu" { | |
guest_os_type = "Ubuntu_64" | |
vm_name = "docker-swarm" | |
iso_url = "http://releases.ubuntu.com/20.04/ubuntu-20.04.6-desktop-amd64.iso" // Updated for the latest version of Ubuntu 20.04 LTS | |
iso_checksum = "99999999999999999999999999999999" // You will need to provide the correct sha256 checksum | |
iso_checksum_type = "sha256" // Updated to match the checksum type | |
disk_size = 10000 | |
ssh_username = "vagrant" | |
ssh_password = "vagrant" | |
ssh_wait_timeout = "10000s" | |
http_directory = "packer" | |
headless = true | |
boot_wait = "5s" | |
shutdown_command = "echo 'vagrant' | sudo -S shutdown -P now" | |
boot_command = [ | |
"<enter><wait><f6><esc><bs>...<bs>/install/vmlinuz<wait>", | |
# ... (rest of the boot_command configuration) | |
] | |
} | |
# --- Build --- | |
build { | |
sources = [ | |
"source.amazon-ebs.ubuntu", | |
"source.googlecompute.ubuntu", | |
"source.virtualbox-iso.ubuntu" | |
] | |
provisioner "shell" { | |
inline = [ | |
"sleep 30", | |
"sudo apt-get update", // Update package lists before installing | |
"sudo curl -fsSL https://get.docker.com -o get-docker.sh", // Use the official script | |
"sudo sh get-docker.sh", // Run the official script | |
"sudo usermod -aG docker $(whoami)", | |
"sudo curl -L \"https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-$(uname -s)-$(uname -m)\" -o /usr/local/bin/docker-compose", // Update to the latest Docker Compose version | |
"sudo chmod +x /usr/local/bin/docker-compose", | |
"sudo curl -L git.io/weave -o /usr/local/bin/weave", | |
"sudo chmod +x /usr/local/bin/weave" | |
] | |
} | |
post-processor "vagrant" { | |
only = ["virtualbox-iso.ubuntu"] | |
include = ["docker-compose.yml"] | |
output = "infra/local/docker-swarm.box" | |
} | |
post-processor "shell-local" { | |
only = ["virtualbox-iso.ubuntu"] | |
inline = [ | |
"vagrant box add --force docker-swarm infra/local/docker-swarm.box" | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment