I have a very basic user data script that packer is using, but when I check it looks like packer doesn’t run the .sh script at all.
The user data .sh script as a file is:
echo "User data script started" >>/var/log/user_data.log
and my amazon-ebs source that points to the file:
source "amazon-ebs" "amznlnx2023-rendernode-ami" {
tags = merge(
{ "packer_source" : "amazon-ebs.amznlnx2023-rendernode-ami" },
{ "ami_role" : "firehawk_amznlnx2023_rendernode_ami" },
{ "Name" : "firehawk_amznlnx2023_rendernode_ami" },
local.common_ami_tags
)
ami_description = "An Amazon Linux 2023 AMI that will accept connections from hosts with TLS Certs."
ami_name = "firehawk-rendernode-amznlnx2023-${local.timestamp}-{{uuid}}"
temporary_key_pair_type = "ed25519"
instance_type = "t2.small"
region = var.aws_region
source_ami_filter {
filters = {
"tag:ami_role" : "amznlnx2023_base_ami",
"tag:packer_template" : "firehawk-base-ami",
"tag:commit_hash" : var.ingress_commit_hash,
"tag:commit_hash_short" : var.ingress_commit_hash_short,
"tag:resourcetier" : var.resourcetier,
}
most_recent = true
owners = [var.account_id]
}
ssh_username = "ec2-user"
iam_instance_profile = var.packer_iam_profile_name # provide read and write s3 access for updating and retrieving installers
launch_block_device_mappings {
device_name = "/dev/xvda"
volume_size = 25
volume_type = "gp3"
delete_on_termination = true
}
user_data = file("${path.root}/scripts/amazon_linux_user_data.sh")
}
I also tried:
user_data_file = "${path.root}/scripts/amazon_linux_user_data.sh"
My image then builds and runs other operations (takes about 5 mins to build), and if I check the log output path nothing is there so user data must not be running. Any ideas what I’m missing here? I couldn’t see any examples in the docs so I’m assuming this is the way to use it.