Created
March 19, 2024 08:20
-
-
Save NotHarshhaa/b65e9b4c10078f0c3e2eb69ae77eb25d to your computer and use it in GitHub Desktop.
Create a VPC, an EKS cluster, and a bastion host in AWS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# main.tf | |
# Provider configuration for AWS | |
provider "aws" { | |
region = "us-west-2" # Change to your desired AWS region | |
} | |
# Create a VPC | |
resource "aws_vpc" "my_vpc" { | |
cidr_block = "10.0.0.0/16" | |
enable_dns_support = true | |
enable_dns_hostnames = true | |
} | |
# Create a public subnet | |
resource "aws_subnet" "public_subnet" { | |
vpc_id = aws_vpc.my_vpc.id | |
cidr_block = "10.0.1.0/24" | |
availability_zone = "us-west-2a" # Change to your desired AZ | |
map_public_ip_on_launch = true | |
} | |
# Create an EKS cluster | |
module "eks_cluster" { | |
source = "terraform-aws-modules/eks/aws" | |
cluster_name = "my-cluster" | |
cluster_version = "1.21" | |
subnets = [aws_subnet.public_subnet.id] | |
vpc_id = aws_vpc.my_vpc.id | |
node_group_name = "my-node-group" | |
node_group_instance_type = "t2.micro" | |
node_group_desired_capacity = 2 | |
} | |
# Create a security group for bastion host | |
resource "aws_security_group" "bastion_sg" { | |
name = "bastion_sg" | |
description = "Allow SSH access to bastion host" | |
vpc_id = aws_vpc.my_vpc.id | |
ingress { | |
from_port = 22 | |
to_port = 22 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
} | |
# Create a key pair for bastion host | |
resource "aws_key_pair" "bastion_key_pair" { | |
key_name = "bastion_key" | |
public_key = file("~/.ssh/id_rsa.pub") # Replace with your public key path | |
} | |
# Create a bastion host | |
resource "aws_instance" "bastion_host" { | |
ami = "ami-12345678" # Replace with your desired AMI | |
instance_type = "t2.micro" | |
subnet_id = aws_subnet.public_subnet.id | |
key_name = aws_key_pair.bastion_key_pair.key_name | |
security_groups = [aws_security_group.bastion_sg.id] | |
tags = { | |
Name = "bastion-host" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment