Issue
Is there a way to bypass the 16KB EC2 user_data limitation without any custom AMI? I have tried below examples in Terraform without any success. instance-user-data.ps1.tmpl is a powershell script of about 20KB.
Below script using base64encode complains about going over 16KB
resource "aws_instance" "instance" {
...
user_data_base64 = "${base64encode(templatefile("${path.module}/instance-user-data.ps1.tmpl", {
admin_username = local.admin_username
admin_password = random_password.admin_password.result
}))}"
}
Tried Gzip with Base64 encode as well, but script does not set any user data at all.
resource "aws_instance" "instance" {
...
user_data_base64 = "${base64gzip(templatefile("${path.module}/instance-user-data.ps1.tmpl", {
admin_username = local.admin_username
admin_password = random_password.admin_password.result
}))}"
}
Solution
The way I would get around this is to push your scripts/files to S3, which can be done with the Terraform aws_s3_object resource, and simply have your user_data script download the real startup script from S3 and run it.
Answered By - Mark B Answer Checked By - Willingham (WPSolving Volunteer)