using count.index in terraform?

前端 未结 1 1745
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-06 03:24

I am trying to generate a bunch of files from templates - I need to replace the hardcoded 1 with the count.index , not sure what format terraform will allow we to use.



        
相关标签:
1条回答
  • 2021-02-06 03:53

    You can iterate through the tenant_repo_multi data source like so -

    resource "local_file" "foo" {
      count    = "${length(var.files)}"
      content  = "${element(data.template_file.tenant_repo_multi.*.rendered, count.index)}"
      filename = "${element(var.files, count.index)}"
    }
    

    However, have you considered using the template_dir resource in the Terraform Template provider. An example below -

    resource "template_dir" "config" {
        source_dir      = "./unrendered"
        destination_dir = "./rendered"
    
        vars = {
            message = "world"
        }
    }
    
    0 讨论(0)
提交回复
热议问题