TLDR: Setup AWS CLI, authenticate to AWS with it, and terraform will automatically use those credentials.

Step-by-step:

  1. Install AWS CLI
  2. Authenticate the AWS CLI with your AWS credentials
  3. Install terraform
  4. Run terraform init and terraform plan to prove it works.

The AWS CLI will create a ~/.aws/credentials file once authenticated. Terraform will then use this to authenticate with AWS. So, when terraform goes to create stuff in AWS: it will use these credentials. That’s basically it, you’re done. Here’s an example of what a credentials file looks like:

~/.aws/credentials:

[default]
aws_access_key_id = 20_CHARACTER_ACCESS_KEY
aws_secret_access_key = 40_CHARACTER_SECRET_KEY

If you are a solo-developer, your credential file should be very straight forward. This should take 5 min.

You could also give credentials to terraform like below, but this is not recommended for security reasons:

provider "aws" {
  region     = "us-east-1"
  access_key = "some-access-key"
  secret_key = "some-secret-key"
}

Here’s another useful doc on authenticating the AWS “provider” with terraform: