Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraform v0.12.12: When using "for_each", the key can be a string #133

Open
karabijavad opened this issue Nov 8, 2019 · 6 comments
Open

Comments

@karabijavad
Copy link

karabijavad commented Nov 8, 2019

This results in this error:
Error reading tfstate file: 0.12 format error: json: cannot unmarshal string into Go struct field resourceStateTerraform0dot12.index of type int; pre-0.12 format error: <nil> (nil error means no content/modules found in the respective format)

example:

data aws_iam_user staff_users {
  for_each  = var.staff_aws_usernames
  user_name = each.value
}

The above causes "index" to be a string

@sprnza
Copy link

sprnza commented Dec 30, 2019

Is there any way to workaround this?

@karabijavad
Copy link
Author

@sprnza i believe i simply went back to using count = , instead of for_each :(

@gothicfann
Copy link

someone please fix this issue...

@adammck
Copy link
Owner

adammck commented Feb 3, 2020

It looks like #132 is a partial fix. I don't have time to fix this myself, but I'd be happy to review and merge a proper fix. It would helpful if one of you could provide a (redacted) statefile exhibiting the broken behavior.

@gothicfann
Copy link

ERROR:

[WARNING]:  * Failed to parse /home/gothicfan/Lab/vmware/terraform/terraform-
inventory with script plugin: Inventory script
(/home/gothicfan/Lab/vmware/terraform/terraform-inventory) had an execution
error: Error reading tfstate file: 0.12 format error: <nil>; pre-0.12 format
error: <nil> (nil error means no content/modules found in the respective
format)

[WARNING]:  * Failed to parse /home/gothicfan/Lab/vmware/terraform/terraform-
inventory with yaml plugin: 'utf-8' codec can't encode character '\udcc8' in
position 40: surrogates not allowed

[WARNING]:  * Failed to parse /home/gothicfan/Lab/vmware/terraform/terraform-
inventory with ini plugin: /home/gothicfan/Lab/vmware/terraform/terraform-
inventory:1: Error parsing host definition 'ELF>0XE@
�@8@@@@@@��
��@�@dd
@@V�V���O�O�<
�<"bb exWQ�td
�e*

@V�A
�O�x� �
�~�I �V
�� S�V��
]��V��
g��V��j': No closing quotation

[WARNING]: Unable to parse /home/gothicfan/Lab/vmware/terraform/terraform-
inventory as an inventory source

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that
the implicit localhost does not match 'all'

[WARNING]: Could not match supplied host pattern, ignoring: postgresql-master


PLAY [postgresql-master] *******************************************************
skipping: no hosts matched

PLAY RECAP *********************************************************************

EXAMPLE TFSTATE FILE:

{
  "version": 4,
  "terraform_version": "0.12.20",
  "serial": 103,
  "lineage": "003abf14-ae09-2cd5-ae86-76be9977b7b2",
  "outputs": {},
  "resources": [
    {
      "mode": "data",
      "type": "vsphere_compute_cluster",
      "name": "cluster",
      "provider": "provider.vsphere",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "datacenter_id": "datacenter-7",
            "id": "domain-c42",
            "name": "nsx-t",
            "resource_pool_id": "resgroup-43"
          }
        }
      ]
    },
    {
      "mode": "data",
      "type": "vsphere_datacenter",
      "name": "dc",
      "provider": "provider.vsphere",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "id": "datacenter-7",
            "name": "Datacenter"
          }
        }
      ]
    },
    {
      "mode": "data",
      "type": "vsphere_datastore",
      "name": "datastore",
      "provider": "provider.vsphere",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "datacenter_id": "datacenter-7",
            "id": "datastore-29",
            "name": "SSD-Local-H02"
          }
        }
      ]
    },
    {
      "mode": "data",
      "type": "vsphere_network",
      "name": "network",
      "provider": "provider.vsphere",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "datacenter_id": "datacenter-7",
            "id": "network-25",
            "name": "prod",
            "type": "Network"
          }
        }
      ]
    },
    {
      "mode": "data",
      "type": "vsphere_virtual_machine",
      "name": "template",
      "provider": "provider.vsphere",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "alternate_guest_name": "",
            "datacenter_id": "datacenter-7",
            "disks": [
              {
                "eagerly_scrub": false,
                "size": 20,
                "thin_provisioned": false
              }
            ],
            "firmware": "bios",
            "guest_id": "centos7_64Guest",
            "guest_ip_addresses": [],
            "id": "4236179a-4f77-5293-fc1b-974f344f3f30",
            "name": "centos7-template",
            "network_interface_types": [
              "vmxnet3"
            ],
            "scsi_bus_sharing": "noSharing",
            "scsi_controller_scan_count": 1,
            "scsi_type": "pvscsi"
          }
        }
      ]
    },
    {
      "mode": "managed",
      "type": "vsphere_virtual_machine",
      "name": "postgresql-master",
      "provider": "provider.vsphere",
      "instances": [
        {
          "schema_version": 3,
          "attributes": {
            "alternate_guest_name": "",
            "annotation": "",
            "boot_delay": 0,
            "boot_retry_delay": 10000,
            "boot_retry_enabled": false,
            "cdrom": [],
            "change_version": "2020-02-01T21:04:30.650991Z",
            "clone": [
              {
                "customize": [
                  {
                    "dns_server_list": [
                      "10.49.61.11",
                      "10.49.61.12"
                    ],
                    "dns_suffix_list": null,
                    "ipv4_gateway": "10.207.100.1",
                    "ipv6_gateway": "",
                    "linux_options": [
                      {
                        "domain": "ede.local",
                        "host_name": "postgresql-master",
                        "hw_clock_utc": true,
                        "time_zone": ""
                      }
                    ],
                    "network_interface": [
                      {
                        "dns_domain": "",
                        "dns_server_list": null,
                        "ipv4_address": "10.207.100.201",
                        "ipv4_netmask": 24,
                        "ipv6_address": "",
                        "ipv6_netmask": 0
                      }
                    ],
                    "timeout": 10,
                    "windows_options": [],
                    "windows_sysprep_text": ""
                  }
                ],
                "linked_clone": false,
                "template_uuid": "4236179a-4f77-5293-fc1b-974f344f3f30",
                "timeout": 30
              }
            ],
            "cpu_hot_add_enabled": false,
            "cpu_hot_remove_enabled": false,
            "cpu_limit": -1,
            "cpu_performance_counters_enabled": false,
            "cpu_reservation": 0,
            "cpu_share_count": 1000,
            "cpu_share_level": "normal",
            "custom_attributes": null,
            "datastore_cluster_id": null,
            "datastore_id": "datastore-29",
            "default_ip_address": "10.207.100.201",
            "disk": [
              {
                "attach": false,
                "datastore_id": "datastore-29",
                "device_address": "scsi:0:0",
                "disk_mode": "persistent",
                "disk_sharing": "sharingNone",
                "eagerly_scrub": false,
                "io_limit": -1,
                "io_reservation": 0,
                "io_share_count": 1000,
                "io_share_level": "normal",
                "keep_on_remove": false,
                "key": 2000,
                "label": "disk0",
                "name": "",
                "path": "postgresql-master/postgresql-master.vmdk",
                "size": 20,
                "thin_provisioned": false,
                "unit_number": 0,
                "uuid": "6000C29b-89c7-82ff-d32e-5695166e1580",
                "write_through": false
              }
            ],
            "efi_secure_boot_enabled": false,
            "enable_disk_uuid": false,
            "enable_logging": false,
            "ept_rvi_mode": "automatic",
            "extra_config": null,
            "firmware": "bios",
            "folder": "",
            "force_power_off": true,
            "guest_id": "centos7_64Guest",
            "guest_ip_addresses": [
              "10.207.100.201",
              "fe80::250:56ff:feb6:ef73"
            ],
            "host_system_id": "host-28",
            "hv_mode": "hvAuto",
            "id": "4236e5d1-d670-8901-47c2-0dcde2995bc9",
            "ignored_guest_ips": null,
            "imported": null,
            "latency_sensitivity": "normal",
            "memory": 1024,
            "memory_hot_add_enabled": false,
            "memory_limit": -1,
            "memory_reservation": 0,
            "memory_share_count": 10240,
            "memory_share_level": "normal",
            "migrate_wait_timeout": 30,
            "moid": "vm-120",
            "name": "postgresql-master",
            "nested_hv_enabled": false,
            "network_interface": [
              {
                "adapter_type": "vmxnet3",
                "bandwidth_limit": -1,
                "bandwidth_reservation": 0,
                "bandwidth_share_count": 50,
                "bandwidth_share_level": "normal",
                "device_address": "pci:0:7",
                "key": 4000,
                "mac_address": "00:50:56:b6:ef:73",
                "network_id": "network-25",
                "use_static_mac": false
              }
            ],
            "num_cores_per_socket": 1,
            "num_cpus": 1,
            "reboot_required": false,
            "resource_pool_id": "resgroup-43",
            "run_tools_scripts_after_power_on": true,
            "run_tools_scripts_after_resume": true,
            "run_tools_scripts_before_guest_reboot": false,
            "run_tools_scripts_before_guest_shutdown": true,
            "run_tools_scripts_before_guest_standby": true,
            "scsi_bus_sharing": "noSharing",
            "scsi_controller_count": 1,
            "scsi_type": "pvscsi",
            "shutdown_wait_timeout": 3,
            "swap_placement_policy": "inherit",
            "sync_time_with_host": false,
            "tags": null,
            "uuid": "4236e5d1-d670-8901-47c2-0dcde2995bc9",
            "vapp": [],
            "vapp_transport": [],
            "vmware_tools_status": "guestToolsRunning",
            "vmx_path": "postgresql-master/postgresql-master.vmx",
            "wait_for_guest_ip_timeout": 0,
            "wait_for_guest_net_routable": true,
            "wait_for_guest_net_timeout": 5
          },
          "private": "eyJzY2hlbWFfdmVyc2lvbiI6IjMifQ=="
        }
      ]
    },
    {
      "mode": "managed",
      "type": "vsphere_virtual_machine",
      "name": "postgresql-slave",
      "provider": "provider.vsphere",
      "instances": [
        {
          "schema_version": 3,
          "attributes": {
            "alternate_guest_name": "",
            "annotation": "",
            "boot_delay": 0,
            "boot_retry_delay": 10000,
            "boot_retry_enabled": false,
            "cdrom": [],
            "change_version": "2020-02-01T21:09:06.712862Z",
            "clone": [
              {
                "customize": [
                  {
                    "dns_server_list": [
                      "10.49.61.11",
                      "10.49.61.12"
                    ],
                    "dns_suffix_list": null,
                    "ipv4_gateway": "10.207.100.1",
                    "ipv6_gateway": "",
                    "linux_options": [
                      {
                        "domain": "ede.local",
                        "host_name": "postgresql-slave",
                        "hw_clock_utc": true,
                        "time_zone": ""
                      }
                    ],
                    "network_interface": [
                      {
                        "dns_domain": "",
                        "dns_server_list": null,
                        "ipv4_address": "10.207.100.202",
                        "ipv4_netmask": 24,
                        "ipv6_address": "",
                        "ipv6_netmask": 0
                      }
                    ],
                    "timeout": 10,
                    "windows_options": [],
                    "windows_sysprep_text": ""
                  }
                ],
                "linked_clone": false,
                "template_uuid": "4236179a-4f77-5293-fc1b-974f344f3f30",
                "timeout": 30
              }
            ],
            "cpu_hot_add_enabled": false,
            "cpu_hot_remove_enabled": false,
            "cpu_limit": -1,
            "cpu_performance_counters_enabled": false,
            "cpu_reservation": 0,
            "cpu_share_count": 1000,
            "cpu_share_level": "normal",
            "custom_attributes": null,
            "datastore_cluster_id": null,
            "datastore_id": "datastore-29",
            "default_ip_address": "10.207.100.202",
            "disk": [
              {
                "attach": false,
                "datastore_id": "datastore-29",
                "device_address": "scsi:0:0",
                "disk_mode": "persistent",
                "disk_sharing": "sharingNone",
                "eagerly_scrub": false,
                "io_limit": -1,
                "io_reservation": 0,
                "io_share_count": 1000,
                "io_share_level": "normal",
                "keep_on_remove": false,
                "key": 2000,
                "label": "disk0",
                "name": "",
                "path": "postgresql-slave/postgresql-slave.vmdk",
                "size": 20,
                "thin_provisioned": false,
                "unit_number": 0,
                "uuid": "6000C29b-89c7-82ff-d32e-5695166e1580",
                "write_through": false
              }
            ],
            "efi_secure_boot_enabled": false,
            "enable_disk_uuid": false,
            "enable_logging": false,
            "ept_rvi_mode": "automatic",
            "extra_config": null,
            "firmware": "bios",
            "folder": "",
            "force_power_off": true,
            "guest_id": "centos7_64Guest",
            "guest_ip_addresses": [
              "10.207.100.202",
              "fe80::250:56ff:feb6:9343"
            ],
            "host_system_id": "host-28",
            "hv_mode": "hvAuto",
            "id": "42362040-0498-b491-7a56-44f82b66ce3e",
            "ignored_guest_ips": null,
            "imported": null,
            "latency_sensitivity": "normal",
            "memory": 1024,
            "memory_hot_add_enabled": false,
            "memory_limit": -1,
            "memory_reservation": 0,
            "memory_share_count": 10240,
            "memory_share_level": "normal",
            "migrate_wait_timeout": 30,
            "moid": "vm-121",
            "name": "postgresql-slave",
            "nested_hv_enabled": false,
            "network_interface": [
              {
                "adapter_type": "vmxnet3",
                "bandwidth_limit": -1,
                "bandwidth_reservation": 0,
                "bandwidth_share_count": 50,
                "bandwidth_share_level": "normal",
                "device_address": "pci:0:7",
                "key": 4000,
                "mac_address": "00:50:56:b6:93:43",
                "network_id": "network-25",
                "use_static_mac": false
              }
            ],
            "num_cores_per_socket": 1,
            "num_cpus": 1,
            "reboot_required": false,
            "resource_pool_id": "resgroup-43",
            "run_tools_scripts_after_power_on": true,
            "run_tools_scripts_after_resume": true,
            "run_tools_scripts_before_guest_reboot": false,
            "run_tools_scripts_before_guest_shutdown": true,
            "run_tools_scripts_before_guest_standby": true,
            "scsi_bus_sharing": "noSharing",
            "scsi_controller_count": 1,
            "scsi_type": "pvscsi",
            "shutdown_wait_timeout": 3,
            "swap_placement_policy": "inherit",
            "sync_time_with_host": false,
            "tags": null,
            "uuid": "42362040-0498-b491-7a56-44f82b66ce3e",
            "vapp": [],
            "vapp_transport": [],
            "vmware_tools_status": "guestToolsRunning",
            "vmx_path": "postgresql-slave/postgresql-slave.vmx",
            "wait_for_guest_ip_timeout": 0,
            "wait_for_guest_net_routable": true,
            "wait_for_guest_net_timeout": 5
          },
          "private": "eyJzY2hlbWFfdmVyc2lvbiI6IjMifQ==",
          "dependencies": [
            "vsphere_virtual_machine.postgresql-master"
          ]
        }
      ]
    }
  ]
}

atikhono added a commit to atikhono/terraform-inventory that referenced this issue Feb 5, 2020
atikhono added a commit to atikhono/terraform-inventory that referenced this issue Feb 5, 2020
@jonathanvansina
Copy link

jonathanvansina commented Aug 21, 2020

What about Terraform 0.13? I just upgraded (never tester terraform-inventory in 0.12).
I'm using a remote state (AWS S3).

This is my Terraform version:

$ terraform version 
Terraform v0.13.0
+ provider registry.terraform.io/digitalocean/digitalocean v1.22.1

And this is the error:

Error reading Terraform state: 0.12 format error: json: cannot unmarshal string into Go struct field resourceStateTerraform0dot12.index of type int; pre-0.12 format error: <nil> (nil error means no content/modules found in the respective format)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants