0

I have a shell script to download a http link using wget:

wget -qO - "${mojang_server_url}"

I want to enter this link in a tfvars file, and then reference this in the shell script using Terraform.

I found a good solution here using template_file data source (it works)

data "template_file" "setup_script" {
 template = file("setup.sh")
 vars = {
  mojang_server_url = "${var.mojang_server_url}"
 }
}

However, the official Terraform documentation for template_file tells me I should be using the templatefile function instead?

I can't seem to figure out the syntax for this function, here's what I've got:

templatefile("setup.sh",{"mojang_server_url"="${var.mojang_server_url}")

it highlights templatefile, saying:

Argument or block definition required: An argument or block definition is required here. To set an argument, use the equals sign "=" to introduce the argument value.

Is there a way to make it so this can reference the tfvars variable ina shell script?

thank you!

1 Answer 1

0

You just simply have to provide a map as an input for the second argument:

data "template_file" "setup_script" {
  template = templatefile("setup.sh",
    {
      mojang_server_url = var.mojang_server_url
    }
  )
}
Sign up to request clarification or add additional context in comments.

1 Comment

thank you! I was assuming you had to replace template_file resource with templatefile function but you used them together

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.