Terraform AWS provisioning examples for beginners
If you are planning to use this Terraform repo for learning, please hit the star. Thanks!
terraform init \
-backend-config="key=dev/vpc.tfstate" \
-backend-config="bucket=dcube-terraform-state" \
-backend-config="region=us-west-2" \
-backend-config="dynamodb_table=terraform-state-lock" \
-var-file=../../../vars/dev/vpc.tfvars
cd into the environments/dev/vpc
directory and run the following commands:
- Init Terraform in the directory
environments/dev/vpc
terraform init
- To preview the changes in code
terraform plan -var-file=../../../vars/dev/vpc.tfvars
- To apply the changes
terraform apply -var-file=../../../vars/dev/vpc.tfvars
- To destroy the resources created using the code
terraform destroy -var-file=../../../vars/dev/vpc.tfvars
#### RDS Provisioning
cd into the `environments/dev/rds` directory and run the following commands:
1. Init Terraform in the directory `environments/dev/rds`
terraform init
2. To preview the changes in code
terraform plan -var-file=../../../vars/dev/rds.tfvars
3. To apply the changes
terraform apply -var-file=../../../vars/dev/rds.tfvars
4. To destroy the resources created using the code
terraform destroy -var-file=../../../vars/dev/rds.tfvars
### ALB and ASG Provisioning
cd into the `environments/dev/alb-asg` directory and run the following commands:
1. Init Terraform in the directory `environments/dev/alb-asg`
terraform init
2. To preview the changes in code
terraform plan -var-file=../../../vars/dev/alb-asg.tfvars
3. To apply the changes
terraform apply -var-file=../../../vars/dev/alb-asg.tfvars
4. To destroy the resources created using the code
terraform destroy -var-file=../../../vars/dev/alb-asg.tfvars
## EC2 Instance Provisioning
1. Navigate to the `environment/dev` folder:
```bash
cd environment/dev
- Open the
ec2.tfvars
file and modify it with your desired details. This file contains variables used in the Terraform configuration.
- Initialize Terraform in the working directory:
terraform init
- Create an execution plan:
terraform plan -var-file=../../../vars/dev/ec2.tfvars
- Apply the changes to create the EC2 instance:
terraform apply -var-file=../../../vars/dev/ec2.tfvars
- To destroy the EC2 instance and associated resources:
terraform destroy -var-file=../../../vars/dev/ec2.tfvars
Note: Always review the execution plan (terraform plan
) before applying changes to avoid unintended modifications.
- Navigate to the
environment/dev
folder:
cd environment/tag-policy
- Open the
tag-policy.tfvars
file and modify it with your desired details. This file contains variables used in the Terraform configuration.
- Initialize Terraform in the working directory:
terraform init
- Create an execution plan:
terraform plan -var-file=../../../vars/dev/tag-policy.tfvars
- Apply the changes to create the Tag Policy:
terraform apply -var-file=../../../vars/dev/tag-policy.tfvars
- To destroy the Tag Policy:
terraform destroy -var-file=../../../vars/dev/tag-policy.tfvars
Note: Always review the execution plan (terraform plan
) before applying changes to avoid unintended modifications.
Update all outputs:
terraform refresh
Show all outputs:
terraform show