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" + ] + } }