-
-
Save smaeda-ks/bc087b44fd817226d183f32ef8ebfda8 to your computer and use it in GitHub Desktop.
HCP Packer Registory example Packer templates
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
packer { | |
required_plugins { | |
amazon = { | |
version = ">= 1.0.1" | |
source = "github.com/hashicorp/amazon" | |
} | |
git-commit = { | |
version = ">= 0.3.0" | |
source = "github.com/ethanmdavidson/git" | |
} | |
} | |
} | |
variable "version" { | |
type = string | |
default = "1.0.0" | |
} | |
data "amazon-ami" "ubuntu-focal-west" { | |
region = "us-west-1" | |
filters = { | |
name = "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*" | |
} | |
most_recent = true | |
owners = ["099720109477"] | |
} | |
source "amazon-ebs" "basic-example-west" { | |
region = "us-west-1" | |
source_ami = data.amazon-ami.ubuntu-focal-west.id | |
instance_type = "t2.small" | |
ssh_username = "ubuntu" | |
ssh_agent_auth = false | |
ami_name = "packer_AWS_{{timestamp}}_v${var.version}" | |
} | |
data "git-commit-commit" "cwd-head" { } | |
locals { | |
truncated_sha = substr(data.git-commit-commit.cwd-head.hash, 0, 8) | |
author = data.git-commit-commit.cwd-head.author | |
} | |
build { | |
hcp_packer_registry { | |
bucket_name = "learn-packer-ubuntu" | |
description = <<EOT | |
Some nice description about the image being published to HCP Packer Registry. | |
EOT | |
bucket_labels = { | |
"owner" = "platform-team" | |
"os" = "Ubuntu", | |
"ubuntu-version" = "Focal 20.04", | |
} | |
build_labels = { | |
"build-time" = timestamp() | |
"build-source" = basename(path.cwd) | |
"git-commit-hash" = "${local.truncated_sha}" | |
"git-commit-author" = "${local.author}" | |
} | |
} | |
sources = [ | |
"source.amazon-ebs.basic-example-west" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment