Skip to content

Instantly share code, notes, and snippets.

@kosyfrances
Created November 29, 2019 13:10
Show Gist options
  • Save kosyfrances/41d04ad7945da4fce8641ad7013ebfca to your computer and use it in GitHub Desktop.
Save kosyfrances/41d04ad7945da4fce8641ad7013ebfca to your computer and use it in GitHub Desktop.
Render terraform template to local file tested on Terraform v0.12.16
locals {
our_rendered_content = templatefile("${path.module}/yourtemplatefile.tmpl", { yourvars = var.yourvars })
}
resource "null_resource" "local" {
triggers = {
template = local.our_rendered_content
}
# Render to local file on machine
# https://github.com/hashicorp/terraform/issues/8090#issuecomment-291823613
provisioner "local-exec" {
command = format(
"cat <<\"EOF\" > \"%s\"\n%s\nEOF",
var.output_file,
local.our_rendered_content
)
}
}
@petewilcock
Copy link

Good example of this use-case, thanks :)

@karlpokus
Copy link

Thanks! Still works in v1.0.11

@benrifkind
Copy link

🙌 Still works in v1.3.7

@lakinduakash
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment