Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wup #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

wup #11

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
46 changes: 46 additions & 0 deletions qpizza-tf/bastion/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
resource "tls_private_key" "that" {
algorithm = "RSA"
rsa_bits = 4096
}

resource "aws_key_pair" "that" {
key_name = var.key_name
public_key = tls_private_key.that.public_key_openssh
}

resource "aws_security_group" "bastion_sg" {
description = "Security group for Bastion"
vpc_id = var.vpc_id

ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}

data "aws_ssm_parameter" "ami_id" {
name = "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-arm64"
}


resource "aws_instance" "bastion" {
ami = data.aws_ssm_parameter.ami_id.value
instance_type = var.bastion_instance_type
subnet_id = var.subnet_id
vpc_security_group_ids = [aws_security_group.bastion_sg.id]
key_name = aws_key_pair.that.key_name
user_data = <<EOF
#!/bin/bash
yum -y install mariadb105
EOF
}

Empty file added qpizza-tf/bastion/outputs.tf
Empty file.
17 changes: 17 additions & 0 deletions qpizza-tf/bastion/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
variable "vpc_id" {
type = string
}

variable "subnet_id" {
type = string
}

variable "key_name" {
type = string
default = "tfkeypair"
}

variable "bastion_instance_type" {
type = string
default = "t4g.micro"
}
59 changes: 59 additions & 0 deletions qpizza-tf/database/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
resource "aws_security_group" "aurora_sg" {
description = "Security group for RDS"
vpc_id = var.vpc_id
ingress {
from_port = 3306
to_port = 3306
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}

resource "aws_db_subnet_group" "that" {
subnet_ids = var.subnet_ids
description = "Subnet group for RDS"
}

#TODO: Prefix the parameter names with the environment name
data "aws_ssm_parameter" "master_username" {
name = "master_username"
}

data "aws_ssm_parameter" "master_password" {
name = "master_password"
}

resource "aws_rds_cluster" "aurora_cluster" {
engine = "aurora-mysql"
engine_mode = "provisioned"
engine_version = "8.0"

db_subnet_group_name = aws_db_subnet_group.that.name
master_username = data.aws_ssm_parameter.master_username.value
master_password = data.aws_ssm_parameter.master_password.value
backup_retention_period = 7
preferred_backup_window = "07:00-09:00"
vpc_security_group_ids = [aws_security_group.aurora_sg.id]
storage_encrypted = true
skip_final_snapshot = true
enable_http_endpoint = true

serverlessv2_scaling_configuration {
min_capacity = 0.5
max_capacity = 8
}
}

resource "aws_rds_cluster_instance" "cluster_instances" {
cluster_identifier = aws_rds_cluster.aurora_cluster.id
instance_class = "db.serverless"
engine = aws_rds_cluster.aurora_cluster.engine
engine_version = aws_rds_cluster.aurora_cluster.engine_version
}
3 changes: 3 additions & 0 deletions qpizza-tf/database/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "aurora_sg_id" {
value = aws_security_group.aurora_sg.id
}
8 changes: 8 additions & 0 deletions qpizza-tf/database/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
variable vpc_id {
type = string
}

variable subnet_ids {
type = list(string)
}

20 changes: 18 additions & 2 deletions qpizza-tf/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ provider "aws" {
}

module "networking" {
source = "./networking"
aws_region = var.aws_region
source = "./networking"
}

module "secrets" {
source = "./secrets"
}

module "database" {
source = "./database"
depends_on = [ module.networking, module.secrets ]
vpc_id = module.networking.vpc_id
subnet_ids = module.networking.private_subnet_ids
}

module "bastion" {
source = "./bastion"
vpc_id = module.networking.vpc_id
subnet_id = module.networking.public_subnet_ids[0]
}
3 changes: 0 additions & 3 deletions qpizza-tf/networking/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
variable "aws_region" {
default = "us-west-2"
}
6 changes: 5 additions & 1 deletion qpizza-tf/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ output "private_subnet_ids" {

output "public_subnet_ids" {
value = module.networking.public_subnet_ids
}
}

output "aurora_sg_id" {
value = module.database.aurora_sg_id
}
11 changes: 11 additions & 0 deletions qpizza-tf/secrets/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "aws_ssm_parameter" "master_username" {
name = "master_username"
type = "String"
value = var.master_username
}

resource "aws_ssm_parameter" "master_password" {
name = "master_password"
type = "String"
value = (var.master_password != "" ? var.master_password : uuid())
}
Empty file added qpizza-tf/secrets/outputs.tf
Empty file.
9 changes: 9 additions & 0 deletions qpizza-tf/secrets/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "master_username" {
type = string
default = "admin"
}

variable "master_password" {
type = string
default = ""
}
2 changes: 1 addition & 1 deletion qpizza-tf/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
variable "aws_region" {
default = "us-west-2"
default = "us-east-1"
}