当我执行terraform init时,我得到了以下输出:
Initializing modules...
- compute in modules\compute
- private_network in modules\private_network
- public_ip in modules\public_ip
- route in modules\route
Initializing the backend...
Initializing provider plugins...
- Finding terraform-provider-openstack/openstack versions matching "~> 1.35.0"...
- Finding latest version of hashicorp/openstack...
- Installing terraform-provider-openstack/openstack v1.35.0...
- Installed terraform-provider-openstack/openstack v1.35.0 (self-signed, key ID 4F80527A391BEFD2)
Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/plugins/signing.html
Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider
hashicorp/openstack: provider registry registry.terraform.io does not have a
provider named registry.terraform.io/hashicorp/openstack这是我的provider.tf文件(灵感来自官方的Terraform文档):
# Define required providers
terraform {
required_version = ">= 0.14.0"
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "~> 1.35.0"
}
}
}
# Configure the OpenStack Provider
provider "openstack" {
user_name = "username"
tenant_name = "tenantname"
password = "mypasswd"
auth_url = "http://my.openstack.lan:5000"
region = "RegionOne"
}
# Create a web server
#resource "openstack_compute_instance_v2" "test-server" {
# ...
#}当我检查版本时,我会得到这样的结果:
Terraform v0.14.2
Your version of Terraform is out of date! The latest version
is 1.0.3. You can update by downloading from https://www.terraform.io/downloads.html这是我运行terraform apply的时候
Error: Could not load plugin
Plugin reinitialization required. Please run "terraform init".
Plugins are external binaries that Terraform uses to access and manipulate
don't satisfy the version constraints, or are otherwise incompatible.
Terraform automatically discovers provider requirements from your
configuration, including providers used in child modules. To see the
requirements and constraints, run "terraform providers".
2 problems:
- Failed to instantiate provider "registry.terraform.io/hashicorp/openstack"
to obtain schema: unknown provider "registry.terraform.io/hashicorp/openstack"
- Failed to instantiate provider
"registry.terraform.io/terraform-provider-openstack/openstack" to obtain
schema: unknown provider最后是terraform providers
Providers required by configuration:
.
├── provider[registry.terraform.io/terraform-provider-openstack/openstack] ~> 1.35.0
├── module.compute
│ └── provider[registry.terraform.io/hashicorp/openstack]
├── module.private_network
│ └── provider[registry.terraform.io/hashicorp/openstack]
├── module.public_ip
│ └── provider[registry.terraform.io/hashicorp/openstack]
└── module.route
└── provider[registry.terraform.io/hashicorp/openstack]发布于 2021-08-11 16:53:16
要手动管理提供程序版本,请使用terraform mirror。
基本上:创建提供程序路径,下载并安装提供程序,设置terraform镜像路径。
# mkdir -p /root/.local/share/terraform/plugins/registry.terraform.io/terraform-provider-openstack/openstack/1.40.0/linux_amd64/
# curl -L https://releases.hashicorp.com/terraform-provider-openstack/1.40.0/terraform-provider-openstack_1.40.0_linux_amd64.zip -o terraform-provider-openstack.zip
# unzip terraform-provider-openstack.zip
# mv terraform-provider-openstack_v1.40.0 /root/.local/share/terraform/plugins/registry.terraform.io/terraform-provider-openstack/openstack/1.40.0/linux_amd64/
# terraform providers mirror /root/.local/share/terraform/plugins/一旦完成,当terraform初始化时,它将从此路径加载提供程序。(我使用此路径是因为在TF的以前版本中,提供程序在那里)。
此外,当我从Gitlab在openstack上部署TF时,我已经创建了一个docker镜像。下面是Dockerfile:
FROM hashicorp/terraform:0.14.7
RUN apk update && \
apk upgrade && \
apk add --no-cache \
curl && \
mkdir -p /root/.local/share/terraform/plugins/registry.terraform.io/terraform-provider-openstack/openstack/1.40.0/linux_amd64/ && \
curl -L https://releases.hashicorp.com/terraform-provider-openstack/1.40.0/terraform-provider-openstack_1.40.0_linux_amd64.zip -o terraform-provider-openstack.zip && \
unzip terraform-provider-openstack.zip && \
mv terraform-provider-openstack_v1.40.0 /root/.local/share/terraform/plugins/registry.terraform.io/terraform-provider-openstack/openstack/1.40.0/linux_amd64/ && \
terraform providers mirror /root/.local/share/terraform/plugins/
ENTRYPOINT /bin/sh发布于 2021-08-04 12:44:13
有一种方法可以避免这样的错误:
您可以将openstack提供程序定义为空白,并在将要执行terraform plan/apply命令->的同一终端上提供openrc
provider "openstack" {}您的openrc.sh也应该包含这一点
read -sr OS_PASSWORD_INPUT
export TF_VAR_os_password=$OS_PASSWORD_INPUT我的provider.tf有以下几行代码:
terraform {
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "~> 1.42.0"
}
}
}
provider "openstack" {}我在我的模板中使用os_password。在这种情况下,我使用TF_VAR_os_password作为环境变量,在variable.tf中,我只是将变量名定义为:
variable "os_password" {
sensitive = true
}https://stackoverflow.com/questions/68647767
复制相似问题