Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ odinb
*.terraform.lock*
.terraform/
rippkgs*
**keys.json
16 changes: 16 additions & 0 deletions deployments/openTofu/AWS/ODIN_AWS/compute/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# data "aws_vpc" "vpc" {
# filter {
# name = "tag:Name"
# values = ["valnix-vpc-useast-1"]
# }
# }

# data "aws_subnet" "compute_subnet" {
# filter {
# name = "tag:Name"
# values = ["snet-compute-01"]
# }
# }
data "aws_iam_role" "spot-fleet" {
name = "AWSServiceRoleForEC2SpotFleet"
}
3 changes: 3 additions & 0 deletions deployments/openTofu/AWS/ODIN_AWS/compute/local.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
rds_endpoint = split(":", module.rds.rds_pip)[0]
}
235 changes: 235 additions & 0 deletions deployments/openTofu/AWS/ODIN_AWS/compute/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
module "vpc" {
source = "../../modules/vpc"

vpc_name = "valnix-vpc-useast-1"
vpc_address_block = "10.0.0.0/16"
}

module "compute_subnet" {
source = "../../modules/vpc/subnet"

subnet_name = "snet-compute-01"
vpc_id = module.vpc.vpc_id
snet_availability_zone = var.snet_availability_zone1
snet_cidr = "10.0.0.0/24"
map_public_ip_on_launch = true
}

module "db_subnet01" {
source = "../../modules/vpc/subnet"

subnet_name = "snet-db-01"
vpc_id = module.vpc.vpc_id
snet_availability_zone = var.snet_availability_zone1
snet_cidr = "10.0.1.0/24"
map_public_ip_on_launch = true
}

module "db_subnet02" {
source = "../../modules/vpc/subnet"

subnet_name = "snet-db-02"
vpc_id = module.vpc.vpc_id
snet_availability_zone = var.snet_availability_zone2
snet_cidr = "10.0.2.0/24"
map_public_ip_on_launch = true
}

module "internet_gateway" {
source = "../../modules/vpc/internetGateway"

vpc_id = module.vpc.vpc_id
}

module "compute_route_table" {
source = "../../modules/vpc/routeTable"

route_table = "compute-route-01"
vpc_id = module.vpc.vpc_id
subnet_id = module.compute_subnet.subnet_id
internet_gateway_id = module.internet_gateway.internet_gateway_id
}

module "db_route_table01" {
source = "../../modules/vpc/routeTable"

route_table = "db-route-01"
vpc_id = module.vpc.vpc_id
subnet_id = module.db_subnet01.subnet_id
internet_gateway_id = module.internet_gateway.internet_gateway_id
}

module "db_route_table02" {
source = "../../modules/vpc/routeTable"

route_table = "db-route-02"
vpc_id = module.vpc.vpc_id
subnet_id = module.db_subnet02.subnet_id
internet_gateway_id = module.internet_gateway.internet_gateway_id
}

module "ssh_security_group" {
source = "../../modules/vpc/securityGroups"

security_grp_name = "SSH_Inbound"
vpc_id = module.vpc.vpc_id
ingress_rules = [
{
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
},
{

from_port = 2049
to_port = 2049
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
},
{

from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
,
{

from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
]
}

# resource "aws_network_interface" "my_network_interface" {
# subnet_id = module.subnet.subnet_id
# private_ips = ["10.0.1.10"]

module "key_Pair" {
source = "../../modules/keyPair"

key_pair_name = var.key_pair_name
}

module "ec2" {
source = "../../modules/ec2"
deploy = true

instance_type = var.ec2_instance_type
ami = "ami-0866a3c8686eaeeba"
security_group_ids = [module.ssh_security_group.sg_id]
subnet_id = module.compute_subnet.subnet_id
# nic_id = aws_network_interface.my_network_interface.id
key_pair_name = module.key_Pair.aws_key_pair_name
associate_pip = true
}

module "ebs" {
source = "../../modules/ebs"

ebs_name = "shared_nix_store"
ebs_size = var.ebs_size
ec2_availability_zone = module.ec2.ec2_availability_zone
multi_attach_enabled = var.multi_attach_enabled
ebs_type = var.ebs_type
ebs_iops = var.ebs_iops
snapshot_id = var.shared_nix_store_id #"snap-0daa1ed513204e62f"
}

module "ec2_spot_fleet" {
source = "../../modules/ec2SpotFleet"

aws_arn = data.aws_iam_role.spot-fleet.arn
ami_id = "ami-0866a3c8686eaeeba"
instance_types = ["m6a.xlarge", "m5.xlarge", "m7a.xlarge", "m5a.xlarge", "m6i.xlarge", "m6id.xlarge"]
key_Pair = module.key_Pair.aws_key_pair_name
subnet_id = module.compute_subnet.subnet_id
availability_zone = module.ebs.ebs_availability_zone #data.aws_subnet.compute_subnet.availability_zone
associate_pip = true
security_group_ids = [module.ssh_security_group.sg_id]

}

# module "server_ebs_vol_attach" {
# source = "../../modules/ebs/ebs_volume_attach"

# ec2_id = module.ec2_spot_fleet.spot_fleet_id
# volume_id = module.ebs.ebs_id
# depends_on = [module.ec2_spot_fleet]
# }


module "db_security_group" {
source = "../../modules/vpc/securityGroups"

security_grp_name = "DB_Inbound"
vpc_id = module.vpc.vpc_id
ingress_rules = [
{
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
},
{

from_port = 2049
to_port = 2049
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
},
{

from_port = 5432
to_port = 5432
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
]
}

module "random_password" {
source = "../../modules/randomPassword"
deploy = true
pwd_include_lower = true
pwd_include_number = true
pwd_include_upper = true
pwd_length = 15
pwd_special = false
}
module "rds" {
source = "../../modules/rds"

db_instance_name = "odinstagingserver"
rds_engine = "postgres"
engine_version = "16.3"
db_compute_instance = var.rds_compute_type
skip_create_final_snapshot = true
db_name = "odinstagingdb"
db_password = module.random_password.password
db_username = "odinstagingowner"
subnet_ids = [module.db_subnet01.subnet_id, module.db_subnet02.subnet_id]
security_group_ids = [module.db_security_group.sg_id]
multi_availability_zones = false
allocated_storage = 10

db_subnet_group_name = "valnix-rds-subnet-group"
}

module "odin_secret" {
source = "../../modules/secret"

secret_name = "odin-worker-secrets-3"
secret_value = {
POSTGRES_USER = "odinstagingowner"
POSTGRES_DB = "odinstagingdb"
POSTGRES_PASSWORD = module.rds.rds_password
POSTGRES_PORT = "5432"
POSTGRES_HOST = local.rds_endpoint
}

}
12 changes: 12 additions & 0 deletions deployments/openTofu/AWS/ODIN_AWS/compute/odin.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
location = "us-east-1"
snet_availability_zone1 = "us-east-1a"
snet_availability_zone2 = "us-east-1b"
key_pair_name = "ec2_key_pair"

ebs_size = 80
multi_attach_enabled = false
ebs_iops = 5000
ebs_type = "gp3"

ec2_instance_type = "t3.small"
rds_compute_type = "db.t3.micro"
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
terraform {
backend "s3" {
bucket = "valnix-terraform-state-bucket"
key = "AWS_Readiness/compute/compute01.tfstate"
region = "us-east-1"
dynamodb_table = "tf-backend"
encrypt = true
}
# backend "s3" {}
# bucket = "valnix-terraform-state-bucket"
# key = "AWS_Readiness/compute/compute01.tfstate"
# region = "us-east-1"
# dynamodb_table = "tf-backend"
# encrypt = true
# }

required_providers {
aws = {
Expand All @@ -25,7 +25,4 @@ provider "aws" {
region = var.location
access_key = ""
secret_key = ""
# assume_role {
# role_arn = "arn:aws:iam::775188627313:user/manoj_ha"
# }
}
38 changes: 38 additions & 0 deletions deployments/openTofu/AWS/ODIN_AWS/compute/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
variable "location" {
type = string
}
variable "snet_availability_zone1" {
type = string
}
variable "snet_availability_zone2" {
type = string
}
# variable "security_groups" {
# type = list(string)
# }
variable "key_pair_name" {
type = string
}
variable "ebs_size" {
type = number
default = 80
}
variable "multi_attach_enabled" {
type = bool
}
variable "ebs_type" {
type = string
}
variable "ebs_iops" {
type = number
}
variable "shared_nix_store_id" {
type = string
default = ""
}
variable "ec2_instance_type" {
type = string
}
variable "rds_compute_type" {
type = string
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ resource "aws_ebs_volume" "ebs" {
multi_attach_enabled = var.multi_attach_enabled
type = var.ebs_type
iops = var.ebs_iops
snapshot_id = ""#var.snapshot_id

tags = {
Name = var.ebs_name
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ variable "ebs_type" {
}
variable "ebs_iops" {
type = number
}
variable "snapshot_id" {

}
variable "ebs_name" {

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource "aws_instance" "ec2" {

count = var.deploy == false ? 1 : 0
count = var.deploy == true ? 1 : 0
ami = var.ami
instance_type = var.instance_type
vpc_security_group_ids = var.security_group_ids
Expand All @@ -12,4 +12,7 @@ resource "aws_instance" "ec2" {
# }
key_name = var.key_pair_name
associate_public_ip_address = var.associate_pip
tags = {
Name = "odin-server"
}
}
9 changes: 9 additions & 0 deletions deployments/openTofu/AWS/modules/ec2/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "ec2_public_ip" {
value = var.deploy == true ? aws_instance.ec2[0].public_ip : 0
}
output "ec2_id" {
value = var.deploy == true ? aws_instance.ec2[0].id : 0
}
output "ec2_availability_zone" {
value = aws_instance.ec2[0].availability_zone
}
Loading