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

add RDS #4241

Closed
wants to merge 36 commits into from
Closed

add RDS #4241

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3f911aa
add RDS
Dec 5, 2023
26b07c1
remove app name locals
Dec 5, 2023
6d21f1a
remove comma app_vars
Dec 5, 2023
f41583d
revise db_name
Dec 5, 2023
d9c205d
remove extra identifier
Dec 5, 2023
b3963a5
remove name argument
Dec 5, 2023
48b8d24
fix database.tf
Dec 7, 2023
30d22de
add s3 access for RDS
Dec 8, 2023
e82f75e
Merge branch 'main' into add_rds
roncitrus Dec 8, 2023
b69287e
Rename hosts (#4271)
pavmoj Dec 8, 2023
8279a02
NIT-981 deploy Oracle backup vault to all envs
Dec 8, 2023
bda9ff2
add s3 access for RDS
Dec 8, 2023
3225341
Pick up correct database type
ranbeersingh1 Dec 8, 2023
b216ce0
Merge pull request #4272 from ministryofjustice/NIT-981-delius-db-cre…
andrewmooreio Dec 8, 2023
a21d369
removed s3 info from rds instance
Dec 8, 2023
e5064a4
fixed typo
Dec 8, 2023
29da388
allow moj vpn access to rds (#4267)
matthewsearle01 Dec 8, 2023
e354de6
Pick up correct database type
ranbeersingh1 Dec 8, 2023
7af1d61
DSOS-2430: create dev oem (#4273)
drobinson-moj Dec 8, 2023
8486983
fixed typo
Dec 8, 2023
89095c2
Merge pull request #4274 from ministryofjustice/DBA-584
ranbeersingh1 Dec 8, 2023
6ede734
fix conflicts rebase
Dec 5, 2023
2d9c6aa
fix conflict locals
Dec 5, 2023
1b47b16
remove comma app_vars
Dec 5, 2023
789e504
revise db_name
Dec 5, 2023
9a977eb
remove extra identifier
Dec 5, 2023
17a3bb7
remove name argument
Dec 5, 2023
b3d48a3
fix database.tf
Dec 7, 2023
45fc12e
add s3 access for RDS
Dec 8, 2023
00facd1
fix conflicts
Dec 8, 2023
5f99bd5
fix conflicts
Dec 8, 2023
0653d5b
fixed conflicts
Dec 8, 2023
be57f08
fixed typo
Dec 8, 2023
b0b2ebf
fix conflicts
roncitrus Dec 8, 2023
852e9db
rebased branch
roncitrus Dec 8, 2023
d826ffb
add rds prepro and prod
roncitrus Dec 8, 2023
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
33 changes: 32 additions & 1 deletion terraform/environments/cdpt-chaps/application_variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,46 @@
"accounts": {
"development": {
"region": "eu-west-2",
"docker_image_tag": "development"
"docker_image_tag": "development",
"db_enabled": true,
"db_instance_class": "db.t3.small",
"db_user": "admin",
"db_allocated_storage": "75",
"db_name": "chaps-dev",
"env_name": "development",
"db_instance_identifier": "chaps-dev-instance",
"friendly_name": "Chaps development",
"container_instance_type": "windows",
"container_version": "preproduction"
},
"preproduction": {
"db_enabled": true,
"db_instance_class": "db.t3.xlarge",
"db_user": "admin",
"db_allocated_storage": "75",
"db_name": "chaps-preproduction",
"env_name": "preproduction",
"db_instance_identifier": "chaps-preprod-instance",
"friendly_name": "Chaps preproduction",
"container_instance_type": "windows",
"container_version": "preproduction",
"region": "eu-west-2",
"docker_image_tag": "preproduction"
},
"production": {
"db_enabled": true,
"db_instance_class": "db.m5.xlarge",
"db_user": "admin",
"db_allocated_storage": "100",
"db_name": "chaps-prod",
"env_name": "production",
"db_instance_identifier": "chaps-prod-instance",
"friendly_name": "Chaps Production",
"container_instance_type": "windows",
"container_version": "production",
"region": "eu-west-2",
"docker_image_tag": "production"
}
}
}

81 changes: 81 additions & 0 deletions terraform/environments/cdpt-chaps/database.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#------------------------------------------------------------------------------
# Database
#------------------------------------------------------------------------------

resource "aws_db_instance" "database" {
allocated_storage = local.app_data.accounts[local.environment].db_allocated_storage
storage_type = "gp2"
engine = "sqlserver-web"
engine_version = "14.00.3381.3.v1"
instance_class = local.app_data.accounts[local.environment].db_instance_class
identifier = local.app_data.accounts[local.environment].db_instance_identifier
username = local.app_data.accounts[local.environment].db_user
iam_database_authentication_enabled = true
}

resource "aws_db_instance_role_association" "rds_s3_role_association" {
db_instance_identifier = aws_db_instance.database.identifier
feature_name = "S3_INTEGRATION"
role_arn = "arn:aws:iam::613903586696:role/RDS-S3-CrossAccountAccess"
}

resource "aws_security_group" "db" {
name = "db"
description = "Allow DB inbound traffic"

ingress {
from_port = 1433
to_port = 1433
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_iam_role" "rds_s3_access" {
assume_role_policy = jsonencode({
Version = "2017-10-17",
Statement = [
{
Action = "sts:AssumeRole",
Effect = "Allow",
Principal = {
Service = "rds.amazonaws.com"
},
},
]
})
}

#------------------------------------------------------------------------------
# KMS setup for RDS
#------------------------------------------------------------------------------

resource "aws_kms_key" "rds" {
description = "Encryption key for rds"
enable_key_rotation = true
policy = data.aws_iam_policy_document.rds-kms.json
}

resource "aws_kms_alias" "rds-kms-alias" {
name = "alias/rds"
target_key_id = aws_kms_key.rds.arn
}

data "aws_iam_policy_document" "rds-kms" {
statement {
effect = "Allow"
actions = ["kms:*"]
resources = ["*"]
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
}
}
}
5 changes: 4 additions & 1 deletion terraform/environments/cdpt-chaps/locals.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#### This file can be used to store locals specific to the member account ####
locals {
app_data = jsondecode(file("./application_variables.json"))

domain_types = { for dvo in aws_acm_certificate.external.domain_validation_options : dvo.domain_name => {
name = dvo.resource_record_name
record = dvo.resource_record_value
Expand All @@ -14,4 +17,4 @@ locals {
domain_type_sub = [for k, v in local.domain_types : v.type if k != "modernisation-platform.service.justice.gov.uk"]

ecr_url = "${local.environment_management.account_ids["core-shared-services-production"]}.dkr.ecr.eu-west-2.amazonaws.com/cdpt-chaps-ecr-repo"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resource "aws_backup_vault" "oracle_backup_vault" {
name = "${var.env_name}-oracle-backup-vault"
kms_key_arn = var.account_config.kms_keys.general_shared
tags = merge(
var.tags,
{
"Name" = "${var.env_name}-oracle-backup-vault"
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ run_ansible() {
then
group=$(echo "$${environment_name}_$${delius_environment_name}_$${database}" | tr [:upper:] [:lower:] | sed "s/-/_/g")
group_all=$(echo "$${environment_name}_$${delius_environment_name}_all" | tr [:upper:] [:lower:] | sed "s/-/_/g")
database_type=$(echo $database | cut -d'_' -f2 | sed "s/db//g")
[[ $database =~ "primarydb" ]] && database_type="primary" || database_type="standby"
ansible_group_vars="$ansible_group_vars --extra-vars @group_vars/$group.yml --extra-vars @group_vars/$group_all.yml --extra-vars database_type=$database_type"
elif [[ $i -gt 2 ]]
then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ run_ansible() {
then
group=$(echo "$${environment_name}_$${delius_environment_name}_$${database}" | tr [:upper:] [:lower:] | sed "s/-/_/g")
group_all=$(echo "$${environment_name}_$${delius_environment_name}_all" | tr [:upper:] [:lower:] | sed "s/-/_/g")
database_type=$(echo $database | cut -d'_' -f2 | sed "s/db//g")
[[ $database =~ "primarydb" ]] && database_type="primary" || database_type="standby"
ansible_group_vars="$ansible_group_vars --extra-vars @group_vars/$group.yml --extra-vars @group_vars/$group_all.yml --extra-vars database_type=$database_type"
elif [[ $i -gt 2 ]]
then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ locals {
availability_zone = null
ebs_volumes_copy_all_from_ami = false
user_data_raw = base64encode(templatefile("./templates/rds.yaml.tftpl", {
rds_hostname = "RDSConnectionBroker"
rds_hostname = "RDSBroker"
}))
})
instance = merge(module.baseline_presets.ec2_instance.instance.default, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ tasks:
Disable-NetAdapterBinding -Name 'Ethernet' -ComponentID 'ms_tcpip6'
Import-Module RemoteDesktop
Enable-PSRemoting -force
Rename-Computer -NewName ${rds_hostname}
Rename-Computer -NewName "${rds_hostname}1"
Sleep 5
Restart-Computer -Force
22 changes: 22 additions & 0 deletions terraform/environments/hmpps-oem/locals_development.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ locals {
# baseline config
development_config = {

baseline_secretsmanager_secrets = {
"/oracle/oem" = local.oem_secretsmanager_secrets
"/oracle/database/EMREP" = local.oem_secretsmanager_secrets
"/oracle/database/DEVRCVCAT" = local.oem_secretsmanager_secrets
}

baseline_ec2_autoscaling_groups = {
dev-base-ol85 = {
config = merge(module.baseline_presets.ec2_instance.config.default, {
Expand Down Expand Up @@ -32,5 +38,21 @@ locals {
}
}

baseline_ec2_instances = {
dev-oem-a = merge(local.oem_ec2_default, {
config = merge(local.oem_ec2_default.config, {
ami_name = "hmpps_ol_8_5_oracledb_19c_release_2023-12-07T12-10-49.620Z"
availability_zone = "eu-west-2a"
})
user_data_cloud_init = merge(local.oem_ec2_default.user_data_cloud_init, {
args = merge(local.oem_ec2_default.user_data_cloud_init.args, {
branch = "45027fb7482eb7fb601c9493513bb73658780dda" # 2023-08-11
})
})
tags = merge(local.oem_ec2_default.tags, {
oracle-sids = "EMREP DEVRCVCAT"
})
})
}
}
}
8 changes: 8 additions & 0 deletions terraform/environments/tipstaff/rds.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ resource "aws_security_group" "postgresql_db_sc" {
module.bastion_linux.bastion_security_group
]
}

ingress {
from_port = 5432
to_port = 5432
protocol = "tcp"
description = "MOJ Digital VPN access"
cidr_blocks = [local.application_data.accounts[local.environment].moj_ip]
}
egress {
description = "allow all outbound traffic"
from_port = 0
Expand Down
Loading