From 5055753086c717b0bafdf42ba6097f387c90dc45 Mon Sep 17 00:00:00 2001 From: Dave Arnold Date: Mon, 26 Aug 2024 16:23:31 -0700 Subject: [PATCH] Update build.pkr.hcl to include AWS ECR repository information --- build.pkr.hcl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/build.pkr.hcl b/build.pkr.hcl index d7f57dc..2e80a74 100644 --- a/build.pkr.hcl +++ b/build.pkr.hcl @@ -108,4 +108,18 @@ build { login_server = "${local.aws_account_id}.dkr.ecr.${local.aws_region}.amazonaws.com" } } + + # Post-processor to write the build name to a file and print the AMI ID + post-processor "manifest" { + output = "ami_id.json" + strip_path = true + } + + post-processor "shell-local" { + inline = [ + "cat ami_id.json", + "cat ami_id.json | jq -r '.builds[0].artifact_id' > ami_id.txt", + "aws ssm put-parameter --name '/image-pipeline/${var.project_name}/image_id' --type 'String' --value $(cat ami_id.json | jq -r '.builds[0].artifact_id' | awk -F: '{ print $NF }') --overwrite" + ] + } }