Terraform 403: Access Denied Error
An easy fix for a common error when using Terraform to deploy resources using the CLI.
I was recently helping a colleague troubleshoot an issue with a new AWS environment he was provisioning. We’re using Terraform to manage the infrastructure through code and our CI/CD pipeline. The issue came when we were trying to provision new S3 buckets using Terraform files from our local machine. By running terraform init
we would eventually receive a 403: Access Denied
error back from AWS.
The error/issue was due to a mismatch with the local Terraform state and our new Terraform file. During our testing we had created and deleted several S3 buckets. The local Terraform state was still looking for an old S3 bucket, causing a mismatch.
To resolve, we deleted the .tfstate file from our local directory and everything worked as expected.
rm ~/.terraform/terraform.tfstate