Skip to content

eBPF-based security platform

packer: Print the final AMI with TPM enabled

Michi Mutsuzaki41120c46ce49
diff --git a/infra/aws/packer/scripts/build-with-temporary-instance-profile.sh b/infra/aws/packer/scripts/build-with-temporary-instance-profile.sh
index b8032334..37539419 100755
--- a/infra/aws/packer/scripts/build-with-temporary-instance-profile.sh
+++ b/infra/aws/packer/scripts/build-with-temporary-instance-profile.sh
@@ -329,4 +329,10 @@ cd "$packer_dir"
packer init .
packer build \
-var "iam_instance_profile=$profile_name" \
- "${packer_args[@]}"
+ "${packer_args[@]}" |
+ awk '
+ /^--> .*: AMIs were created:$/ { skip_artifact=1; next }
+ skip_artifact && NF == 0 { skip_artifact=0; next }
+ skip_artifact { next }
+ { print }
+ '
diff --git a/infra/aws/packer/scripts/register-nitrotpm-ami.sh b/infra/aws/packer/scripts/register-nitrotpm-ami.sh
index 0740b4c7..7bb4081f 100755
--- a/infra/aws/packer/scripts/register-nitrotpm-ami.sh
+++ b/infra/aws/packer/scripts/register-nitrotpm-ami.sh
@@ -38,6 +38,19 @@ image_field() {
--output text
}
+verify_and_print_nitrotpm_ami() {
+ local image_id="$1"
+ local tpm_support
+
+ tpm_support="$(image_field "$image_id" 'Images[0].TpmSupport')"
+ if [[ "$tpm_support" != v2.0 ]]; then
+ echo "Registered AMI ${image_id} has TpmSupport=${tpm_support}, expected v2.0" >&2
+ return 1
+ fi
+
+ printf 'Deployable target AMI for Terraform: %s\n' "$image_id"
+}
+
require_command aws
if [[ ! -r "$PACKER_MANIFEST_PATH" ]]; then
@@ -95,6 +108,7 @@ if [[ -n "$existing_tpm_ami_id" && "$existing_tpm_ami_id" != "None" ]]; then
--resources "$existing_tpm_ami_id" \
--tags "Key=ShirudoRole,Value=${SHIRUDO_IMAGE_ROLE}"
echo "NitroTPM AMI already exists: ${existing_tpm_ami_id} (${tpm_ami_name})"
+ verify_and_print_nitrotpm_ami "$existing_tpm_ami_id"
exit 0
fi
@@ -147,3 +161,4 @@ aws ec2 describe-images \
--image-ids "$tpm_ami_id" \
--query 'Images[0].{ImageId:ImageId,Name:Name,BootMode:BootMode,TpmSupport:TpmSupport}' \
--output table
+verify_and_print_nitrotpm_ami "$tpm_ami_id"