Skip to content

Commit

Permalink
Added DDMC to AWS
Browse files Browse the repository at this point in the history
  • Loading branch information
bottkars committed Apr 8, 2024
1 parent d3749ad commit a770e10
Show file tree
Hide file tree
Showing 7 changed files with 293 additions and 0 deletions.
27 changes: 27 additions & 0 deletions terraforming-aws/ddmc_output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

output "ddmc_private_ip" {
value = var.ddmc_count > 0 ? module.ddmc[0].ddmc_private_ip_address : null
description = "The private ip address for the ddmc Instance"
}

output "ddmc_instance_id" {
value = var.ddmc_count > 0 ? module.ddmc[0].ddmc_instance_id : null
description = "The instance id (initial password) for the ddmc Instance"
sensitive = true
}
output "ddmc_ssh_private_key" {
sensitive = true
value = var.ddmc_count > 0 ? module.ddmc[0].ssh_private_key : null
description = "The ssh private key for the ddmc Instance"
}

output "ddmc_ssh_public_key_name" {
value = var.ddmc_count > 0 ? module.ddmc[0].ssh_public_key_name : null
description = "The ssh public key name for the ddmc Instance"
}

output "ddmc_ssh_public_key" {
value = var.ddmc_count > 0 ? module.ddmc[0].ssh_public_key : null
sensitive = true
description = "The ssh public key for the ddmc Instance"
}
39 changes: 39 additions & 0 deletions terraforming-aws/ddmc_variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
variable "ddmc_count" {
default = false
description = "Do you want to create a ddmc"
}

variable "DDMC_HOSTNAME" {
default = "ddmc_terraform"
description = "Hotname of the ddmc Machine"
}


variable "ddmc_version" {
type = string
default = "7.13.0.10"
description = "ddmc Version, can be: '7.13.0.10','7.10.1.20', '7.7.5.30'"
validation {
condition = anytrue([
var.ddmc_version == "7.13.0.10",
var.ddmc_version == "7.10.1.20",
var.ddmc_version == "7.7.5.30",
])
error_message = "Must be a valid ddmc Version, can be: '7.13.0.10','7.10.1.20', '7.7.5.30' ."
}
}



variable "ddmc_type" {
type = string
default = "12.5 Gigabit Ethernet ddmc"
description = "ddmc Type, can be: '12.5 Gigabit Ethernet ddmc', '10 Gigabit Ethernet ddmc'"
validation {
condition = anytrue([
var.ddmc_type == "12.5 Gigabit Ethernet ddmc",
var.ddmc_type == "10 Gigabit Ethernet ddmc",
])
error_message = "Must be a valid ddmc Type, can be: '12.5 Gigabit Ethernet ddmc', '10 Gigabit Ethernet ddmc'."
}
}
97 changes: 97 additions & 0 deletions terraforming-aws/modules/ddmc/ddmc.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
locals {
ddmc_size = {
"10 Gigabit Ethernet ddmc" = {
ddmc_metadata_volume_count = 2
instance_type = "m5.xlarge"
}
"12.5 Gigabit Ethernet ddmc" = {
ddmc_metadata_volume_count = 4
instance_type = "m6i.xlarge"
}


}
ddmc_name = "${var.ddmc_name}-${var.ddmc_instance}"
}

data "aws_ami" "ddmc" {
most_recent = true
include_deprecated = true
filter {
name = "name"
values = ["ddmc-${var.ddmc_version}*"]

}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["679593333241"]
}

resource "aws_instance" "ddmc" {
ami = data.aws_ami.ddmc.id
instance_type = local.ddmc_size[var.ddmc_type].instance_type
vpc_security_group_ids = ["${aws_security_group.ddmc_sg[0].id}", var.default_sg_id]
associate_public_ip_address = false
subnet_id = var.subnet_id
key_name = aws_key_pair.ddmc.key_name
tags = merge(
var.tags,
{ "Name" = local.ddmc_name
"environment" = var.environment },
)
root_block_device {
delete_on_termination = true
}
lifecycle {
# prevent_destroy = true
ignore_changes = [tags,tags_all,ami]
}
}

resource "aws_ebs_volume" "dbvolume" {
type = "gp2"
size = 200
availability_zone = var.availability_zone
tags = merge(
var.tags,
{ Name = "${var.ddmc_name}-dbvolume"
environment = var.environment
OwningInstance = local.ddmc_name
},
)

}


resource "aws_volume_attachment" "ebs_att_dbvolume" {
device_name = "/dev/sdb"
volume_id = aws_ebs_volume.dbvolume.id
instance_id = aws_instance.ddmc.id
stop_instance_before_detaching = true
skip_destroy = true
}

resource "aws_ebs_volume" "resvolume" {
type = "gp2"
size = 100
availability_zone = var.availability_zone
tags = merge(
var.tags,
{ Name = "${var.ddmc_name}-resvolume"
environment = var.environment
OwningInstance = local.ddmc_name
},
)

}


resource "aws_volume_attachment" "ebs_att_resvolume" {
device_name = "/dev/sdc"
volume_id = aws_ebs_volume.resvolume.id
instance_id = aws_instance.ddmc.id
stop_instance_before_detaching = true
skip_destroy = true
}
9 changes: 9 additions & 0 deletions terraforming-aws/modules/ddmc/keypair.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "aws_key_pair" "ddmc" {
key_name = "${var.environment}-ddmc-key-${var.ddmc_instance}"
public_key = tls_private_key.ddmc.public_key_openssh
}

resource "tls_private_key" "ddmc" {
algorithm = "RSA"
rsa_bits = "4096"
}
19 changes: 19 additions & 0 deletions terraforming-aws/modules/ddmc/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
output "ddmc_private_ip_address" {
value = "${aws_instance.ddmc.private_ip}"
}


output "ddmc_instance_id" {
value = "${aws_instance.ddmc.id}"
}
output "ssh_public_key_name" {
value = aws_key_pair.ddmc.key_name
}
output "ssh_public_key" {
sensitive = true
value = tls_private_key.ddmc.public_key_openssh
}
output "ssh_private_key" {
sensitive = true
value = tls_private_key.ddmc.private_key_pem
}
32 changes: 32 additions & 0 deletions terraforming-aws/modules/ddmc/sg.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
resource "aws_security_group" "ddmc_sg" {
count = var.is_crs ? 0 : 1
name = "ddmc_sg-${var.ddmc_instance}"
vpc_id = var.vpc_id
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = concat(var.ingress_cidr_blocks, var.private_subnets_cidr, var.public_subnets_cidr)
}
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = concat(var.ingress_cidr_blocks, var.private_subnets_cidr, var.public_subnets_cidr)
}

ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = concat(var.ingress_cidr_blocks, var.private_subnets_cidr)
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = [
"0.0.0.0/0"]
}
}
70 changes: 70 additions & 0 deletions terraforming-aws/modules/ddmc/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
variable "tags" {
description = "Key/value tags to assign to all resources."
default = {}
type = map(string)
}
variable "environment" {}
variable "vpc_id" {}
variable "region" {}

variable "availability_zone" {}
variable "ingress_cidr_blocks" {
type = list(any)
default = [""]
}
variable "subnet_id" {}
variable "public_subnets_cidr" {
type = list(any)
description = "cidr of the public subnets cidrs when creating the vpc"
}
variable "private_subnets_cidr" {
type = list(any)
description = "cidr of the private subnets cidrs when creating the vpc"
}
variable "default_sg_id" {}


variable "ddmc_type" {}
variable "ddmc_name" {
type = string
default = "ddmc_terraform"
}

variable "ddmc_instance" {
type = number
}
variable "ddmc_version" {
default = "7.10.0.0"
}
variable "is_crs" {
type = bool
default = false
}
variable "ec2_device_names" {
default = [
"/dev/sdc",
"/dev/sdd",
"/dev/sde",
"/dev/sdf",
"/dev/sdg",
"/dev/sdh",
"/dev/sdi",
"/dev/sdj",
"/dev/sdk",
"/dev/sdl",
"/dev/sdm",
"/dev/sdn",
"/dev/sdo",
"/dev/sdp",
"/dev/sdq",
"/dev/sdr",
"/dev/sds",
"/dev/sdt",
"/dev/sdu",
"/dev/sdv",
"/dev/sdw",
"/dev/sdx",
"/dev/sdy",
"/dev/sdz",
]
}

0 comments on commit a770e10

Please sign in to comment.