Skip to content

Instantly share code, notes, and snippets.

@Cyclenerd
Last active February 28, 2024 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cyclenerd/fc5c51b25539a735cfb6707948255992 to your computer and use it in GitHub Desktop.
Save Cyclenerd/fc5c51b25539a735cfb6707948255992 to your computer and use it in GitHub Desktop.
Amazon Machine Images (AMI) Snippets
provider "aws" {
region = "eu-central-1"
default_tags {
tags = {
terraform = "true"
}
}
}
# https://registry.terraform.io/providers/-/aws/latest/docs/data-sources/ami
data "aws_ami" "image" {
most_recent = true
filter {
name = "name"
values = ["ubuntu-minimal/images/hvm-ssd/ubuntu-jammy-22.04-*"]
}
filter {
name = "architecture"
values = ["x86_64"]
}
owners = ["099720109477"] # Canonical
}
output "image" {
description = "AMI ID"
value = data.aws_ami.image.id
}
# Copy an AMI (you can copy an AMI from one Region to another)
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/CopyingAMIs.html#ami-copy-steps
# https://docs.aws.amazon.com/cli/latest/reference/ec2/copy-image.html
aws ec2 copy-image \
--source-image-id "ami-03b52b3400f6c6a77" \
--source-region "us-east-1" \
--name "freebsd_13.3_x86_64-nils" \
--region "eu-central-1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment