From 9d3c3d05503a044a84e5da516238164bb9936170 Mon Sep 17 00:00:00 2001 From: Anton Babenko Date: Tue, 19 Nov 2019 11:45:18 +0100 Subject: [PATCH] Added user_data_base64 (fixed #117) --- README.md | 3 ++- examples/basic/main.tf | 11 ++++++++++- main.tf | 7 ++++--- variables.tf | 10 ++++++++-- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c1ccc0d1..d4ce07b9 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,8 @@ data "aws_ami" "ubuntu-xenial" { | tags | A mapping of tags to assign to the resource | map(string) | `{}` | no | | tenancy | The tenancy of the instance (if the instance is running in a VPC). Available values: default, dedicated, host. | string | `"default"` | no | | use\_num\_suffix | Always append numerical suffix to instance name, even if instance_count is 1 | bool | `"false"` | no | -| user\_data | The user data to provide when launching the instance | string | `""` | no | +| user\_data | The user data to provide when launching the instance. Do not pass gzip-compressed data via this argument; see user_data_base64 instead. | string | `"null"` | no | +| user\_data\_base64 | Can be used instead of user_data to pass base64-encoded binary data directly. Use this instead of user_data whenever the value is not a valid UTF-8 string. For example, gzip-encoded user data must be base64-encoded and passed via this argument to avoid corruption. | string | `"null"` | no | | volume\_tags | A mapping of tags to assign to the devices created by the instance at launch time | map(string) | `{}` | no | | vpc\_security\_group\_ids | A list of security group IDs to associate with | list(string) | `"null"` | no | diff --git a/examples/basic/main.tf b/examples/basic/main.tf index 33426b14..2ae888d6 100644 --- a/examples/basic/main.tf +++ b/examples/basic/main.tf @@ -2,6 +2,13 @@ provider "aws" { region = "eu-west-1" } +locals { + user_data = < 0 ? null : element( distinct(compact(concat([var.subnet_id], var.subnet_ids))), count.index, diff --git a/variables.tf b/variables.tf index 81cfc509..3e22361f 100644 --- a/variables.tf +++ b/variables.tf @@ -110,9 +110,15 @@ variable "source_dest_check" { } variable "user_data" { - description = "The user data to provide when launching the instance" + description = "The user data to provide when launching the instance. Do not pass gzip-compressed data via this argument; see user_data_base64 instead." type = string - default = "" + default = null +} + +variable "user_data_base64" { + description = "Can be used instead of user_data to pass base64-encoded binary data directly. Use this instead of user_data whenever the value is not a valid UTF-8 string. For example, gzip-encoded user data must be base64-encoded and passed via this argument to avoid corruption." + type = string + default = null } variable "iam_instance_profile" {