Terraform OpenSearch Index Resource Causes provider Error

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]
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật