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

Cannot use terraform on Debian #26627

Closed
kmaikaze opened this issue Oct 19, 2020 · 8 comments
Closed

Cannot use terraform on Debian #26627

kmaikaze opened this issue Oct 19, 2020 · 8 comments
Labels
bug waiting for reproduction unable to reproduce issue without further information

Comments

@kmaikaze
Copy link

kmaikaze commented Oct 19, 2020

Hi there,

I am following tutorial on specially created empty Debian container, I had never any issues with this environment. It looks like azurerm provider is broken
I've followed this walkthrough to install terraform newest version for Linux/Debian distro.

Is there something I'm missing?

Terraform Version

Terraform v0.13.4

Terraform Configuration Files

Debug Output

$ echo $TF_LOG
DEBUG

Crash Output

$ terraform -version

Terraform v0.13.4

$ az login

To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code (...) to authenticate.
The following tenants don't contain accessible subscriptions. Use 'az login --allow-no-subscriptions' to have tenant level access.
a2d8e6b4-e26e-4421-8f3d-ec288c827c7d
[
  {
    "cloudName": "AzureCloud",
     (...)
    }
  }
]

$ mkdir learn-terraform-azure && cd $_

mkdir: created directory 'learn-terraform-azure'

$ cat main.tf

# Configure the Azure provider
terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = ">= 2.26"
    }
  }
}

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "rg" {
  name     = "myTFResourceGroup"
  location = "westus2"
}

$ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding hashicorp/azurerm versions matching ">= 2.26.*"...
- Installing hashicorp/azurerm v2.32.0...
- Installed hashicorp/azurerm v2.32.0 (signed by HashiCorp)

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

$ terraform plan

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/azurerm" to
obtain schema: fork/exec
.terraform/plugins/registry.terraform.io/hashicorp/azurerm/2.32.0/linux_amd64/terraform-provider-azurerm_v2.32.0_x5:
exec format error

$ terraform -version

Terraform v0.13.4
+ provider registry.terraform.io/hashicorp/azurerm v2.32.0

Expected Behavior

Terraform prints action plan

Actual Behavior

Error: Could not load plugin

Steps to Reproduce

$ az login
$ mkdir learn-terraform-azure && cd $_

create file main.tf with content as specified in https://learn.hashicorp.com/tutorials/terraform/azure-build?in=terraform/azure-get-started#create-your-initial-configuration

$ terraform init
$ terraform plan

Additional Context

Terraform is running in Debian Docker container

References

@kmaikaze kmaikaze added bug new new issue not yet triaged labels Oct 19, 2020
@jbardin
Copy link
Member

jbardin commented Oct 19, 2020

Hi @kmaikaze,

I'm not sure how you ended up with the wrong format binary for the provider.
Can you show the output for the following?

uname -a

and

file .terraform/plugins/registry.terraform.io/hashicorp/azurerm/2.32.0/linux_amd64/terraform-provider-azurerm_v2.32.0_x5

Thanks!

@jbardin jbardin added waiting-response An issue/pull request is waiting for a response from the community and removed new new issue not yet triaged labels Oct 19, 2020
@kmaikaze
Copy link
Author

Hello @jbardin

Sure:
$ uname -a
Linux bffb1a9ef788 4.19.76-linuxkit #1 SMP Tue May 26 11:42:35 UTC 2020 x86_64 GNU/Linux
$ file .terraform/plugins/registry.terraform.io/hashicorp/azurerm/2.32.0/linux_amd64/terraform-provider-azurerm_v2.32.0_x5
.terraform/plugins/registry.terraform.io/hashicorp/azurerm/2.32.0/linux_amd64/terraform-provider-azurerm_v2.32.0_x5: data

@ghost ghost removed the waiting-response An issue/pull request is waiting for a response from the community label Oct 19, 2020
@alisdair alisdair added the waiting for reproduction unable to reproduce issue without further information label Oct 19, 2020
@apparentlymart
Copy link
Member

Hi @kmaikaze,

The output you saw from the file command suggests that either you have a corrupted provider executable or your system lacks the data file that file uses to recognize filetype signatures, which is /usr/share/misc/magic.mgc on my system.

Here's the expected output for that executable:

/tmp/terraform-provider-azurerm_v2.32.0_x5: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=qRDb7tV3gekDob_BuZtJ/l0Rbizqi2yjNkICaU_bn/stpvo2mE7BC90IdJxmhq/MPzFk5afzVXpojyk1WrT, stripped

Unfortunately with this being a relatively large binary file it's not very easy to study to see what's going on, but one way we could look a little closer is to use the hexdump command -- assuming you have it installed on that system -- to see what the start of the file looks like. For example, on my system:

$ hexdump -C /tmp/terraform-provider-azurerm_v2.32.0_x5 -n 200
00000000  7f 45 4c 46 02 01 01 00  00 00 00 00 00 00 00 00  |.ELF............|
00000010  02 00 3e 00 01 00 00 00  90 4e 46 00 00 00 00 00  |..>......NF.....|
00000020  40 00 00 00 00 00 00 00  c8 01 00 00 00 00 00 00  |@...............|
00000030  00 00 00 00 40 00 38 00  07 00 40 00 0e 00 03 00  |....@.8...@.....|
00000040  06 00 00 00 04 00 00 00  40 00 00 00 00 00 00 00  |........@.......|
00000050  40 00 40 00 00 00 00 00  40 00 40 00 00 00 00 00  |@.@.....@.@.....|
00000060  88 01 00 00 00 00 00 00  88 01 00 00 00 00 00 00  |................|
00000070  00 10 00 00 00 00 00 00  04 00 00 00 04 00 00 00  |................|
00000080  9c 0f 00 00 00 00 00 00  9c 0f 40 00 00 00 00 00  |..........@.....|
00000090  9c 0f 40 00 00 00 00 00  64 00 00 00 00 00 00 00  |..@.....d.......|
000000a0  64 00 00 00 00 00 00 00  04 00 00 00 00 00 00 00  |d...............|
000000b0  01 00 00 00 05 00 00 00  00 00 00 00 00 00 00 00  |................|
000000c0  00 00 40 00 00 00 00 00                           |..@.....|
000000c8

The first four bytes here represent that this is an ELF executable, which is what we expect to see for a Linux build of a Terraform provider. The next 60 (approximately) bytes after that are the ELF header which is what file is reading to determine that this is a "64-bit LSB executable, x86-64, version 1 (SYSV), statically linked" file.

If you could replicate the above on your system using the .terraform/plugins/registry.terraform.io/hashicorp/azurerm/2.32.0/linux_amd64/terraform-provider-azurerm_v2.32.0_x5 then we could compare the file you have with the file I have and see whether your file has somehow been corrupted during the installation process.

Thanks!

@apparentlymart apparentlymart added the waiting-response An issue/pull request is waiting for a response from the community label Oct 20, 2020
@kmaikaze
Copy link
Author

Hi @apparentlymart !

I did a workaround by downloading the provider file manually, and replace the file downloaded by terraform:

curl https://releases.hashicorp.com/terraform-provider-azurerm/2.32.0/terraform-provider-azurerm_2.32.0_linux_amd64.zip -o tmp/terraform-provider-azurerm_2.32.0_linux_amd64.zip
unzip terraform-provider-azurerm_2.32.0_linux_amd64.zip

And after that it looks quite the same as yours.

$ file (...)/terraform-provider-azurerm_v2.32.0_x5 
(...)/terraform-provider-azurerm_v2.32.0_x5: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=qRDb7tV3gekDob_BuZtJ/l0Rbizqi2yjNkICaU_bn/stpvo2mE7BC90IdJxmhq/MPzFk5afzVXpojyk1WrT, stripped
$ hexdump -C .(...)/terraform-provider-azurerm_v2.32.0_x5 | head -n 20
00000000  7f 45 4c 46 02 01 01 00  00 00 00 00 00 00 00 00  |.ELF............|
00000010  02 00 3e 00 01 00 00 00  90 4e 46 00 00 00 00 00  |..>......NF.....|
00000020  40 00 00 00 00 00 00 00  c8 01 00 00 00 00 00 00  |@...............|
00000030  00 00 00 00 40 00 38 00  07 00 40 00 0e 00 03 00  |....@.8...@.....|
00000040  06 00 00 00 04 00 00 00  40 00 00 00 00 00 00 00  |........@.......|

I've learnt a lot here - thanks for the insights!

What bothers me is why this happens while executing terraform init. Is there some package or other requirement I might missing?

@ghost ghost removed the waiting-response An issue/pull request is waiting for a response from the community label Oct 21, 2020
@apparentlymart
Copy link
Member

Hi @kmaikaze ,

I can't guess why the file was corrupted on your first attempt without some more information: I've not seen this behavior reported before. If you can share a hex dump of the file you had originally then the contents of that for may give a clue as to how it got corrupted.

@kmaikaze
Copy link
Author

@apparentlymart

The file looks like archived or corrupted:

$ hexdump -C .terraform/plugins/registry.terraform.io/hashicorp/azurerm/2.33.0/linux_amd64/terraform-provider-azurerm_v2.33.0_x5 | head -n 50
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00110000  85 88 01 00 00 48 8b b4  24 68 01 00 00 48 8b 1e  |.....H..$h...H..|
00110010  e9 1d ff ff ff 48 89 d8  48 89 f1 e8 20 3e f5 ff  |.....H..H... >..|
00110020  48 89 f1 e8 f8 3d f5 ff  e8 13 3e f5 ff e8 ee 3d  |H....=....>....=|
00110030  f5 ff 48 8d 05 47 2b 01  04 48 89 04 24 e8 7e cb  |..H..G+..H..$.~.|
00110040  ef ff 48 8b 44 24 08 48  c7 40 08 15 00 00 00 48  |..H.D$.H.@.....H|
00110050  8d 0d 1c ea 53 04 48 89  08 48 8b 8c 24 c0 00 00  |....S.H..H..$...|
00110060  00 48 89 48 10 48 8d 0d  b4 b0 e7 03 48 89 0c 24  |.H.H.H......H..$|
00110070  48 89 44 24 08 e8 e6 29  f2 ff 48 89 d8 48 89 f1  |H.D$...)..H..H..|
00110080  e8 bb 3d f5 ff 48 89 f1  e8 93 3d f5 ff e8 ae 3d  |..=..H....=....=|
00110090  f5 ff e8 89 3d f5 ff 48  8d 05 e2 2a 01 04 48 89  |....=..H...*..H.|
001100a0  04 24 e8 19 cb ef ff 48  8b 44 24 08 48 c7 40 08  |.$.....H.D$.H.@.|
001100b0  15 00 00 00 48 8d 0d b7  e9 53 04 48 89 08 48 8b  |....H....S.H..H.|
001100c0  8c 24 c0 00 00 00 48 89  48 10 48 8d 0d 4f b0 e7  |.$....H.H.H..O..|
001100d0  03 48 89 0c 24 48 89 44  24 08 e8 81 29 f2 ff e8  |.H..$H.D$...)...|
001100e0  5c 3d f5 ff e8 37 3d f5  ff 48 8d 05 90 2a 01 04  |\=...7=..H...*..|
001100f0  48 89 04 24 e8 c7 ca ef  ff 48 8b 44 24 08 48 c7  |H..$.....H.D$.H.|
00110100  40 08 13 00 00 00 48 8d  0d 7b 83 53 04 48 89 08  |@.....H..{.S.H..|
00110110  48 8b 8c 24 c0 00 00 00  48 89 48 10 48 8d 0d fd  |H..$....H.H.H...|
00110120  af e7 03 48 89 0c 24 48  89 44 24 08 e8 2f 29 f2  |...H..$H.D$../).|
00110130  ff e8 0a 3d f5 ff e8 e5  3c f5 ff 48 8d 05 3e 2a  |...=....<..H..>*|
00110140  01 04 48 89 04 24 e8 75  ca ef ff 48 8b 44 24 08  |..H..$.u...H.D$.|
00110150  48 c7 40 08 13 00 00 00  48 8d 0d 29 83 53 04 48  |H.@.....H..).S.H|
00110160  89 08 48 8b 8c 24 c0 00  00 00 48 89 48 10 48 8d  |..H..$....H.H.H.|
00110170  0d ab af e7 03 48 89 0c  24 48 89 44 24 08 e8 dd  |.....H..$H.D$...|
00110180  28 f2 ff e8 b8 3c f5 ff  e8 93 3c f5 ff 48 8d 05  |(....<....<..H..|
00110190  ec 29 01 04 48 89 04 24  e8 23 ca ef ff 48 8b 44  |.)..H..$.#...H.D|
001101a0  24 08 48 c7 40 08 12 00  00 00 48 8d 0d 17 50 53  |$.H.@.....H...PS|
001101b0  04 48 89 08 48 8b 8c 24  c0 00 00 00 48 89 48 10  |.H..H..$....H.H.|
001101c0  48 8d 0d 59 af e7 03 48  89 0c 24 48 89 44 24 08  |H..Y...H..$H.D$.|
001101d0  e8 8b 28 f2 ff e8 66 3c  f5 ff e8 41 3c f5 ff 48  |..(...f<...A<..H|
001101e0  8d 05 9a 29 01 04 48 89  04 24 e8 d1 c9 ef ff 48  |...)..H..$.....H|
001101f0  8b 44 24 08 48 c7 40 08  12 00 00 00 48 8d 0d c5  |.D$.H.@.....H...|
00110200  4f 53 04 48 89 08 48 8b  8c 24 c0 00 00 00 48 89  |OS.H..H..$....H.|
00110210  48 10 48 8d 0d 07 af e7  03 48 89 0c 24 48 89 44  |H.H......H..$H.D|
00110220  24 08 e8 39 28 f2 ff e8  14 3c f5 ff e8 ef 3b f5  |$..9(....<....;.|
00110230  ff 48 8d 05 48 29 01 04  48 89 04 24 e8 7f c9 ef  |.H..H)..H..$....|
00110240  ff 48 8b 44 24 08 48 c7  40 08 12 00 00 00 48 8d  |.H.D$.H.@.....H.|
00110250  0d 73 4f 53 04 48 89 08  48 8b 8c 24 c0 00 00 00  |.sOS.H..H..$....|
00110260  48 89 48 10 48 8d 0d b5  ae e7 03 48 89 0c 24 48  |H.H.H......H..$H|
00110270  89 44 24 08 e8 e7 27 f2  ff e8 62 3b f5 ff 48 8d  |.D$...'...b;..H.|
00110280  05 fb 28 01 04 48 89 04  24 e8 32 c9 ef ff 48 8b  |..(..H..$.2...H.|
00110290  44 24 08 48 c7 40 08 12  00 00 00 48 8d 0d 26 4f  |D$.H.@.....H..&O|
001102a0  53 04 48 89 08 48 8b 8c  24 c0 00 00 00 48 89 48  |S.H..H..$....H.H|
001102b0  10 48 8d 0d 68 ae e7 03  48 89 0c 24 48 89 44 24  |.H..h...H..$H.D$|
001102c0  08 e8 9a 27 f2 ff e8 75  3b f5 ff e8 50 3b f5 ff  |...'...u;...P;..|
001102d0  48 8d 05 a9 28 01 04 48  89 04 24 e8 e0 c8 ef ff  |H...(..H..$.....|
001102e0  48 8b 44 24 08 48 c7 40  08 11 00 00 00 48 8d 0d  |H.D$.H.@.....H..|
001102f0  18 1b 53 04 48 89 08 48  8b 8c 24 c0 00 00 00 48  |..S.H..H..$....H|

Anyway, I don't think anyone can figure out what is going on so the issue can be closed. It looks like each time I'm moving the file using VS Code interface or I'm using terraform init file is corrupted. As a workaround I replace it using manually downloaded plugin file.

@apparentlymart
Copy link
Member

Thanks for sharing that follow-up, @kmaikaze!

Indeed, that file content seems weird and not recognizable to me as any particular format. The large sequence of null bytes at the start seems particularly strange.

I agree that there probably isn't anything more we can do here without more information, so at your suggestion I'm going to close this and we will wait to see if someone else later encounters a similar situation. I'm the meantime, it might be worth trying to install the providers you use into one of the local directories Terraform searches in preference to the remote registry (see the CLI Configuration docs on Provider Installation) because if that avoids the problem then at least you will only need to do the manual local install once and future terraform init runs will install from your local directory automatically, so you won't have to do the workaround every time you initialize a new working directory.

@ghost
Copy link

ghost commented Nov 23, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug waiting for reproduction unable to reproduce issue without further information
Projects
None yet
Development

No branches or pull requests

4 participants