Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting terraform plan file. ERROR: Failed to convert terraform plan file to JSON format via terraform #381

Closed
i0na-k opened this issue Oct 1, 2020 · 3 comments · Fixed by #478
Assignees
Labels
Projects

Comments

@i0na-k
Copy link

i0na-k commented Oct 1, 2020

Description :
This is the output when running the container using docker run --rm -v $PWD:/target -it eerkunt/terraform-compliance -f features -p tf.out

To Reproduce

  1. My tf plan .out file is empty. I am following exactly the steps seen here:
    https://docs.microsoft.com/en-us/azure/developer/terraform/best-practices-compliance-testing

  2. I'm running with this command -> docker run --rm -v $PWD:/target -it eerkunt/terraform-compliance -f features -p tf.out

  3. `terraform-compliance v1.3.4 initiated
    . Converting terraform plan file.
    ERROR: Failed to convert terraform plan file to JSON format via terraform. Here is the error :
    None

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

2 problems:

  • Failed to instantiate provider "registry.terraform.io/hashicorp/azurerm" to
    obtain schema: unknown provider "registry.terraform.io/hashicorp/azurerm"
  • Failed to instantiate provider "registry.terraform.io/hashicorp/random" to
    obtain schema: unknown provider "registry.terraform.io/hashicorp/random"`

Expected behavior :
No errors and for the tests to run

Tested versions :

  • terraform-compliance version (v1.3.4)
  • terraform version (Terraform v0.13.2)

Additional context
I was getting version errors when running latest v of terraform so had to downgrade

@EmKayUltra
Copy link

Same problem.

terraform-compliance version (v1.3.6)
terraform version (Terraform v0.13.5)

@tom-dudley
Copy link

I've just had the same issue, and can work around it with the following:

terraform show -json tf.out > tf.out.json
docker run --rm -v $PWD:/target -it eerkunt/terraform-compliance -f features -p tf.out.json

I would suggest that this line be changed to also include the error text Could not load plugin, since it gives the helpful workaround.

@tom-dudley
Copy link

Running docker run --rm -v $PWD:/target --env TF_LOG=trace -it eerkunt/terraform-compliance -f features -p tf.out (note the TF_LOG env var) I get the following:

2020/11/10 14:15:11 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/azurerm v2.35.0 for darwin_amd64 at .terraform/plugins/registry.terraform.io/hashicorp/azurerm/2.35.0/darwin_amd64
2020/11/10 14:15:11 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/random v3.0.0 for darwin_amd64 at .terraform/plugins/registry.terraform.io/hashicorp/random/3.0.0/darwin_amd64
2020/11/10 14:15:11 [TRACE] providercache.fillMetaCache: ignoring .terraform/plugins/registry.terraform.io/hashicorp/azurerm/2.35.0/darwin_amd64 because it is for darwin_amd64, not linux_amd64
2020/11/10 14:15:11 [TRACE] providercache.fillMetaCache: ignoring .terraform/plugins/registry.terraform.io/hashicorp/random/3.0.0/darwin_amd64 because it is for darwin_amd64, not linux_amd64
2020/11/10 14:15:11 [TRACE] providercache.fillMetaCache: using cached result from previous scan of .terraform/plugins
2020/11/10 14:15:11 [WARN] Failed to determine selected providers: failed to recall provider packages selected by earlier 'terraform init': some providers could not be installed:
- registry.terraform.io/hashicorp/azurerm: package for selected version 2.35.0 is no longer available in the local cache directory
- registry.terraform.io/hashicorp/random: package for selected version 3.0.0 is no longer available in the local cache directory

It looks to me like the fact I'm on a Mac is potentially the cause. Is the Docker image built against linux_amd64? I would imagine some multiarch build might potentially fix this?

@eerkunt eerkunt added this to Waiting to be released in Task Queue Jun 4, 2021
@eerkunt eerkunt moved this from Waiting to be released to In progress in Task Queue Jun 4, 2021
@eerkunt eerkunt linked a pull request Jun 4, 2021 that will close this issue
Task Queue automation moved this from In progress to Waiting to be released Jun 4, 2021
@eerkunt eerkunt moved this from Waiting to be released to Released in Task Queue Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Task Queue
Released
Development

Successfully merging a pull request may close this issue.

4 participants