Creating opensearch dashboard visualisations/dashboards via terraform

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):
OpenSearch 2.15

Describe the issue:
I have set up an opensearch domain/pipeline/dashboard in terraform and then also created an index pattern in terraform that i can set up queries/visualisations against. When i create visualisations against this manually in the opensearch dashboards console this works, however i have been trying to replicate this metric creation in terraform as i need to implement this across multiple accounts. here is the resource block to do this:

resource “opensearch_dashboard_object” “visualization” {
tenant_name = “tenant”
body = <<EOF
[
{
“_id”: “visualization:${var.account_alias}-daily-device-numbers”,
“_type”: “doc”,
“_source”: {
“type”: “visualization”,
“visualization”: {
“title”: “Daily device numbers”,
“visState”: “{"title":"daily device numbers","type":"metric","params":{"addTooltip":true},"aggs":[{"id":"1","enabled":true,"type":"count","schema":"metric"}]}”,
“uiStateJSON”: “{}”,
“description”: “count the number of devices in certain categories”,
“version”: 1
}
}
}
]
EOF
}

Relevant Logs or Screenshots:
However when i try to view this in the visualization in the opensearch console i get the following error (the index pattern i created is the default index pattern so it should target this) - Failed to load the visualization, Trying to initialize aggs without index pattern

@Will29 You need to assign index pattern to your visualization.
Take a look at my Terraform example.

terraform {
  required_providers {
    opensearch = {
      source  = "opensearch-project/opensearch"
      version = "~> 2.0"
    }
  }
}
provider "opensearch" {
  # Adjust with your OpenSearch cluster's endpoint and credentials
  url      = var.opensearch_url
  username = var.opensearch_username
  password = var.opensearch_password
  insecure = true
}

resource "opensearch_dashboard_object" "test_visualization_v7" {
  body        = <<EOF
[
  {
    "_id": "visualization:response-time-percentile_v1",
    "_type": "doc",
    "_source": {
      "type": "visualization",
      "visualization": {
        "title": "Total response time percentiles2",
        "visState": "{\"title\":\"vis1\",\"type\":\"table\",\"aggs\":[{\"id\":\"1\",\"enabled\":true,\"type\":\"count\",\"params\":{},\"schema\":\"metric\"}],\"params\":{\"perPage\":10,\"showPartialRows\":false,\"showMetricsAtAllLevels\":false,\"showTotal\":false,\"totalFunc\":\"sum\",\"percentageCol\":\"\"}}",

        "uiStateJSON": "{}",
        "description": "",
        "version": 1,
        "kibanaSavedObjectMeta": {
          "searchSourceJSON": "{\"query\":{\"query\":\"\",\"language\":\"kuery\"},\"filter\":[],\"indexRefName\":\"kibanaSavedObjectMeta.searchSourceJSON.index\"}"
        }

      },
      "references": [
        {
          "name": "kibanaSavedObjectMeta.searchSourceJSON.index",
          "type": "index-pattern",
          "id": "37c65470-b933-11ef-ad85-817902cf53ce"
        }
      ]
    }
  }
]
EOF
}

You can find index pattern ID in its URL.