Why was this repository created? Well, using S3 as a Backend is somewhat tricky. You need to provide resources (such as S3 Buckets) first, before adding the S3 block backend "s3" {}
block. It is not good practice to manually create S2 Buckets since the AWS provision's life cycle should rely on Terraform State File. You will occasionally encounter errors when you do that. Like what you can see below:
Error: Error inspecting states in the "local" backend:
S3 bucket does not exist.
So what's this setup.sh can do is to create S3 Buckets and dynamoDB resources first and run the terraform provision again with the "S3" backend. Specifically, this repo solves the following:
- Avoiding S3 Bucket Common Errors
- Avoiding conflicts on deployments among developers using Terraform State Locking
- AWS profile and credentials checks
Before you get started, you need to have the following:
- Terraform CLI
- Git Bash
- AWS IAM account with
AdministratorAccess
priviledge - AWS Local Authentication
aws configure
I prefer not to talk about it here, so go over to their official Terraform Install documentation
When you're in your favorite CLI
terminal, type in
git clone https://github.com/esstat17/Terraform-S3-Backend-AWS-VPC-DynamoDB-Template.git
.. and you're good to go
- After you've downloaded this archive, navigate to the project folder using your CLI or Terminal command tool.
Change Directory to project folder and run the script
- Initializing the script, installing package dependencies, terraform plan and deployments
cd Terraform-S3-Backend-AWS-VPC-DynamoDB-Template/
To run the script
./setup.sh your-app-name
To undo all provisions
- Undo all commands above or revert them to the 0 state.
git checkout HEAD -- backend.tf && terraform init -migrate-state -force-copy && terraform destroy -auto-approve && echo "# edited" >> ./backend.tf
Just reach me if you need help.
Contributors names and contact info
- 0.1.0
- Initial Release
This project is licensed under the MIT License - see the LICENSE.md file for details
Inspiration, code snippets, etc.
Starting your Terraform project is made easy using this template.