Skip to content

Commit 09fdb84

Browse files
committed
feat: dynamodb and other db resources
1 parent 0c4cda7 commit 09fdb84

14 files changed

+293
-154
lines changed

.github/workflows/pull-request.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ on:
44
pull_request:
55
branches:
66
- main
7-
paths-ignore:
8-
- "**/README.md"
97
workflow_dispatch:
108

119
jobs:

.terraform.lock.hcl

Lines changed: 31 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datasources.tf

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
data "aws_vpc" "vpc" {
2-
filter {
3-
name = "tag:Name"
4-
values = [var.vpc_name]
5-
}
6-
}
1+
# AWS Academy Vocareum AWS Learner Lab
2+
# data "aws_iam_role" "lab_role" {
3+
# name = "LabRole"
4+
# }
75

8-
data "aws_subnets" "private_subnets" {
9-
filter {
10-
name = "tag:Name"
11-
values = ["soat-tech-challenge-subnet-public*"]
12-
}
6+
data "tfe_outputs" "network" {
7+
organization = "soat-tech-challenge"
8+
workspace = "network-staging"
139
}
14-
15-
16-
# data "tfe_outputs" "network" {
17-
# organization = "soat-tech-challenge"
18-
# workspace = "network-staging"
19-
# }

dynamodb.tf

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
resource "aws_dynamodb_table" "identification_svc_clients_table" {
2+
name = "clients"
3+
billing_mode = "PROVISIONED"
4+
5+
hash_key = "id" // Partition key
6+
7+
read_capacity = "5"
8+
write_capacity = "5"
9+
10+
attribute {
11+
name = "id"
12+
type = "S" // Auto-generated UUIDs
13+
}
14+
15+
tags = {
16+
Name : "SOAT-TC DynamoDB Identification Service Clients Table"
17+
}
18+
}
19+
20+
module "identification_svc_clients_table_autoscaling" {
21+
source = "snowplow-devops/dynamodb-autoscaling/aws"
22+
version = "~> 0.2.1"
23+
table_name = aws_dynamodb_table.identification_svc_clients_table.name
24+
}
25+
26+
resource "aws_dynamodb_table" "production_svc_status_table" {
27+
name = "status"
28+
billing_mode = "PROVISIONED"
29+
30+
hash_key = "id" // Partition key
31+
32+
read_capacity = "5"
33+
write_capacity = "5"
34+
35+
attribute {
36+
name = "id"
37+
type = "S" // Auto-generated UUIDs
38+
}
39+
40+
tags = {
41+
Name : "SOAT-TC DynamoDB Production Service Status Table"
42+
}
43+
}
44+
45+
module "production_svc_status_table_autoscaling" {
46+
source = "snowplow-devops/dynamodb-autoscaling/aws"
47+
version = "~> 0.2.1"
48+
table_name = aws_dynamodb_table.production_svc_status_table.name
49+
}

dynamodb_outputs.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

main.tf

Lines changed: 0 additions & 38 deletions
This file was deleted.

network.tf

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
1-
resource "aws_security_group" "this" {
2-
name = "soat-tc-rds-sg"
3-
vpc_id = data.aws_vpc.vpc.id
1+
resource "aws_security_group" "order_svc_rds_db_sg" {
2+
name = "SOAT-TC RDS Order Service DB Security Group"
3+
vpc_id = data.tfe_outputs.network.values.vpc_vpc.id
44

55
ingress {
6-
from_port = var.db_port
7-
to_port = var.db_port
6+
from_port = var.order_svc_db_port
7+
to_port = var.order_svc_db_port
88
protocol = "tcp"
99
cidr_blocks = ["0.0.0.0/0"]
1010
}
1111

12-
tags = {
13-
Name = "Backend DB Security Group",
12+
}
13+
14+
resource "aws_security_group" "payment_svc_rds_db_sg" {
15+
name = "SOAT-TC RDS Payment Service DB Security Group"
16+
vpc_id = data.tfe_outputs.network.values.vpc_vpc.id
17+
18+
ingress {
19+
from_port = var.payment_svc_db_port
20+
to_port = var.payment_svc_db_port
21+
protocol = "tcp"
22+
cidr_blocks = ["0.0.0.0/0"]
1423
}
1524
}
1625

17-
resource "aws_db_subnet_group" "this" {
18-
name = "soat-tc-rds-subnet-group"
19-
subnet_ids = data.aws_subnets.private_subnets.ids
26+
resource "aws_db_subnet_group" "main" {
27+
name = "soat-tc-rds-public-subnets-subnet-group"
28+
subnet_ids = data.tfe_outputs.network.values.vpc_public_subnets[*].id
29+
30+
tags = {
31+
Name : "SOAT-TC RDS Public Subnets Subnet Group"
32+
}
2033
}
34+

outputs.tf

Lines changed: 0 additions & 4 deletions
This file was deleted.

providers.tf

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
1+
terraform {
2+
required_version = ">= 0.12.26"
3+
4+
cloud {
5+
organization = "soat-tech-challenge"
6+
7+
workspaces {
8+
name = "database-staging"
9+
}
10+
}
11+
12+
required_providers {
13+
aws = {
14+
source = "hashicorp/aws"
15+
version = "5.34.0"
16+
}
17+
18+
tfe = {
19+
source = "hashicorp/tfe"
20+
version = "~> 0.51.1"
21+
}
22+
}
23+
}
24+
125
provider "aws" {
226
region = var.aws_region
327

428
access_key = var.aws_access_key
529
secret_key = var.aws_secret_key
30+
token = var.aws_session_token
631

732
default_tags {
833
tags = {
934
Organization = "soat-tech-challenge"
1035
Workspace = "database-staging"
11-
Exemplo = "apresentacao"
1236
}
1337
}
1438
}

rds.tf

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
resource "aws_db_parameter_group" "main" {
2+
name = "soat-tc-psql-pg"
3+
description = "SOAT Tech Challenge RDS Parameter Group for PostgreSQL"
4+
family = "postgres15"
5+
6+
parameter {
7+
name = "log_connections"
8+
value = "1"
9+
}
10+
11+
tags = {
12+
Name : "SOAT-TC RDS PostgreSQL Parameter Group"
13+
}
14+
}
15+
16+
resource "aws_db_instance" "order_svc_db" {
17+
identifier = "soat-tc-rds-order-svc-db"
18+
engine = "postgres"
19+
20+
db_name = var.order_svc_db_name
21+
22+
allocated_storage = 20
23+
storage_type = "gp2"
24+
engine_version = "15.4"
25+
instance_class = "db.t3.micro"
26+
27+
username = var.order_svc_db_username
28+
password = var.order_svc_db_password
29+
port = var.order_svc_db_port
30+
31+
skip_final_snapshot = true
32+
publicly_accessible = true # For presentation purposes
33+
deletion_protection = false
34+
ca_cert_identifier = "rds-ca-rsa2048-g1"
35+
apply_immediately = true
36+
37+
parameter_group_name = aws_db_parameter_group.main.name
38+
db_subnet_group_name = aws_db_subnet_group.main.name
39+
40+
vpc_security_group_ids = [aws_security_group.order_svc_rds_db_sg.id]
41+
42+
# monitoring_interval = 15
43+
# monitoring_role_arn = data.aws_iam_role.lab_role.arn
44+
}
45+
46+
resource "aws_db_instance" "payment_svc_db" {
47+
identifier = "soat-tc-rds-payment-svc-db"
48+
engine = "postgres"
49+
50+
db_name = var.payment_svc_db_name
51+
52+
allocated_storage = 20
53+
storage_type = "gp2"
54+
engine_version = "15.4"
55+
instance_class = "db.t3.micro"
56+
57+
username = var.payment_svc_db_username
58+
password = var.payment_svc_db_password
59+
port = var.payment_svc_db_port
60+
61+
skip_final_snapshot = true
62+
publicly_accessible = true # For presentation purposes
63+
deletion_protection = false
64+
ca_cert_identifier = "rds-ca-rsa2048-g1"
65+
apply_immediately = true
66+
67+
parameter_group_name = aws_db_parameter_group.main.name
68+
db_subnet_group_name = aws_db_subnet_group.main.name
69+
70+
vpc_security_group_ids = [aws_security_group.payment_svc_rds_db_sg.id]
71+
72+
# monitoring_interval = 15
73+
# monitoring_role_arn = data.aws_iam_role.lab_role.arn
74+
}

0 commit comments

Comments
 (0)