terraform: "Error: Could not load plugin"

Viewed 5358

Running a terraform plan command with the docker image of hashicorp results in this error:

 $ 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"

Looks like it is similar to this issue. I am using workspaces to refer to different environments. And it only happens when using terraform with the docker image. When using the binary, it works as expected.

Is there a way to overcome this problem when using the docker image hashicorp/terraform?

1 Answers

You can try with setting up working directory to terrascripts using -w flag:

init

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

plan

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

Depending on your setup you may need to work on this more to provide valid aws credentials.

Related