Terraform hangs on terraform plan

Hello,
Terraform v0.12.24

  • provider.aws v2.58.0
    Win 10

I’ve reverted to a simple example on the terraform.io doc. New directory except two files:
example.tf
provider “aws” {
region = var.region
}

resource “aws_instance” “example” {
ami = “ami-b374d5a5”
instance_type = “t2.micro”
}

and variables.tf
variable “region” {
default = “us-east-1”
}

I saved these, did terraform init, then terraform apply: just hangs, have to break out by force.

I didn’t use a package manager to install terraform, should I try to remove and re-install? Not seeing any documentation on how to reinstall terraform, were there changes made in the machine registry?

Thanks,
CF

I started fresh with

Hi @cottagefarmerwwt,

I think a common reason why the AWS provider can appear to hang on startup is when it can’t find any credentials and it tries to detect if it is running on an EC2 instance where instance profile credentials might be available. Depending on how the network stack on your system is configured, that might hang rather than fail immediately because EC2 metadata service uses a link-local-reserved IP address (169.254.169.254).

If you also have the AWS CLI installed you could perhaps try running an AWS CLI command that requires credentials to see if it gives you a similar result. If it also hangs or if it produces a credentials-related error, that may suggest that AWS credentials are not configured correctly on your system.


Regarding uninstalling Terraform: Terraform for Windows is a standalone Windows executable which you can just delete. It does not interact with the Windows registry. However, for that reason it’s also unlikely that reinstalling will change the behavior you are seeing.

1 Like

Thanks @apparentlymart yes that was it. I tested with creds entered into the script and then it worked. However, it was the same creds I used at the CLI for AWS configure - there in the root of the terraform folder for the script. I checked them several times. If you have such creds at the CLI, and you also have an AWS profile in a script, but without creds, does it stop looking?

Hi @cottagefarmerwwt,

The usual way to use Terraform with AWS is to configure your credentials once in the same location where the CLI looks (e.g. ~/.aws/credentials or in environment variables) and then you don’t have to separately configure your AWS credentials for every program you use which interacts with the AWS APIs. It also means that if you change to using a different approach to configuring your credentials in the future you won’t need to edit your Terraform configuration to do so.

For pragmatic reasons the Terraform AWS provider does allow credentials to be specified inside the provider "aws" block, but that is intended only for exceptional situations. If you do set credentials in the provider configuration then they will override the ones that are shared with the AWS CLI.

Thank you. I do set my creds ok, and end with “terraform-user” which I define in AWS IAM, that allows access to the account to run the scripts. On “terraform plan” do I need to append something to use the creds? It doesn’t find the creds that way and I have to force kill it. Maybe the path is not correct, I’ll recheck that too. Thanks.