Skip to content

Instantly share code, notes, and snippets.

@gulducat
Created June 3, 2020 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gulducat/fb8e9c9035e9ab5b03f58518a277f1d7 to your computer and use it in GitHub Desktop.
Save gulducat/fb8e9c9035e9ab5b03f58518a277f1d7 to your computer and use it in GitHub Desktop.
example usage of Terraform csvdecode()
# very slightly altered from
# https://www.terraform.io/docs/configuration/functions/csvdecode.html#use-with-the-for_each-meta-argument
locals {
csv_data = <<-CSV
local_id,instance_type,ami
foo1,t2.micro,ami-54d2a63b
foo2,t2.micro,ami-54d2a63b
CSV
instances = csvdecode(local.csv_data)
}
resource "null_resource" "nully" {
for_each = { for i in local.instances : i.local_id => i }
triggers = {
my_id = each.value.local_id
}
}
output "nully" {
value = null_resource.nully
}
@gulducat
Copy link
Author

gulducat commented Jun 3, 2020

$ terraform apply
...
null_resource.nully["foo2"]: Creation complete after 0s [id=2423428970411014196]
null_resource.nully["foo1"]: Creation complete after 0s [id=2818486755736522600]

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

Outputs:

nully = {
  "foo1" = {
    "id" = "1232772559400057772"
    "triggers" = {
      "my_id" = "foo1"
    }
  }
  "foo2" = {
    "id" = "8322300694178091254"
    "triggers" = {
      "my_id" = "foo2"
    }
  }
}

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