Terraform OpenSearch 索引资源导致提供程序错误

问题描述 投票:0回答:1

我正在开发一个使用 Terraform 来管理 OpenSearch 索引的项目。当我注释掉 opensearch_index 资源时,一切正常,并且 terraform init 运行没有问题。但是,当我取消注释资源时,我在 terraform plan 或 terraform apply 期间遇到问题。

这是我定义的资源的简化版本:

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
}

我的提供商.tf:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
    opensearch = {
      source = "opensearch-project/opensearch"
      version = "2.3.0"
    }
  }
}
PS C:\Users\projets\iac> 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:\Users\projets\iac> 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:\Users\iac> terraform init -upgrade
Initializing the backend...
Upgrading modules...
- api-gateway in modules\resource_api_gateway
- api-gateway_back in modules\resource_api_gateway_back
- api-gateway_bff in modules\resource_api_gateway_bff
- elastic-search in modules\resource_elastic_search
- lambda in modules\lambda
- module-cloud-front in modules\cloudfront
- module-s3 in modules\resource_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:\Users\iac> 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



我删除了 .terraform.lock.hcl 文件,从状态文件中删除了所有 opensearch 资源并再次运行 init,但仍然遇到相同的问题。 在我的 opensearch 模块中,我只有集群、域、密码配置和资源 opensearch_index 来创建索引,如果我评论它,我的 init 工作正常,否则它会出现错误。

也许他引用了其他提供商,因为当我测试时,我使用了不同的提供商:hashicorp/opensearch,但我删除了 .terraform.lock.file,它应该在初始化后工作

amazon-web-services terraform amazon-opensearch elasticsearch-indices
1个回答
0
投票

尝试将所有这些都放在同一个文件中并使用“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]
}
© www.soinside.com 2019 - 2024. All rights reserved.