Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add data source utils_template_file #55

Closed
wants to merge 2 commits into from
Closed

Conversation

nitrocode
Copy link
Member

@nitrocode nitrocode commented Aug 28, 2021

See https://registry.terraform.io/providers/cloudposse/template/latest instead

what

  • Add data source utils_template_file - copied and converted over from the hashicorp/template provider

notes

  • Perhaps the tests should be copied and ported over too ?
  • I could not port the tflang.scope over as it's now an internal function.
    • Without this, none of the terraform functions within the template file would be able to execute.
    • Perhaps it would be better to use MakeTemplateFileFunc which is the same function mapped to templatefile.
    • Looks like tfsec had to copy over all the hashicorp/terraform/internal files in order to reuse the functions.
Example

main.tf

data "utils_template_file" "test" {
  template = file("${path.module}/init.tpl")
  vars = {
    consul_address = "test"
    port           = "8080"
  }
}

output "value" {
  value = data.utils_template_file.test.rendered
}

terraform {
  required_providers {
    utils = {
      source  = "cloudposse/utils"
    }
  }
}

init.tpl

#!/bin/bash

echo "CONSUL_ADDRESS = ${consul_address}" > /tmp/iplist
$ terraform apply
value = <<EOT
#!/bin/bash

echo "CONSUL_ADDRESS = test" > /tmp/iplist

EOT

why

  • templatefile function only works with files created before the init stage
  • existing template provider does not have a darwin arm plugin

references

@nitrocode nitrocode requested review from a team as code owners August 28, 2021 15:52
@nitrocode nitrocode changed the title Add data.utils_template_file Add data source utils_template_file Aug 28, 2021
@nitrocode nitrocode marked this pull request as draft August 28, 2021 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support an updated template_file until string templates are in terraform core
1 participant