Set Multiline Environment Variables In Elastic Beanstalk With Terraform


Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently.
With the benefits of Continuous Integration/Continuous Deployments, adopting Infrastructure as Code(IaC) bring lots of benefits.
I was stuck for a few hours trying to set a multiline environment variable specifically an RSA private key for an Elastic Beanstalk deployment because the newline character (\n) was either an illegal character or not allowed.
Solution
The solution was to base64 encode the value because the base64 encoded string contains only ASCII characters. The fix required a little change in my code which was to decode the base64 encoded value before use.
To achieve this with terraform was simple. I used the base64encode function to achieve it:
Conclusion
You can adopt this same idea of base64 encoding values for other cloud providers when you have issues setting values with special characters.
