Templatefile function errors

I am trying to create a job resource in Rundeck using terraform. Getting below error when trying to template the bash script which has curl command.

Resource block:

resource "rundeck_job" "createjob" {
  #for_each          = toset(var.rule_list)
  for_each          = var.rule_list
  name              = each.key
  group_name        = "Create DropFilters"
  project_name      = rundeck_project.projects.name
  description       = "Creates ${each.key} DropFilter"
  node_filter_query = "name: rundeck"
  option {
    name               = "${var.proj_name}APIKey"
    required           = true
    obscure_input      = true
    exposed_to_scripts = true
    storage_path       = "rundeck"

  }

  command {
    #inline_script = file("${path.module}/${var.proj_name}/createscripts/${each.key}_create.sh")
    inline_script = templatefile("${path.module}/${var.proj_name}/create.tftpl", { 
      nr_accountid = var.nr_accountid
      project = var.proj_name
      })
  }
}

Template file:

#!/bin/bash

curl --no-progress-meter -X POST https://api.newrelic.com/graphql \

-H 'Content-Type: application/json' \

-H 'API-Key: @option.Key@' \

-d '{ "query": "{\n actor {\n account(id: '${nr_accountid}') {\n nrqlDropRules {\n list {\n rules {\n id\n description\n }\n }\n }\n }\n }\n}", "variables":""}'\

| jq -r '.data.actor.account.nrqlDropRules.list.rules[].description' > /dropfilters/${proj_name}/list_of_dropfilters.txt

Error:

Call to function "templatefile" failed: ./Dev/create.tftpl:12,32-33: Invalid character; This character is not used within the language., and 1 other
│ diagnostic(s).

This is resolved. Actually i had a for loop in the bash script which plays with array as below.
for rule in "${dropfilters[@]}" ; do
I had to add ‘$’ in there: for rule in "$${dropfilters[@]}" ; do

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.