- An AWS account and a user with permission to create IAM users and access keys.
- Terraform installed locally.
- (Optional) AWS CLI installed for managed credential storage.
- Open the AWS Management Console

- Navigate to IAM

- Create a new IAM user for Terraform
- Click “Users” in the left navigation, then “Create user”.
- Give the user a name (for example,
terraform) — you can choose any naming convention you prefer. - Enable programmatic access so AWS generates an access key ID and secret access key for the user.

- Attach permissions (least privilege recommended)

AdministratorAccess only if you truly need full administrative scope). Limiting permissions to what Terraform requires is a best practice.


- Create an access key for programmatic access


- Example Terraform configuration
main.tf) in your working directory before running terraform plan:
By default the empty
provider "aws" {} block lets Terraform pick up credentials and the region from environment variables or the AWS shared credentials file. To set a region explicitly, add region = "us-east-1" inside the provider block (or configure required_providers if your Terraform workflow requires it).- Configure AWS credentials for Terraform
| Platform / Method | Command / File | Notes |
|---|---|---|
| macOS / Linux (bash, zsh) — session-only | bash export AWS_ACCESS_KEY_ID="AKIAEXAMPLEACCESSKEY" export AWS_SECRET_ACCESS_KEY="examplesecretKEY+chars" export AWS_DEFAULT_REGION="us-east-1" | Exports apply only to the current shell session. Persist in ~/.bashrc or ~/.zshrc if needed (beware security). |
| Windows PowerShell — session-only | powershell $Env:AWS_ACCESS_KEY_ID = "AKIAEXAMPLEACCESSKEY" $Env:AWS_SECRET_ACCESS_KEY = "examplesecretKEY+chars" $Env:AWS_DEFAULT_REGION = "us-east-1" | Session-only — values disappear when the shell closes. |
| AWS CLI (recommended for persistence) | Run aws configure and follow prompts (stores credentials in ~/.aws/credentials) | Cross-platform managed file — safer than repeatedly exporting keys in shells. See AWS CLI docs below. |
aws configure— then enter Access Key ID, Secret Access Key, default region, and output format when prompted.
- Verify Terraform and credentials
.tf files in the working directory, run Terraform commands:
terraform initto initialize providers.terraform planto see what Terraform intends to create.
terraform plan with no configuration files you will see the familiar message:
- Use the principle of least privilege when attaching IAM policies.
- Prefer short-lived credentials or managed profiles when possible.
- Rotate or delete access keys when they are no longer required.
After you finish using these credentials, delete the access key in the IAM console (or rotate it). Treat access keys like passwords and follow the principle of least privilege.
export on macOS/Linux, $Env: for Windows PowerShell, or the AWS CLI aws configure command for persistent credentials.