This module handles the creation of VPC, EC2, ECR, and EKS resources on AWS using Terraform.
- AWS account
- AWS CLI installed and configured
- Terraform 1.9.3 installed
- VPC: The module provisions a VPC with the necessary subnets, gateway, and route tables.
- EC2: The module creates an EC2 instance.
- ECR: The module sets up an Elastic Container Registry.
- EKS: The module creates an Elastic Kubernetes Service cluster.
This module will create:
- A VPC with necessary subnets, gateway, nat gateway, and route tables
- EC2 instance
- ECR repository
- An EKS cluster
- 2 Worker Nodes.
- A Jenkins EC2 instance with:
- Docker
- AWS-CLI
- Kubectl
You can define variables in a terraform.tfvars file or at the CLI. Below are the expected variables:
region: AWS region (e.g., "ap-southeast-1")vpc_base_name: Basename for the VPCcidr_block: The CIDR block for the VPCavailability_zones: Availability zones for the subnetspublic_subnet_ips: IP ranges for the public subnetsprivate_subnet_ips: IP ranges for the private subnetsrepository_names: Names for the ECR repositoriesimage_tag_mutability: Tag mutability setting for the repositories (e.g., "MUTABLE" or "IMMUTABLE")enable_scan_on_push: Whether to scan images on push (true or false)instance_type: Type of instance (e.g., "t3.small")image_id: AWS AMI IDjenkins_keypair_path: Path to Jenkins key paireks_node_keypair_path: Path to EKS node key paircluster_name: EKS cluster namecluster_version: EKS cluster version (e.g., "1.30")endpoint_public_access: EKS endpoint public access (true or false)endpoint_private_access: EKS endpoint private access (true or false)managed_node_groups: A map of managed node groups
- Clone the repository:
git clone https://github.com/tuonglevan/sd2793_aws_infastructure.git
- Change directory to the cloned repository:
cd sd2793_aws_infastructure - Initialize Terraform:
terraform init
- Format and validate the Terraform code:
terraform fmt terraform validate
- Run Terraform apply to create the resources:
terraform apply -auto-approve --var-file "terraform.tfvars"
To destroy the infrastructure, run:
terraform destroy -auto-approve -var-file "terraform.tfvars"