During the creation of the new TF module, I met the issue with templatefile functionality.
In the triggers.tf I declared the module with an argument which is templated config. The module ./modules/trigger is using provided argument (filename).
During the TF plan I'm receiving:
Error: Unsupported argument
│
│ on triggers.tf line 43, in module "trigger":
│ 43: filename = templatefile("${path.module}/templates/trigger.yaml.tpl", {
│
│ An argument named "filename" is not expected here.
./modules/trigger/main.tf
resource "null_resource" "trigger" {
filename = var.filename
provisioner "local-exec" {
command = <<EOT
gcloud alpha ... --trigger_config ${self.filename} \
EOT
}
}
triggers.tf
locals {
repos = yamldecode(file("${path.module}/repositories/repos.yaml"))
repos = {
for pair in setproduct([local.repos["project"]], local.repos["repos"]) : "${pair[0]}/${pair[1]}" => {
project = pair[0]
repo = pair[1]
}
}
}
module "trigger" {
source = "./modules/trigger"
for_each = local.repos
filename = templatefile("${path.module}/templates/trigger.yaml.tpl", {
trigger_event = "push"
bitbucket_project = each.value["project"]
bitbucket_repo = each.value["repo"]
})
}
/repositories/repos.yaml
project: test
repos:
- cloud-test
/templates/trigger.yaml.tpl
name: "${trigger_event}"
project: "${bitbucket_project}"
repo: "${bitbucket_repo}"
local_fileresource and providing the path to the variablefilename.null_resourcehas thefilenameargument as well.