mongodb / terraform-provider-mongodbatlas

Terraform MongoDB Atlas Provider: Deploy, update, and manage MongoDB Atlas infrastructure as code through HashiCorp Terraform
https://registry.terraform.io/providers/mongodb/mongodbatlas
Mozilla Public License 2.0
244 stars 172 forks source link

Error: error getting search index information: json: cannot unmarshal array into Go struct field IndexMapping.mappings.fields of type mongodbatlas.IndexField #545

Closed stefanosala closed 3 years ago

stefanosala commented 3 years ago

Terraform CLI and Terraform MongoDB Atlas Provider Version

Terraform v1.0.4
on darwin_amd64
+ provider registry.terraform.io/cloudamqp/cloudamqp v1.9.2
+ provider registry.terraform.io/hashicorp/aws v3.24.1
+ provider registry.terraform.io/hashicorp/google v3.81.0
+ provider registry.terraform.io/hashicorp/null v3.0.0
+ provider registry.terraform.io/hashicorp/random v3.1.0
+ provider registry.terraform.io/hashicorp/template v2.2.0
+ provider registry.terraform.io/heroku/heroku v4.1.1
+ provider registry.terraform.io/jianyuan/sentry v0.6.0
+ provider registry.terraform.io/mongodb/mongodbatlas v1.0.0
+ provider registry.terraform.io/redislabs/rediscloud v0.2.1

Terraform configuration

resource "mongodbatlas_search_index" "skus" {
  project_id      = mongodbatlas_project.main.id
  cluster_name    = mongodbatlas_cluster.main.name
  analyzer        = "lucene.standard"
  collection_name = "skus"
  database        = var.prefix
  mappings_fields = file("./templates/mongodb/search-skus.json")
  name            = "skus.search"
}

# search-skus.json
{
  "account": {
    "type": "objectId"
  },
  "productName": {
    "type": "autocomplete"
  },
  "sku": {
    "type": "autocomplete"
  },
  "variantName": {
    "type": "autocomplete"
  }
}

Atlas search index definition

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "account": {
        "type": "objectId"
      },
      "productName": {
        "type": "autocomplete"
      },
      "sku": [
        {
          "analyzer": "lucene.keyword",
          "searchAnalyzer": "lucene.keyword",
          "type": "string"
        },
        {
          "type": "autocomplete"
        }
      ],
      "variantName": {
        "type": "autocomplete"
      }
    }
  }
}

Steps to Reproduce

  1. terraform apply

Output error

│ Error: error getting search index information: json: cannot unmarshal array into Go struct field IndexMapping.mappings.fields of type mongodbatlas.IndexField
│ 
│   with mongodbatlas_search_index.skus,
│   on mongodb.tf line 82, in resource "mongodbatlas_search_index" "skus":
│   82: resource "mongodbatlas_search_index" "skus" {

Please note that the index has been manually updated via Atlas UI to get that index array definition.

themantissa commented 3 years ago

@stefanosala thank you - we'll have the team take a look and report back.

themantissa commented 3 years ago

@stefanosala this is being caused by a bug in the Atlas go client we use. The bug has been fixed so we'll need to update the provider to be able to use it. We will be working on that quickly. INTMDB-251 internal ticket

themantissa commented 3 years ago

We have a pre-release of 1.0.1 ready - we'll release the GA version tomorrow. If you have time to try it out before then it's here: https://github.com/mongodb/terraform-provider-mongodbatlas/releases/tag/v1.0.1-pre.1

themantissa commented 3 years ago

Fixed in recent release 1.0.1