Terraform: Not able to run terraform init command

Created on 25 Jun 2019  ยท  16Comments  ยท  Source: hashicorp/terraform

Hi,
I am trying to run the terraform init command, but it fails with the below error message

`C:\tf-templates>terraform init

Initializing the backend...

Initializing provider plugins...

  • Checking for available provider plugins...

Registry service unreachable.

This may indicate a network issue, or an issue with the requested Terraform Registry.

Error: registry service is unreachable, check https://status.hashicorp.com/ for status updates`

I have tried with both 0.12.0 and 0.12.1 but got the same error

Note: I am trying to run the above init command in my office computer where I have proxy setup, not sure if the proxy is blocking me from connecting to the hashicorp site to download the provider.
I am able to run init command on my personal computer.

any help is appreciated.. thanks!

question

Most helpful comment

@dfelski curl is not a dependency, my guess is that you did not have ca-certificates installed (which curl depends on) so the TLS request could not be validated.

All 16 comments

I am also seeing same error

@vrbcntrl

If I'm not wrong you could simply test with a curl command if it works at all.
curl -k https://registry.terraform.io/.well-known/terraform.json

Or enable the debug mode when you run terraform init:
export TF_LOG=TRACE

Make sure to use the right command for your console to set the env variable.

Hi folks - @mpratsch's advice is the right next step. If you are consistently seeing this error message that means your machine is having trouble reaching registry.terraform.io and more information from curl -v or Terraform debug logs should help narrow down the issue further.

Hi @phinze,

I have enabled the TF_LOG=TRACE in my windows 10 machine and then ran terraform init and this is what I got

C:\scans\Cloud\Terraform-Templates>terraform init
2019/07/01 16:16:48 [INFO] Terraform version: 0.12.0
2019/07/01 16:16:48 [INFO] Go runtime version: go1.12.4
2019/07/01 16:16:48 [INFO] CLI args: []string{"C:\\scans\\Cloud\\Terraform\\0.12.0\\terraform.exe", "init"}
2019/07/01 16:16:48 [DEBUG] Attempting to open CLI config file: C:\Users\abc123\AppData\Roaming\terraform.rc

2019/07/01 16:16:48 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2019/07/01 16:16:48 [INFO] CLI command args: []string{"init"}
2019/07/01 16:16:48 [TRACE] Meta.Backend: no config given or present on disk, so returning nil config
2019/07/01 16:16:48 [TRACE] Meta.Backend: backend has not previously been initialized in this working directory
2019/07/01 16:16:48 [DEBUG] New state was assigned lineage "0b94f904-aa1c-08a8-b434-f8c857cee2c3"
2019/07/01 16:16:48 [TRACE] Meta.Backend: using default local state only (no backend configuration, and no existing initialized backend)
2019/07/01 16:16:48 [TRACE] Meta.Backend: instantiated backend of type <nil>
2019/07/01 16:16:48 [DEBUG] checking for provider in "."
2019/07/01 16:16:48 [DEBUG] checking for provider in "C:\\scans\\Cloud\\Terraform\\0.12.0"
2019/07/01 16:16:48 [DEBUG] checking for provisioner in "."
2019/07/01 16:16:48 [DEBUG] checking for provisioner in "C:\\scans\\Cloud\\Terraform\\0.12.0"
2019/07/01 16:16:48 [INFO] Failed to read plugin lock file .terraform\plugins\windows_amd64\lock.json: open .terraform\plugins\windows_amd64\lock.json: The system cannot find the path specified.
2019/07/01 16:16:48 [TRACE] Meta.Backend: backend <nil> does not support operations, so wrapping it in a local backend
2019/07/01 16:16:48 [TRACE] backend/local: state manager for workspace "default" will:
 - read initial snapshot from terraform.tfstate
 - write new snapshots to terraform.tfstate
 - create any backup at terraform.tfstate.backup
2019/07/01 16:16:48 [TRACE] statemgr.Filesystem: reading initial snapshot from terraform.tfstate
2019/07/01 16:16:48 [TRACE] statemgr.Filesystem: snapshot file has nil snapshot, but that's okay
2019/07/01 16:16:48 [TRACE] statemgr.Filesystem: read nil snapshot
2019/07/01 16:16:48 [DEBUG] checking for provider in "."
2019/07/01 16:16:48 [DEBUG] checking for provider in "C:\\scans\\Cloud\\Terraform\\0.12.0"
2019/07/01 16:16:48 [DEBUG] plugin requirements: "aws"=""
2019/07/01 16:16:48 [DEBUG] Service discovery for registry.terraform.io at https://registry.terraform.io/.well-known/terraform.json
Initializing the backend...

Initializing provider plugins...
- Checking for available provider plugins...
2019/07/01 16:16:48 [DEBUG] Failed to request discovery document: Get https://registry.terraform.io/.well-known/terraform.json: dial tcp: lookup registry.terraform.io: no such host
2019/07/01 16:16:48 [ERR] Checkpoint error: Get https://checkpoint-api.hashicorp.com/v1/check/terraform?arch=amd64&os=windows&signature=51dda87a-8404-b13c-5caf-947dc300bd77&version=0.12.0: dial tcp: lookup checkpoint-api.hashicorp.com: no such host

Registry service unreachable.

This may indicate a network issue, or an issue with the requested Terraform Registry.


Error: registry service is unreachable, check https://status.hashicorp.com/ for status updates



C:\scans\Cloud\Terraform-Templates>

so I am not sure if there is anything else that I could try...

however as a workaround, I downloaded the provider plugin from HashiCorp site and manually installed it and then able to run init and plan commands.

Ok so the key error message there is

Get https://registry.terraform.io/.well-known/terraform.json: dial tcp: lookup registry.terraform.io: no such host

The DNS lookup for https://registry.terraform.io is failing from the machine you're running Terraform from. If you figure out why your network is not resolving that host that should lead you to the issue that needs to be solved.

I was also facing this issue inside of a Alpine based Docker container. In my scenario the missing curl installation was the reason for this behavior. A simple apk add curl fixed it. Is this dependency somewhere documented?

I am having the same issue on OSX.

$ terraform init -backend-config=beconf.tfvars.local
2019/07/15 16:40:31 [INFO] Terraform version: 0.12.4
2019/07/15 16:40:31 [INFO] Go runtime version: go1.12.4
2019/07/15 16:40:31 [INFO] CLI args: []string{"/usr/local/bin/terraform", "init", "-backend-config=beconf.tfvars.local"}
2019/07/15 16:40:31 [DEBUG] Attempting to open CLI config file: /Users/*/.terraformrc
2019/07/15 16:40:31 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2019/07/15 16:40:31 [INFO] CLI command args: []string{"init", "-backend-config=beconf.tfvars.local"}

Initializing the backend...
2019/07/15 16:40:31 [TRACE] Meta.Backend: no config given or present on disk, so returning nil config
2019/07/15 16:40:31 [TRACE] Meta.Backend: backend has not previously been initialized in this working directory
2019/07/15 16:40:31 [DEBUG] New state was assigned lineage "b867f8a0-09bb-1bf3-05ff-25928f28a391"
2019/07/15 16:40:31 [TRACE] Meta.Backend: using default local state only (no backend configuration, and no existing initialized backend)
2019/07/15 16:40:31 [TRACE] Meta.Backend: instantiated backend of type
2019/07/15 16:40:31 [DEBUG] checking for provider in "."
2019/07/15 16:40:31 [DEBUG] checking for provider in "/usr/local/bin"
2019/07/15 16:40:31 [DEBUG] checking for provisioner in "."
2019/07/15 16:40:31 [DEBUG] checking for provisioner in "/usr/local/bin"
2019/07/15 16:40:31 [INFO] Failed to read plugin lock file .terraform/plugins/darwin_amd64/lock.json: open .terraform/plugins/darwin_amd64/lock.json: no such file or directory
2019/07/15 16:40:31 [TRACE] Meta.Backend: backend does not support operations, so wrapping it in a local backend
2019/07/15 16:40:31 [TRACE] backend/local: state manager for workspace "default" will:

  • read initial snapshot from terraform.tfstate
  • write new snapshots to terraform.tfstate
  • create any backup at terraform.tfstate.backup
    2019/07/15 16:40:31 [TRACE] statemgr.Filesystem: reading initial snapshot from terraform.tfstate
    2019/07/15 16:40:31 [TRACE] statemgr.Filesystem: snapshot file has nil snapshot, but that's okay
    2019/07/15 16:40:31 [TRACE] statemgr.Filesystem: read nil snapshot
    2019/07/15 16:40:31 [DEBUG] checking for provider in "."
    2019/07/15 16:40:31 [DEBUG] checking for provider in "/usr/local/bin"
    2019/07/15 16:40:31 [DEBUG] plugin requirements: "azurerm"=""

2019/07/15 16:40:31 [DEBUG] Service discovery for registry.terraform.io at https://registry.terraform.io/.well-known/terraform.json
Initializing provider plugins...

Registry service unreachable.

This may indicate a network issue, or an issue with the requested Terraform Registry.

Error: registry service is unreachable, check https://status.hashicorp.com/ for status updates

@dfelski curl is not a dependency, my guess is that you did not have ca-certificates installed (which curl depends on) so the TLS request could not be validated.

I had the same issue, and in my case it wat incorrect permissions on the directory (Mac). Once I set the correct permissions, I was able to successfully run init. Hope this helps...

It appears this issue may be resolved? Can you confirm @vrbcntrl ?

well...in my case, i am running terraform init and plan commands from my work computer that is where its failing, and I guess I need to check with my company proxy team, however as a workaround I am able to download the latest provider plugins from terraform site :https://releases.hashicorp.com/terraform-provider-aws/ manually and place it in the same folder where I have my tf templates. so with this workaround I am able to proceed with my work

so I guess I am good...this ticket can be closed.

Thank you all for your inputs and time.

have a great day!!!

I had the same issue, and in my case it wat incorrect permissions on the directory (Mac). Once I set the correct permissions, I was able to successfully run init. Hope this helps...

What are the correct permissions on which directory?

What are the correct permissions on which directory?

Just try sudo terraform init

as @hrba said, run:
sudo terraform init
this also resolved my issue.(Mac)

For me, I was running in an alpine container and curl was not installed. The terraform package for alpine does not declare a dependency on curl. After installing curl, terraform init worked.

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.

Was this page helpful?
0 / 5 - 0 ratings