Skip to content

OutputMapOfObjects throws "Type switching to map[string]interface{} failed." when output objects contain values of type list #1023

@sbgillett

Description

@sbgillett

I have a test which grabs a Terraform output which is a list of objects (Azure public IP addresses).

output "public_ip_addresses" {
  value = azurerm_public_ip.all
}

The referenced resource azurerm_public_ip.all contains the for_each argument, so the output is a list of objects. So terraform output -json public_ip_addresses would give something like

{
  "pip1": {
    "allocation_method": "Static",
    "availability_zone": "2",
    "domain_name_label": null,
    "fqdn": null,
    "id": "/subscriptions/someguid/resourceGroups/example/providers/Microsoft.Network/publicIPAddresses/pip-example-1",
    "idle_timeout_in_minutes": 15,
    "ip_address": "1.2.3.4",
    "ip_tags": null,
    "ip_version": "IPv4",
    "location": "westeurope",
    "name": "pip-example-1",
    "public_ip_prefix_id": null,
    "resource_group_name": "example",
    "reverse_fqdn": null,
    "sku": "Standard",
    "sku_tier": "Regional",
    "tags": {
      "foo": "bar"
    },
    "timeouts": null,
    "zones": [
      "2"
    ]
  },
  "pip2": {
    "allocation_method": "Static",
    ...etc...
  }
}

I have a unit test that tries to retrieve this output in a useful form using

tfOutput := terraform.OutputMapOfObjects(t, terraformOptions, "public_ip_addresses")

But it throws an error "Type switching to map[string]interface{} failed."

This seems to happen at the point it tries to parse the zones property of the first object in the map, as it is a list:

err := errors.New("Type switching to map[string]interface{} failed.")

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingp:queued

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions