地形:"Error: Could not load plugin"



使用hashicorp的docker映像运行地形平面命令会导致以下错误:

$ docker run -it -v `pwd`:/terrascripts  hashicorp/terraform plan /terrascripts
Unable to find image 'hashicorp/terraform:latest' locally
latest: Pulling from hashicorp/terraform
Digest: sha256:eab63752545a0295eedc1318da1d293126cce4689bcd4b139afe816da3f6fffb
Status: Downloaded newer image for hashicorp/terraform:latest
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: unknown provider "registry.terraform.io/hashicorp/aws"

看起来与问题类似。我使用工作区来指代不同的环境。只有在使用带有docker图像的terraform时才会发生这种情况。当使用二进制文件时,它按预期工作。

当使用docker镜像hashicorp/terraform时,有没有办法克服这个问题?

您可以尝试使用-w标志将工作目录设置为terrascripts

初始化

docker run -it -v `pwd`:/terrascripts -w /terrascripts  hashicorp/terraform init

计划

docker run -it -v `pwd`:/terrascripts -w /terrascripts  hashicorp/terraform plan

根据您的设置,您可能需要更多的工作来提供有效的aws凭据。

最新更新