This Git repository contains Terraform code to deploy AWS infrastructure for different work environments, such as dev, prod, and stg. It includes resources like EC2 instances, S3 buckets, and other infrastructure components. This README provides an overview of the project and instructions for deploying and managing the infrastructure.
- Prerequisites
- Getting Started
- Project Structure
- Terraform Configuration
- Deployment
- Managing the Infrastructure
- Destroying the Infrastructure
- Contributing
- License
Before you begin, make sure you have the following prerequisites installed and configured:
- Terraform (v1.0.0 or later)
- AWS CLI configured with valid credentials and a default region
- Git (optional for cloning this repository)
- AWS IAM User or Role with permissions to create EC2 instances, S3 buckets, and appropriate permissions for Terraform
-
Clone this Git repository (if you haven't already):
git clone https://github.com/your-username/terraform-environment-infrastructure.git cd terraform-environment-infrastructure
-
Initialize the Terraform workspace:
terraform init
The project structure is organized as follows:
terraform-environment-infrastructure/
├── dev/
│ ├── my_bucket.tf # Terraform configuration for the dev environment
│ ├── my_server.tf
│ ├── my_table.tf
│ ├── variables.tf
│ └── ...
├── prod/
│ ├── my_bucket.tf # Terraform configuration for the prod environment
│ ├── my_server.tf
│ ├── my_table.tf
│ ├── variables.tf
│ └── ...
├── stg/
│ ├── my_bucket.tf # Terraform configuration for the stg environment
│ ├── my_server.tf
│ ├── my_table.tf
│ ├── variables.tf
│ └── ...
├── .gitignore # Gitignore file to exclude sensitive information
├── README.md # This README file
├── backend_infra.tf # Terraform configuration for backend infrastructure
├── main.tf # Main Terraform configuration file (environment-specific modules)
├── providers.tf # Providers configuration file
├── terraform.tf # Terraform backend configuration
└── ...
The project includes environment-specific Terraform configuration files (my_bucket.tf
, my_server.tf
, my_table.tf
, etc.) within each environment directory (dev/
, prod/
, stg/
). These files define the infrastructure resources for each environment. You can customize these files as needed for your specific requirements.
The variables.tf
files in each environment can be used to specify environment-specific variables.
-
Navigate to the specific environment directory (e.g.,
dev/
,prod/
, orstg/
) where you want to deploy infrastructure. -
Create a
terraform.tfvars
file in the environment directory to specify any environment-specific variable values. -
Apply the Terraform configuration to create the infrastructure for the selected environment:
terraform apply
-
Confirm the changes and enter
yes
when prompted.
Repeat the deployment process for each environment as needed.
You can manage the infrastructure for each environment independently by navigating to the corresponding environment directory and using Terraform commands such as terraform plan
, terraform apply
, and terraform destroy
.
To destroy the infrastructure and resources created by Terraform for a specific environment, navigate to the corresponding environment directory and use the following command:
terraform destroy
Confirm the destruction of resources by entering yes
when prompted.
Thank you for using the Terraform AWS Environment Infrastructure project. If you have any questions or encounter any issues, please don't hesitate to reach out to the project maintainers.