Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add base64gzip function support to Packer template #13142

Conversation

pwfee
Copy link
Contributor

@pwfee pwfee commented Aug 10, 2024

Why

Packer doesn't support base64zip() which is a useful function to compress user_data or any string in Packer. However terraform indeed supports this function.

As one of the many usecases, AWS has limit the EC2 user_data size on 16KB. It's easier to over this size and we are willing to have this compress function.

Changes

  • Add base64gzip function support in Packer template
  • Add unittest for base64gzip function
  • Add mdx page for base64gzip function

Tests

  1. Build test: Confirmed we can decode base64gzip from the temporary instance user_data
$ aws ec2 describe-instance-attribute --instance-id i-031779e5c7811745e --attribute userData --output text --query "UserData.Value"  --region us-west-2 | base64 -d | gunzip | head
#cloud-config

# see /etc/cloud/cloud.cfg for order of operations for cloud-init

# This cloud_init will run during the image baking process
# Purpose: Install needed software, pull docker images and provision configs

write_files:
- path: /etc/ssh/sshd_config
  owner: root:root
  1. Test base64gzip() in Packer console, confirmed content in base64gzip
> local.user_data
> I2Nsb3VkL....
  1. Unittest

@pwfee pwfee requested a review from a team as a code owner August 10, 2024 02:22
Copy link

hashicorp-cla-app bot commented Aug 10, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

@pwfee pwfee force-pushed the feature/add-base64gzip-function-support branch from e19e954 to 3198acd Compare August 10, 2024 02:26
Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @pwfee,

Thanks for the PR, this LGTM! I left a small nit on a comment, but that's minor, I'll let you address that, and I'll come back for a final pass of review after.

Pre-approving to not block later.

hcl2template/function/encoding.go Outdated Show resolved Hide resolved
@lbajolet-hashicorp
Copy link
Contributor

Thanks for the update @pwfee, merging once tests go green

@lbajolet-hashicorp
Copy link
Contributor

Only test failing is the Vercel deployment, which is irrelevant to this PR, so merging now.

@lbajolet-hashicorp lbajolet-hashicorp merged commit 1b160e5 into hashicorp:main Aug 13, 2024
11 of 12 checks passed
@lbajolet-hashicorp lbajolet-hashicorp added the backport/1.11.x Backport PR changes to `release/1.11.x` label Aug 13, 2024
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/1.11.x Backport PR changes to `release/1.11.x` enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants