This project is created as part of a sharing session to introduce Terraform.
The following instructions assume you are using macOS. If you are not using macOS, certain steps also come with alternate installations options. Otherwise, you can fallback on your on your experience and search_engine-fu.
The following instructions assumes you have little to no knowledge of Terraform and some experience with Amazon Web Service (AWS).
Follow instructions on the Homebrew homepage.
brew install asdf
asdf plugin-add terraform https://github.com/asdf-community/asdf-hashicorp.git
asdf install
Other installation options here.
(Optional) direnv
brew install direnv
And follow instructions to complete setup. We use this to configure AWS_ACCESS_KEY_ID
, AWS_SECRET_ACCESS_KEY
and AWS_DEFAULT_REGION
. This is optional and you can choose to configure via other methods such as AWS CLI.
- (Optional) Create your own
.envrc
. You can skip this step if you are not using direnv.
cp .envrc.template .envrc
-
You will require an AWS account that has permissions to create VPCs, subnets, RDS databases, S3 buckets and EC2 instances. Ensure you have an IAM account that has the necessary permissions to create and configure these services. If you are testing on a root account, I highly recommend you to create an IAM account for this purpose.
-
Generate an access key and update variables in
.envrc
. If you are not using direnv, setup accordingly. -
You may also want to log into AWS Console to observe the changes made by Terraform.
Initialize the working directory
terraform init
Review the changes that will be made.
terraform plan
Create resource on AWS
terraform apply
Do keep an eye on the output.
If you are experimenting with configurations, adding or removing resources. You will be using terraform plan
and terraform apply
repeatedly. You can also use terraform validate
for a quick and local validatation of your changes.
When you are done and wish to delete all resources
terraform destroy
If you no longer wish to run this Terraform project. You may want to consider:
- Deleting the AWS access key if it was generated only for the purpose of this project.