I’m working on a project using Terraform to manage OpenSearch indexes. When I comment out the opensearch_index resources, everything works fine, and terraform init runs without issues. However, when I uncomment the resources, I encounter a problem during terraform plan or terraform apply.
Here is a simplified version of the resources I’m defining:
resource "opensearch_index" "my_index" {
name = "my_index"
number_of_shards = "1"
number_of_replicas = "1"
mappings = <<EOF
{
"properties": {
"name": { "type": "keyword" },
"date": { "type": "date" }
}
}
EOF
}
my provider.tf:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
opensearch = {
source = "opensearch-project/opensearch"
version = "2.3.0"
}
}
}
PS C:Usersprojetsiac> terraform init
Initializing the backend...
Initializing modules...
Initializing provider plugins...
- Finding latest version of hashicorp/opensearch...
- Reusing previous version of hashicorp/aws from the dependency lock file
- Reusing previous version of opensearch-project/opensearch from the dependency lock file
- Reusing previous version of hashicorp/archive from the dependency lock file
- Reusing previous version of hashicorp/random from the dependency lock file
- Reusing previous version of hashicorp/template from the dependency lock file
- Reusing previous version of hashicorp/aws from the dependency lock file
- Reusing previous version of opensearch-project/opensearch from the dependency lock file
- Reusing previous version of hashicorp/archive from the dependency lock file
- Reusing previous version of hashicorp/random from the dependency lock file
- Reusing previous version of hashicorp/template from the dependency lock file
- Reusing previous version of opensearch-project/opensearch from the dependency lock file
- Reusing previous version of hashicorp/archive from the dependency lock file
- Reusing previous version of hashicorp/random from the dependency lock file
- Reusing previous version of hashicorp/template from the dependency lock file
- Reusing previous version of hashicorp/archive from the dependency lock file
- Reusing previous version of hashicorp/random from the dependency lock file
- Reusing previous version of hashicorp/template from the dependency lock file
- Reusing previous version of hashicorp/random from the dependency lock file
- Reusing previous version of hashicorp/template from the dependency lock file
- Reusing previous version of hashicorp/template from the dependency lock file
- Using previously-installed hashicorp/archive v2.6.0
- Using previously-installed hashicorp/archive v2.6.0
- Using previously-installed hashicorp/random v3.6.3
- Using previously-installed hashicorp/template v2.2.0
- Using previously-installed hashicorp/aws v5.66.0
- Using previously-installed opensearch-project/opensearch v2.3.0
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/opensearch: provider registry registry.terraform.io does not have a provider named registry.terraform.io/hashicorp/opensearch
│
│ Did you intend to use opensearch-project/opensearch? If so, you must specify that source address in each module which requires that provider. To see which modules are currently depending on
│ hashicorp/opensearch, run the following command:
│ terraform providers
PS C:Usersprojetsiac> terraform providers
Providers required by configuration:
.
├── provider[registry.terraform.io/opensearch-project/opensearch] 2.3.0
├── provider[registry.terraform.io/hashicorp/aws] ~> 5.0
├── module.elastic-search
│ ├── provider[registry.terraform.io/hashicorp/aws]
│ ├── provider[registry.terraform.io/hashicorp/opensearch]
│ └── provider[registry.terraform.io/hashicorp/random]
├── module.lambda
│ ├── provider[registry.terraform.io/hashicorp/archive]
│ └── provider[registry.terraform.io/hashicorp/aws]
Providers required by state:
provider[registry.terraform.io/hashicorp/aws]
provider[registry.terraform.io/hashicorp/archive]
provider[registry.terraform.io/hashicorp/random]
provider[registry.terraform.io/hashicorp/template]
PS C:Usersiac> terraform init -upgrade
Initializing the backend...
Upgrading modules...
- api-gateway in modulesresource_api_gateway
- api-gateway_back in modulesresource_api_gateway_back
- api-gateway_bff in modulesresource_api_gateway_bff
- elastic-search in modulesresource_elastic_search
- lambda in moduleslambda
- module-cloud-front in modulescloudfront
- module-s3 in modulesresource_s3
Initializing provider plugins...
- Finding latest version of hashicorp/random...
- Finding latest version of hashicorp/archive...
- Finding opensearch-project/opensearch versions matching "2.3.0"...
- Finding hashicorp/aws versions matching "~> 5.0"...
- Finding latest version of hashicorp/template...
- Finding latest version of hashicorp/opensearch...
- Using previously-installed hashicorp/random v3.6.3
- Using previously-installed hashicorp/archive v2.6.0
- Using previously-installed opensearch-project/opensearch v2.3.0
- Using previously-installed hashicorp/aws v5.66.0
- Using previously-installed hashicorp/template v2.2.0
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/opensearch: provider registry registry.terraform.io does not have a provider named registry.terraform.io/hashicorp/opensearch
│
│ Did you intend to use opensearch-project/opensearch? If so, you must specify that source address in each module which requires that provider. To see which modules are currently depending on
│ hashicorp/opensearch, run the following command:
│ terraform providers
PS C:Usersiac> terraform init -reconfigure
Initializing the backend...
Successfully configured the backend "s3"! Terraform will automatically
use this backend unless the backend configuration changes.
Initializing modules...
Initializing provider plugins...
- Finding latest version of hashicorp/opensearch...
- Reusing previous version of hashicorp/aws from the dependency lock file
- Reusing previous version of opensearch-project/opensearch from the dependency lock file
- Reusing previous version of hashicorp/archive from the dependency lock file
- Reusing previous version of hashicorp/random from the dependency lock file
- Reusing previous version of hashicorp/template from the dependency lock file
- Using previously-installed hashicorp/aws v5.66.0
- Using previously-installed opensearch-project/opensearch v2.3.0
- Using previously-installed hashicorp/archive v2.6.0
- Using previously-installed hashicorp/random v3.6.3
- Using previously-installed hashicorp/template v2.2.0
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/opensearch: provider registry registry.terraform.io does not have a provider named registry.terraform.io/hashicorp/opensearch
│
│ Did you intend to use opensearch-project/opensearch? If so, you must specify that source address in each module which requires that provider. To see which modules are currently depending on
│ hashicorp/opensearch, run the following command:
│ terraform providers
i removed the .terraform.lock.hcl file, removed all of my opensearch resources from the state file and run init again but still having the same issue.
in my opensearch module,i have only the cluster,domain,password configuration and the resource opensearch_index to create the indexes , if i comment it my init works fine otherwise it bug.
maybe he is referencing an other provider because when i was testing i used a different provider:hashicorp/opensearch but i deleted the .terraform.lock.file and it should work after an init
Try with all this in the same file and use “terraform init -upgrade”
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.67.0"
}
opensearch = {
source = "opensearch-project/opensearch"
version = "~> 2.3.0"
}
}
}
resource "aws_opensearch_domain" "my_domain" {
...
...
}
## Providers
provider "opensearch" {
url = "https://${aws_opensearch_domain.my_domain.endpoint}"
# Endpoint OpenSearch
username = var.master_user_name
password = var.master_user_password
# Must be disabled for basic auth
sign_aws_requests = false
}
resource "opensearch_index" "my_index" {
name = "my_index"
number_of_shards = "1"
number_of_replicas = "1"
mappings = <<EOF
{
"properties": {
"name": { "type": "keyword" },
"date": { "type": "date" }
}
}
EOF
lifecycle {
ignore_changes = [mappings]
}
depends_on = [aws_opensearch_domain.my_domain]
}