title: Iterate over a list of json objects in terraforms 0.12.23
body: <p>I have two arrays of objects in a json file that I'm passing as a tfvar file over the cli command. One is a list of flavors and another is a list of images. What I wanna do is create a VM for each flavor and image, combining them.</p>
  
  <p>Here is an example of the image array:</p>
  
  <pre><code>{
    "image_list" : [
      {
        "ID": "e7d95104-4d15-4087-ab32-4a33f580d664",
        "Name": "CentOS-7-x86_64",
        "Status": "active"
      },
      {
        "ID": "d266a91a-9bfb-4b32-b0de-f9940adc4017",
        "Name": "Debian-8-x86_64",
        "Status": "active"
      },
      {
        "ID": "912967ae-4ee8-4aab-ad6d-b97aeeac3526",
        "Name": "Debian-9-x86_64",
        "Status": "active"
      }
    ]
  }
  </code></pre>
  
  <p>And here is an example of the flavor list:</p>
  
  <pre><code>{
    "flavor_list": [
      {
        "ID": "00000000-0000-000A-0001-000000001024",
        "Name": "T1-1vCPU-1GB-RAM",
        "RAM": 1024,
        "Disk": 50,
        "Ephemeral": 0,
        "VCPUs": 1,
        "Is_Public": true
      },
      {
        "ID": "00000000-0000-000A-0002-000000002048",
        "Name": "T1-2vCPU-2GB-RAM",
        "RAM": 2048,
        "Disk": 50,
        "Ephemeral": 0,
        "VCPUs": 2,
        "Is_Public": true
      },
      {
        "ID": "01829284-4e5e-4bf8-a753-525dc59e8476",
        "Name": "M1-4vCPU-32GB-RAM",
        "RAM": 32768,
        "Disk": 50,
        "Ephemeral": 0,
        "VCPUs": 4,
        "Is_Public": true
      }
    ]
  }
  </code></pre>
  
  <p>I have followed the instructions here <a href="https://www.hashicorp.com/blog/hashicorp-terraform-0-12-preview-for-and-for-each/" rel="nofollow noreferrer">https://www.hashicorp.com/blog/hashicorp-terraform-0-12-preview-for-and-for-each/</a> but it's not working and the error messages are not helping either.</p>
  
  <p>Here is my tf file:</p>
  
  <pre><code># Configure the OpenStack Provider
  provider "openstack" {
  # I have ommited the content here
  }
  
  variable "image_list" {
    type = list(object({
      ID      = string
      Name    = string
      Status  = string
    }))
    default = [
      {
        ID      = "912967ae-4ee8-4aab-ad6d-b97aeeac3526",
        Name    = "Debian-9-x86_64",
        Status  = "active"
      }
    ]
  }
  
  variable "flavor_list" {
    type = list(object({
      ID        = string
      Name      = string
      RAM       = number
      Disk      = number
      Ephemeral = number
      VCPUs     = number
      Is_Public = bool
    }))
  }
  
  # Create a web server
  resource "openstack_compute_instance_v2" "Odin_test_VMs" {
    for_each = var.flavor_list
  
    dynamic "flavor" {
      for_each = var.flavor_list
  
      content {
        name = flavor_list.value.Name
      }
    }
  
    dynamic "image" {
      for_each = var.image_list
  
      content {
        id = image.value.ID
      }
    }
  
    name = "VM_${flavor.value.name}"
    flavor_name = flavor.value.name
    image_id    = image.value.id
  
    network {
      name = "1234362-network"
      uuid = "cb7be82b-e521-4b21-b82c-fb084abe8d3b"
    }
  }
  </code></pre>
  
  <h2>Edit</h2>
  
  <p>Even after the mjpgpy3 suggestions, I'm having the same error messages:</p>
  
  <pre><code>Error: Reference to undeclared resource
  
    on odin_test.tf line 61, in resource "openstack_compute_instance_v2" "Odin_test_VMs":
    61:   name = "VM_${flavor.value.name}"
  
  A managed resource "flavor" "value" has not been declared in the root module.
  
  
  Error: Reference to undeclared resource
  
    on odin_test.tf line 62, in resource "openstack_compute_instance_v2" "Odin_test_VMs":
    62:   flavor_name = flavor.value.name
  
  A managed resource "flavor" "value" has not been declared in the root module.
  
  
  Error: Reference to undeclared resource
  
    on odin_test.tf line 63, in resource "openstack_compute_instance_v2" "Odin_test_VMs":
    63:   image_id    = image.value.id
  
  A managed resource "image" "value" has not been declared in the root module.
  </code></pre>