Created
May 22, 2023 07:07
-
-
Save naveenrajm7/99af4e6e24f2b8acacd95d00ce801076 to your computer and use it in GitHub Desktop.
Microshift in AWS
This file contains 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
terraform { | |
required_providers { | |
aws = { | |
source = "hashicorp/aws" | |
version = "~> 4.16" | |
} | |
} | |
required_version = ">= 1.2.0" | |
} | |
provider "aws" { | |
region = var.aws_region | |
} | |
resource "aws_vpc" "exp_vpc" { | |
cidr_block = var.vpc_cidr_block | |
tags = { | |
Name = "microshift-vpc" | |
} | |
} | |
resource "aws_subnet" "exp_public_subnet" { | |
vpc_id = aws_vpc.exp_vpc.id | |
cidr_block = var.public_subnet | |
availability_zone = var.aws_az | |
tags = { | |
Name = "microshift-public-subnet" | |
} | |
} | |
resource "aws_internet_gateway" "exp_ig" { | |
vpc_id = aws_vpc.exp_vpc.id | |
tags = { | |
Name = "exp-internet-gateway" | |
} | |
} | |
resource "aws_route_table" "exp_public_rt" { | |
vpc_id = aws_vpc.exp_vpc.id | |
route { | |
cidr_block = "0.0.0.0/0" | |
gateway_id = aws_internet_gateway.exp_ig.id | |
} | |
route { | |
ipv6_cidr_block = "::/0" | |
gateway_id = aws_internet_gateway.exp_ig.id | |
} | |
tags = { | |
Name = "exp-public-route-table" | |
} | |
} | |
resource "aws_route_table_association" "exp_public_1_rt_a" { | |
subnet_id = aws_subnet.exp_public_subnet.id | |
route_table_id = aws_route_table.exp_public_rt.id | |
} | |
resource "aws_security_group" "exp_sg" { | |
name = "PING and SSH" | |
vpc_id = aws_vpc.exp_vpc.id | |
ingress { | |
description = "Ping" | |
from_port = 8 # Echo request | |
to_port = 0 | |
protocol = "icmp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
ingress { | |
description = "SSH" | |
from_port = 22 | |
to_port = 22 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
ingress { | |
description = "For security group" | |
from_port = 0 | |
to_port = 0 | |
protocol = -1 | |
self = true | |
} | |
egress { | |
description = "Allow all outgoing traffic" | |
from_port = 0 | |
to_port = 0 | |
protocol = -1 | |
cidr_blocks = ["0.0.0.0/0"] | |
ipv6_cidr_blocks = ["::/0"] | |
} | |
} | |
resource "aws_instance" "edge_node" { | |
instance_type = var.instance_type | |
ami = var.instance_ami | |
vpc_security_group_ids = [aws_security_group.exp_sg.id] | |
subnet_id = aws_subnet.exp_public_subnet.id | |
private_ip = "198.18.60.10" | |
key_name = var.instance_key | |
associate_public_ip_address = true | |
ebs_block_device { | |
device_name = "/dev/sdm" | |
volume_size = 10 | |
} | |
tags = { | |
Name = "edge-node" | |
} | |
} |
This file contains 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
output "instance_id" { | |
description = "ID of the EC2 instance" | |
value = aws_instance.edge_node.id | |
} | |
output "edge_public_ip" { | |
description = "Public IP address of Edge instance" | |
value = aws_instance.edge_node.public_ip | |
} |
This file contains 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
variable "aws_region" { | |
description = "AWS Region" | |
type = string | |
default = "us-east-1" | |
} | |
variable "aws_az" { | |
description = "Availability zone" | |
type = string | |
default = "us-east-1a" | |
} | |
variable "vpc_cidr_block" { | |
description = "VPC CIDR" | |
type = string | |
default = "198.18.0.0/16" # RFC 2544, aws /15 not allowed | |
} | |
variable "public_subnet" { | |
type = string | |
default = "198.18.60.0/24" | |
} | |
variable "instance_key" { | |
description = "Key pair" | |
type = string | |
default = "micro" | |
} | |
variable "instance_type" { | |
description = "EC2 Instance type" | |
type = string | |
default = "t3.small" # (Edge Device) | |
} | |
variable "instance_ami" { | |
type = string | |
description = "The id of the machine image (AMI) to use for the server." | |
default = "ami-08900fdabfe86d539" # "ami-08900fdabfe86d539" (RHEL 8.7), "ami-016eb5d644c333ccb" (RHEL 9.0) [us east 1] | |
validation { | |
condition = length(var.instance_ami) > 4 && substr(var.instance_ami, 0, 4) == "ami-" | |
error_message = "The image_id value must be a valid AMI id, starting with \"ami-\"." | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment