Terraform throwing error, "No valid credential sources found for AWS Provider" on Windows

Viewed 1252

I started learning Terraform. I am now trying to deploy an EC2 instance to the AWS following the tutorial. I am using Windows 10. I have configured the AWS credentials on my laptop and I have been using it to deploy my applications to the ElasticBeanstalk. But it seems not to be working with Terraform.

I have an example.tf file with the following code.

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 2.70"
    }
  }
}

provider "aws" {
  profile = "default"
  region  = "us-west-1"
}

resource "aws_instance" "example" {
  ami           = "ami-830c94e3"
  instance_type = "t2.micro"
}

To deploy, I have run the following command.

terraform apply

Then I got the following error.

Error: No valid credential sources found for AWS Provider.
        Please see https://terraform.io/docs/providers/aws/index.html for more information on
        providing credentials for the AWS Provider

Instead of using profile, when I use, acess_key and access_secret, it is working as expected. But there are AWS credentials already configured on my machine. I cannot just figure out why it is not working. What is wrong with my configuration and how can I fix it?

This is my ~/.aws/config file.

enter image description here

This is my ~/.aws/credentials file.

enter image description here

0 Answers
Related