詹金斯工作中不断"Error: Could not load plugin: Plugin reinitialization required"



我在Jenkis作业中遇到了这个问题:

+ terraform --version
Terraform v0.15.5
+ rm -rf .terraform/
+ rm -f .terraform.lock.hcl
+ terraform init -upgrade -reconfigure
Upgrading modules...
...
Initializing the backend...
Successfully configured the backend "s3"! Terraform will automatically
use this backend unless the backend configuration changes.
Initializing provider plugins...
- Finding hashicorp/aws versions matching "~> 3.0"...
- Using hashicorp/aws v3.75.2 from the shared cache directory
...
Terraform has been successfully initialized!
...
+ terraform plan -var-file qa-up.tfvars -out=tfplan
╷
│ Error: Could not load plugin
│ 
│ 
│ Plugin reinitialization required. Please run "terraform init".
│ 
│ Plugins are external binaries that Terraform uses to access and manipulate
│ resources. The configuration provided requires plugins which can't be
│ located,
│ 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".
│ 
│ failed to instantiate provider "registry.terraform.io/hashicorp/aws" to
│ obtain schema: the cached package for registry.terraform.io/hashicorp/aws
│ 3.75.2 (in .terraform/providers) does not match any of the checksums
│ recorded in the dependency lock file

script returned exit code 1

供应商(本地(:

$ terraform providers
Providers required by configuration:
.
├── provider[registry.terraform.io/hashicorp/aws]
└── module.elasticache
└── provider[registry.terraform.io/hashicorp/aws] ~> 3.0
Providers required by state:
provider[registry.terraform.io/hashicorp/aws]

但一旦在本地运行(假设地形版本也是0.15.5(,就不存在这样的问题。它的原因是什么?如何解决?

当使用多个CPU架构时,往往会出现此问题。terraform init命令将下载底层CPU体系结构的提供程序二进制文件,并创建相应的.terraform.lock.hcl文件。为了使其在混合环境中工作,有一个命令可以用来避免问题[1]:

terraform providers lock 
-platform=windows_amd64  # 64-bit Windows
-platform=darwin_amd64   # 64-bit macOS
-platform=linux_amd64     # 64-bit Linux

对于M1 MacOS,它将是-platform=darwin_arm64。由于似乎涉及某种缓存,删除旧的锁定文件并使用新的锁定文件应该会有所帮助。


[1]https://developer.hashicorp.com/terraform/cli/commands/providers/lock#specifying-目标平台

以下对我有效:

terraform state replace-provider   registry.terraform.io/-/template  registry.terraform.io/hashicorp/template
terraform state replace-provider   registry.terraform.io/-/aws  registry.terraform.io/hashicorp/aws

来源:从0.12升级到0.13:无法实例化提供程序"registry.terraform.io/-/aws"以获取

最新更新