Hello,
I am a new to terraform and struggling with using templatefile to pass a list to my script.yml.
I can pass the list devnames
to a bash script without issues but I cannot figure it out with script.yml. With the belw configuration, when I run terraform plan
, the list just shows as $devnames
and does not unpack the content of the list devnames
.
Can you please assist?
resource "aws_imagebuilder_component" "devmappings" {
name = "devmappings"
platform = "Linux"
data = templatefile("${path.module}/script.yml", {
device_names = join(" ", local.devnames)
})
version = "1.0.0"
}
I need to execute script.yml
against the content of the list devnames
name: 'myName'
description: 'myDescrip'
schemaVersion: 1.0
phases:
- name: build
steps:
- name: Install-prereqs
action: ExecuteBash
inputs:
commands: ["echo $devnames; for i in `seq 0 26`; do; nvme_blkd='/dev/nvme$${i}n1'; if [ -e $nvme_blkd ]; then; mapdevs='$${devnames[i]}'; if [[ -z '$mapdevs' ]]; then; mapdevs='$${devnames[i]}'; fi; if [[ '$mapdevs' != /dev/* ]]; then; mapdevs='/dev/$${mapdevs}'; fi; if [ -e $mapdevs ]; then; echo 'path exists: $${mapdevs}'; else; ln -s $nvme_blkd $mapdevs; echo 'symlink created: $${nvme_blkd} to $${mapdevs}'; fi; fi; done"]