How to pass userdata when creating an ec2-instance with the service catalog? #77
-
A customer asked:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Let's first start by understanding how user data is currently configured and passed in the module. In the ec2-instance service catalog module you indicated, the user-data script is specified in the user-data.sh file here (in the root of the same module). You will notice that user-data.sh file is a template that has values expecting to be interpolated later, such as the following: readonly users_for_ip_lockdown=(${ip_lockdown_users})
start_ec2_baseline \
"${enable_cloudwatch_log_aggregation}" \
"${enable_ssh_grunt}" \
"${enable_fail2ban}" \
"${enable_ip_lockdown}" \
"${ssh_grunt_iam_group}" \
"${ssh_grunt_iam_group_sudo}" \
"${log_group_name}" \
"${external_account_ssh_grunt_role_arn}" \
"$${users_for_ip_lockdown[@]}" # Need a double dollar-sign here to avoid Terraform interpolation
volume_json=$(echo ${ebs_volumes} | base64 -d)
for name in $(echo $${volume_json} | jq -r 'keys[]') ; do
mount_point=$(echo $${volume_json} | jq -r ".\"$${name}\".mount_point")
device_name=$(echo $${volume_json} | jq -r ".\"$${name}\".device_name")
owner=$(echo $${volume_json} | jq -r ".\"$${name}\".owner")
id=$(echo ${ebs_volume_data} | base64 -d | jq -r "[.\"$${name}\"][0].id")
mount-ebs-volume \
--aws-region "${ebs_aws_region}" \
--volume-id "$${id}" \
--device-name "$${device_name}" \
--mount-point "$${mount_point}" \
--owner "$${owner}"
done On lines 97 to 114 of the main.tf file in that module, a local variable called With that done, a new local map is created in lines 77 to 81 here which represents the structure expected by the variable cloud_init_parts which is defined here on lines 154 to 162 of variables.tf. As noted in a comment there, this doc explains the use of All that said, here's the official guide to configuring user data within your own terraform / terragrunt config. |
Beta Was this translation helpful? Give feedback.
Let's first start by understanding how user data is currently configured and passed in the module.
In the ec2-instance service catalog module you indicated, the user-data script is specified in the user-data.sh file here (in the root of the same module).
You will notice that user-data.sh file is a template that has values expecting to be interpolated later, such as the following: