skip to Main Content

Just started using IntelliJ with AWS and this error pops after using the terraform apply command and the code is just a simple deployment of an EC2 instance.

Error: error configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found.
│ 
│ Please see https://registry.terraform.io/providers/hashicorp/aws
│ for more information about providing credentials.
│
│ Error: failed to refresh cached credentials, no EC2 IMDS role found, operation error ec2imds: GetMetadata, request send failed, Get "http://169.254.169.2
54/latest/meta-data/iam/security-credentials/": dial tcp 169.254.169.254:80: i/o timeout
│
│
│   with provider["registry.terraform.io/hashicorp/aws"],
│   on main.tf line 1, in provider "aws":
│    1: provider "aws" {
│
╵

Credentials with AWS Explorer are correct Using an IAM user in Admin group. Terraform is installed IntelliJ plug-ins for Terraform and AWS are installed There is a connection between IntelliJ and AWS
Using Windows 10 Can’t use admin operations on Windows I feel like Terraform and AWS cant be connected (as the error says), but I can’t understand why.
Any ideas how can I deploy this instance? Any help is appreciated. I am here to answer any questions you may have. I expected to deploy an EC2 instance. I’ve tried creating a new project, reinstalling IntelliJ, using other IDE like VS Code.

2

Answers


  1. Chosen as BEST ANSWER

    So I had to run:

    $ export AWS_ACCESS_KEY_ID=(your access key id)
    $ export AWS_SECRET_ACCESS_KEY=(your secret access key)
    

    With my keys in the Ubuntu terminal in IntelliJ and it worked!


  2. Alternatively, you can configure your provider block as follows:

    provider "aws" {
      region                  = "aws_region_to_create_resources"
      profile                 = "aws_profile_to_use"
    }
    

    or if your aws credentials file is in another path other than the default $HOME/.aws :

    provider "aws" {
      region                  = "aws_region_to_create_resources"
      shared_credentials_file = "path_to_aws_credentials_file"
      profile                 = "aws_profile_to_use"
    }
    

    Specifying a profile has the advantage of allowing you to use different AWS accounts for different environments. You can also use this method to deploy resources in the same terraform module to different accounts or regions by using aliases.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search