m1-terraform-provider-helper icon indicating copy to clipboard operation
m1-terraform-provider-helper copied to clipboard

Error: Failed to install provider

Open nishant-ci opened this issue 2 years ago • 14 comments

Receiving the error Error: Failed to install provider when installing hashicorp/template in a repo which uses aws provider. Below is the exact error.

│ Error: Failed to install provider
│ 
│ Error while installing hashicorp/template v2.2.0: the local package for
│ registry.terraform.io/hashicorp/template 2.2.0 doesn't match any of the
│ checksums previously recorded in the dependency lock file (this might be
│ because the available checksums are for packages targeting different
│ platforms)

Following is the command that I used.

m1-terraform-provider-helper install hashicorp/template -v v2.2.0

Expected Behavior

When using the command the build generated should match the checksum in the lock file.

Actual Behavior

The generated build is not matching the checksum in lock file

Steps to Reproduce (including precondition)

  1. Run m1-terraform-provider-helper install hashicorp/template -v v2.2.0
  2. Run terraform init
  3. The error is generated at the end of above command

Screenshot on This Problem (if possible)

image

Output after running terraform init

Your Environment

  • OS: MacOS Monterey 12.2.1
  • m1-terraform-provider-helper version: Latest, installed yesterday

nishant-ci avatar Feb 14 '22 03:02 nishant-ci

Please try to delete the terraform.lock.hcl file and run terraform init again. My guess is, that you run a terraform init without local providers first, which downloaded providers and created the lockfile. Now when switching to local providers, of course the checksum is different, because we compile the providers ourselves.

In addition, could you post the outputs of m1-terraform-provider-helper status and m1-terraform-provider-helper list here?

Junkern avatar Feb 14 '22 08:02 Junkern

Hi @Junkern ,

Thanks for the response.

Below is the output after deleting .terraform.lock.hcl and running terraform init.

image

Below is the output after running m1-terraform-provider-helper status and m1-terraform-provider-helper list

image

nishant-ci avatar Feb 14 '22 09:02 nishant-ci

This is interesting. The second screenshot states that m1-terraform-provider-helper is active and that you have hashicorp/template installed.

However, in the first screenshot it (successfully) downloads hashicorp/aws and fails at hashicorp/template ( due to no darwin_arm64 image available). It apparently is not using the local providers, because it is downloading providers.

So, apparently terraform does not know about the plugin dir. Can you check what is inside $HOME/.terraform.d/plugins? Also, do you have $HOME/.terraformrc file and paste the contents here?

Junkern avatar Feb 14 '22 13:02 Junkern

@Junkern

There is no .terraformrc file in home directory.

Below is the what is inside .terraform.d directory.

image

nishant-ci avatar Feb 14 '22 13:02 nishant-ci

The tree looks okay except the part after darwin_arm_64. There should be a single executable inside darwin_arm_64 with the name terraform-provider-template_2.2.0_x5. From the looks of your tree, there are two folders below the darwin_arm64.

For me it looks like this:

plugins/registry.terraform.io/hashicorp/template
├── 2.1.2
│   └── darwin_arm64
│       └── terraform-provider-template_2.1.2_x5
└── 2.2.0
    └── darwin_arm64
        └── terraform-provider-template_2.2.0_x5

Junkern avatar Feb 14 '22 14:02 Junkern

Could you run m1-terraform-provider-helper install hashicorp/template -v v2.2.0 again and paste the output of the log?

Junkern avatar Feb 14 '22 14:02 Junkern

@Junkern

Below is the log after running m1-terraform-provider-helper install hashicorp/template -v v2.2.0.

xxxx ~ % m1-terraform-provider-helper install hashicorp/template -v v2.2.0
Repo: https://github.com/hashicorp/terraform-provider-template
GitRepo: https://github.com/hashicorp/terraform-provider-template
HEAD is now at 920304d v2.2.0
2022/02/14 20:03:05 version: v2.2.0
==> Checking that code complies with gofmt requirements...
go install
Cancel
2022/02/14 20:03:07 Move from /Users/xx/go/bin/ to /Users/xx/.terraform.d/plugins/registry.terraform.io/hashicorp/template/2.2.0/darwin_arm64/_2.2.0_x5
2022/02/14 20:03:07 rename /Users/xx/go/bin/ /Users/xx/.terraform.d/plugins/registry.terraform.io/hashicorp/template/2.2.0/darwin_arm64/_2.2.0_x5: file exists

nishant-ci avatar Feb 14 '22 14:02 nishant-ci

Okay, thanks. That was very helpful! I will provide a fix in a few hours!

Junkern avatar Feb 14 '22 14:02 Junkern

@nishant-ci Should be fixed with version 0.5.1. Thanks for reporting!

Junkern avatar Feb 14 '22 15:02 Junkern

@Junkern

Thanks a lot it worked. Had to do some minor changes to lock file for it to work with terraform cloud but its fine.

nishant-ci avatar Feb 14 '22 16:02 nishant-ci

I have never worked with terraform cloud, so I would be interested in those changes. Are those changes something m1-terraform-provider-helper should do out of the box? Or with a flag?

Junkern avatar Feb 14 '22 16:02 Junkern

@Junkern

So the thing is after doing terraform init in darwin_arm64. A new lock file is generated containing the hash for new provider package(darwin_arm64) that does not contain all the hashes for all the OSes and the OS in terraform cloud uses linux so its terraform init failed when I pushed. A fix can be that we run terraform providers lock but it wont work for darwin_arm64 since the provider that we installed with helper is not available for this platform.

So I went to a previous commit and copied the hashes for previous provider installation of linux(before mac I was using Ubuntu) and pasted them in current lock file. Those hashes start with zh. This I did for only hashicorp/template.

I think it can be done by this plugin. When it is ran from terraform project folder. We can add a flag where we want to use the hashes from previous installation. So when the provider is installed the old lock file is copied to a temp file and then deleted from current folder because only then the terraform init will work and once it is successful we can create a merged version of new lock file and old lock file for that provider.

Hope you understand. Let me know if you need any help.

nishant-ci avatar Feb 14 '22 16:02 nishant-ci

Hmmm, interesting. Thanks for the explanation! This could make for a good addition to the tool, but I will have to think things through first.

Junkern avatar Feb 15 '22 10:02 Junkern

@nishant-ci I just released v0.7.0 which has a m1-terraform-provider-helper lockfile upgrade command to add the hashes of the local providers to the lockfile. Does that help with your problem?

Junkern avatar Jul 07 '22 09:07 Junkern

I'm having similar issue when using m1-terraform-provider-helper install hashicorp/google The output error is error: Malformed version: I couldnot find the terraform.lock.hcl file to delet, since terraform init never worked for me!

Nameer-Alkhayyat avatar Sep 14 '22 18:09 Nameer-Alkhayyat

Please supply the -v flag to supply a value As shown in the README

m1-terraform-provider-helper activate # (In case you have not activated the helper)
m1-terraform-provider-helper install hashicorp/vault -v v2.10.0 # Install and compile

Junkern avatar Sep 15 '22 07:09 Junkern

Closing, as the initial problem was fixed.

Junkern avatar Sep 15 '22 07:09 Junkern

Might have a similar issue, no executable seems to be generated. Also the provider is not created in go/bin

m1-terraform-provider-helper install opsgenie/opsgenie -v v0.6.11
Getting provider data from terraform registry
Getting source code...
Compiling...
2022/09/19 15:54:57 rename /.../go/bin/terraform-provider-opsgenie /.../.terraform.d/plugins/registry.terraform.io/opsgenie/opsgenie/0.6.11/darwin_arm64/terraform-provider-opsgenie_0.6.11_x5: no such file or directory

m1-terraform-provider-helper list                          
opsgenie/opsgenie -> 0.6.11
m1-terraform-provider-helper status                        
Status: Active
Local providers are used
terraform init

│ Error: Failed to install provider
│ 
│ Error while installing opsgenie/opsgenie v0.6.11: provider binary not
│ found: could not find executable file starting with
│ terraform-provider-opsgenie

GustavJaner avatar Sep 19 '22 14:09 GustavJaner

This is probably because the opsgenie provider is using goreleaser in their make build and that places the files somewhere unexpected. @GustavJaner could you open a seperate issue for that?

Junkern avatar Sep 20 '22 14:09 Junkern