This Terraform configuration sets up an AWS Virtual Private Cloud (VPC) with public and private subnets. It utilizes a module to manage VPC resources across different environments.
- main.tf: Defines the AWS provider and resources for creating the VPC and subnets.
- variables.tf: Defines input variables used in the configuration.
- dev-vpc.tf: Configuration for the development environment using the
tf-vpc
module. - prod-vpc.tf: Configuration for the production environment using the
tf-vpc
module. - outputs.tf: Defines output values to be displayed after Terraform applies the configuration.
-
Set up AWS Provider: Ensure you have AWS credentials configured either through environment variables or AWS CLI configuration.
-
Adjust Variables (if necessary): Modify
variables.tf
to customize CIDR blocks or other parameters as needed. -
Initialize Terraform: Run
terraform init
in the directory where these files are located to initialize Terraform and download necessary providers. -
Review Plan: Run
terraform plan
to see the execution plan and ensure it matches your expectations. -
Apply Changes: Run
terraform apply
to apply the configuration and create the AWS resources. -
Destroy Resources: If needed, run
terraform destroy
to destroy the created AWS resources.
- tf-vpc: A module located in the
../modules
directory is used to encapsulate the VPC creation logic. It accepts anenvironment
parameter to distinguish between environments (DEV, PROD).
- vpc-cidr-block: Outputs the CIDR block of the VPC created by the
tf-vpc
module.
- Ensure proper AWS IAM permissions are set for the AWS credentials used with Terraform.
- This configuration assumes AWS region
us-east-1
. Modifyprovider "aws"
block inmain.tf
to change the region if necessary.