opensearch-project / terraform-provider-opensearch

https://registry.terraform.io/providers/opensearch-project/opensearch
Apache License 2.0
73 stars 55 forks source link

[BUG] invalid character 'A' looking for beginning of value #169

Closed nikki603 closed 3 months ago

nikki603 commented 3 months ago

What is the bug?

terraform apply returns

│ Error: invalid character 'A' looking for beginning of value
│ 
│   with opensearch_index.index1,
│   on opensearch.tf line 1, in resource "opensearch_index" "index1":
│    1: resource "opensearch_index" "index1" {

How can one reproduce the bug?

resource "opensearch_index" "index1" {
  name             = "index1"
  index_knn        = true
  default_pipeline = "my-pipeline-id"
  mappings         = <<EOF
{
    "properties": {
      "entity_name_v": {
        "type": "knn_vector",
        "dimension": 384,
        "method": {
          "name": "hnsw",
          "engine": "lucene",
          "space_type": "cosinesimil"
        }
      },
      "entity_name": {
        "type": "text" 
      }
    }
  }
EOF
}

Fails with this error when the provider is using the custom domain URL.

provider "opensearch" {
  url         = "https://search.mydomain.com"
  healthcheck = false
}

This custom domain is a CNAME record in Route53 with value of the AWS provided domain URL.

It does not fail when using the AWS provided domain URL.

provider "opensearch" {
  url         = "https://my-domain.us-east-1.es.amazonaws.com"
  healthcheck = false
}

terraform apply

What is the expected behavior?

index1 created successfully

What is your host/environment?

hashicorp/terraform:1.6.6 Docker container OR MacOS 14.1 (23B2073) opensearch-project/opensearch provider 2.2.0 AWS OpenSearch version OpenSearch_2_11_R20231113-P4 (latest)

rblcoder commented 3 months ago

[Triage] @nikki603 Is custom endpoint configured? https://docs.aws.amazon.com/opensearch-service/latest/developerguide/customendpoint.html opensearch-custom-domain

nikki603 commented 3 months ago

@rblcoder Yes it's configured. I confirmed the custom URL works various ways like in browser to access the Dashboard, Postman requests, and Logstash output plugin.

Screenshot 2024-03-21 at 9 30 42 AM
rblcoder commented 3 months ago

@nikki603 could you check if setting insecure to true helps in the OpenSearch terraform provider?

nikki603 commented 3 months ago

@rblcoder I still get the same error

Screenshot 2024-03-21 at 6 44 46 PM

rblcoder commented 3 months ago

@nikki603 What is the authentication mode you are using? Is it basic authentication or something else?

nikki603 commented 3 months ago

@rblcoder fine grain access control is enabled so I'm using IAM auth. I'm using AWS SSO locally. When running from a CI/CD pipeline I will be using the aws_access_key, aws_secret_key, and aws_token params.

rblcoder commented 3 months ago

@nikki603 I am able apply the following terraform code, I have defined a custom endpoint for my AWS OpenSearch Service domain.

terraform {
  required_providers {
    opensearch = {
      source = "opensearch-project/opensearch"
      version = "2.2.0"
    }
  }
}

provider "opensearch" {
  url = "https://customsubdomain.domain.tld"
  healthcheck        = "false"
  aws_region          = "region"

  version_ping_timeout = "10"

}

resource "opensearch_index" "index" {
  name = "sample"
  number_of_replicas = "1"
  number_of_shards = "1"
}
rblcoder commented 3 months ago

@nikki603 I tested both modifying an existing AWS OpenSearch domain and specifying a custom endpoint at the time of creation of the domain, both are working.

nikki603 commented 3 months ago

I see that I was missing aws_region = "region" when using a custom domain. It works now. Thanks for the attention!

rblcoder commented 3 months ago

Great, good to hear it works now!