Skip to content

Commit ff1c0a5

Browse files
authored
Add encryption to RDS (#59)
* Fix readme and cloudwatch+docker dep * Initial commit * Changing defaults * Adding proxy.env content and fixing redis.env merge
1 parent 13a9def commit ff1c0a5

File tree

10 files changed

+138
-17
lines changed

10 files changed

+138
-17
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ The following inputs can be used as `step.with` keys
191191
#### **Load Balancer Inputs**
192192
| Name | Type | Description |
193193
|------------------|---------|------------------------------------|
194-
| `aws_elb_create` | Boolean | Toggles the creation of a load balancer and map ports to the EC2 instance. Defaults to `true`.|
194+
| `aws_elb_create` | Boolean | Toggles the creation of a load balancer and map ports to the EC2 instance. Defaults to `false`.|
195195
| `aws_elb_security_group_name` | String | The name of the ELB security group. Defaults to `SG for ${aws_resource_identifier} - ELB`. |
196196
| `aws_elb_app_port` | String | Port in the EC2 instance to be redirected to. Default is `3000`. Accepts comma separated values like `3000,3001`. |
197197
| `aws_elb_app_protocol` | String | Protocol to enable. Could be HTTP, HTTPS, TCP or SSL. Defaults to `TCP`. If length doesn't match, will use `TCP` for all.|
@@ -240,10 +240,16 @@ The following inputs can be used as `step.with` keys
240240
| `aws_rds_db_subnets`| String | Specify which subnets to use as a list of strings. Example: `i-1234,i-5678,i-9101`. |
241241
| `aws_rds_db_allocated_storage`| String | Storage size. Defaults to `10`. |
242242
| `aws_rds_db_max_allocated_storage`| String | Max storage size. Defaults to `0` to disable auto-scaling. |
243+
| `aws_rds_db_storage_encrypted` | Boolean | Toogle storage encryption. Defatuls to false. |
244+
| `aws_rds_db_storage_type` | String | Storage type. Like gp2 / gp3. Defaults to gp2. |
245+
| `aws_rds_db_kms_key_id` | String | The ARN for the KMS encryption key. |
243246
| `aws_rds_db_instance_class`| String | DB instance server type. Defaults to `db.t3.micro`. See [this list](https://aws.amazon.com/rds/instance-types/). |
244247
| `aws_rds_db_final_snapshot` | String | If final snapshot is wanted, add a snapshot name. Leave emtpy if not. |
245248
| `aws_rds_db_restore_snapshot_identifier` | String | Name of the snapshot to restore the databse from. |
246249
| `aws_rds_db_cloudwatch_logs_exports`| String | Set of log types to enable for exporting to CloudWatch logs. Defaults to `postgresql`. Options are MySQL and MariaDB: `audit,error,general,slowquery`. PostgreSQL: `postgresql,upgrade`. MSSQL: `agent,error`. Oracle: `alert,audit,listener,trace`. |
250+
| `aws_rds_db_multi_az` | Boolean| Specifies if the RDS instance is multi-AZ. Defaults to `false`. |
251+
| `aws_rds_db_maintenance_window` | String | The window to perform maintenance in. Eg: `Mon:00:00-Mon:03:00` |
252+
| `aws_rds_db_apply_immediately` | Boolean | Specifies whether any database modifications are applied immediately, or during the next maintenance window. Defaults to `false`.|
247253
| `aws_rds_db_additional_tags` | JSON | Add additional tags to the terraform [default tags](https://www.hashicorp.com/blog/default-tags-in-the-terraform-aws-provider), any tags put here will be added to RDS provisioned resources.|
248254
<hr/>
249255
<br/>

action.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,15 @@ inputs:
353353
aws_rds_db_max_allocated_storage:
354354
description: 'Max storage size. Defaults to 0 to disable auto-scaling.'
355355
required: false
356+
aws_rds_db_storage_encrypted:
357+
description: 'Toogle storage encryption. Defatuls to false.'
358+
required: false
359+
aws_rds_db_storage_type:
360+
description: 'Storage type. Like gp2 / gp3. Defaults to gp2.'
361+
required: false
362+
aws_rds_db_kms_key_id:
363+
description: 'The ARN for the KMS encryption key.'
364+
required: false
356365
aws_rds_db_instance_class:
357366
description: 'DB instance server type. Defaults to db.t3.micro.'
358367
required: false
@@ -365,6 +374,15 @@ inputs:
365374
aws_rds_db_cloudwatch_logs_exports:
366375
description: 'Set of log types to enable for exporting to CloudWatch logs.'
367376
required: false
377+
aws_rds_db_multi_az:
378+
description: 'Specifies if the RDS instance is multi-AZ'
379+
required: false
380+
aws_rds_db_maintenance_window:
381+
description: 'The window to perform maintenance in. Eg: Mon:00:00-Mon:03:00 '
382+
required: false
383+
aws_rds_db_apply_immediately:
384+
description: 'Specifies whether any database modifications are applied immediately, or during the next maintenance window'
385+
required: false
368386
aws_rds_db_additional_tags:
369387
description: 'A JSON object of additional tags that will be included on created resources. Example: `{"key1": "value1", "key2": "value2"}`'
370388
required: false
@@ -1041,10 +1059,16 @@ runs:
10411059
AWS_RDS_DB_SUBNETS: ${{ inputs.aws_rds_db_subnets }}
10421060
AWS_RDS_DB_ALLOCATED_STORAGE: ${{ inputs.aws_rds_db_allocated_storage }}
10431061
AWS_RDS_DB_MAX_ALLOCATED_STORAGE: ${{ inputs.aws_rds_db_max_allocated_storage }}
1062+
AWS_RDS_DB_STORAGE_ENCRYPTED: ${{ inputs.aws_rds_db_storage_encrypted }}
1063+
AWS_RDS_DB_STORAGE_TYPE: ${{ inputs.aws_rds_db_storage_type }}
1064+
AWS_RDS_DB_KMS_KEY_ID: ${{ inputs.aws_rds_db_kms_key_id }}
10441065
AWS_RDS_DB_INSTANCE_CLASS: ${{ inputs.aws_rds_db_instance_class }}
10451066
AWS_RDS_DB_FINAL_SNAPSHOT: ${{ inputs.aws_rds_db_final_snapshot }}
10461067
AWS_RDS_DB_RESTORE_SNAPSHOT_IDENTIFIER: ${{ inputs.aws_rds_db_restore_snapshot_identifier }}
10471068
AWS_RDS_DB_CLOUDWATCH_LOGS_EXPORTS: ${{ inputs.aws_rds_db_cloudwatch_logs_exports }}
1069+
AWS_RDS_DB_MULTI_AZ: ${{ inputs.aws_rds_db_multi_az }}
1070+
AWS_RDS_DB_MAINTENANCE_WINDOWS: ${{ inputs.aws_rds_db_maintenance_window }}
1071+
AWS_RDS_DB_APPLY_IMMEDIATELY: ${{ inputs.aws_rds_db_apply_immediately }}
10481072
AWS_RDS_DB_ADDITIONAL_TAGS: ${{ inputs.aws_rds_db_additional_tags }}
10491073

10501074
# AWS AURORA

operations/_scripts/generate/generate_vars_terraform.sh

+12
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,16 @@ if [[ $(alpha_only "$AWS_RDS_DB_ENABLE") == true ]]; then
176176
aws_rds_db_subnets=$(generate_var aws_rds_db_subnets $AWS_RDS_DB_SUBNETS)
177177
aws_rds_db_allocated_storage=$(generate_var aws_rds_db_allocated_storage $AWS_RDS_DB_ALLOCATED_STORAGE)
178178
aws_rds_db_max_allocated_storage=$(generate_var aws_rds_db_max_allocated_storage $AWS_RDS_DB_MAX_ALLOCATED_STORAGE)
179+
aws_rds_db_storage_encrypted=$(generate_var aws_rds_db_storage_encrypted $AWS_RDS_DB_STORAGE_ENCRYPTED)
180+
aws_rds_db_storage_type=$(generate_var aws_rds_db_storage_type $AWS_RDS_DB_STORAGE_TYPE)
181+
aws_rds_db_kms_key_id=$(generate_var aws_rds_db_kms_key_id $AWS_RDS_DB_KMS_KEY_ID)
179182
aws_rds_db_instance_class=$(generate_var aws_rds_db_instance_class $AWS_RDS_DB_INSTANCE_CLASS)
180183
aws_rds_db_final_snapshot=$(generate_var aws_rds_db_final_snapshot $AWS_RDS_DB_FINAL_SNAPSHOT)
181184
aws_rds_db_restore_snapshot_identifier=$(generate_var aws_rds_db_restore_snapshot_identifier $AWS_RDS_DB_RESTORE_SNAPSHOT_IDENTIFIER)
182185
aws_rds_db_cloudwatch_logs_exports=$(generate_var aws_rds_db_cloudwatch_logs_exports $AWS_RDS_DB_CLOUDWATCH_LOGS_EXPORTS)
186+
aws_rds_db_multi_az=$(generate_var aws_rds_db_multi_az $AWS_RDS_DB_MULTI_AZ)
187+
aws_rds_db_maintenance_window=$(generate_var aws_rds_db_maintenance_window $AWS_RDS_DB_MAINTENANCE_WINDOWS)
188+
aws_rds_db_apply_immediately=$(generate_var aws_rds_db_apply_immediately $AWS_RDS_DB_APPLY_IMMEDIATELY)
183189
aws_rds_db_additional_tags=$(generate_var aws_rds_db_additional_tags $AWS_RDS_DB_ADDITIONAL_TAGS)
184190
fi
185191

@@ -473,10 +479,16 @@ $aws_rds_db_port
473479
$aws_rds_db_subnets
474480
$aws_rds_db_allocated_storage
475481
$aws_rds_db_max_allocated_storage
482+
$aws_rds_db_storage_encrypted
483+
$aws_rds_db_storage_type
484+
$aws_rds_db_kms_key_id
476485
$aws_rds_db_instance_class
477486
$aws_rds_db_final_snapshot
478487
$aws_rds_db_restore_snapshot_identifier
479488
$aws_rds_db_cloudwatch_logs_exports
489+
$aws_rds_db_multi_az
490+
$aws_rds_db_maintenance_window
491+
$aws_rds_db_apply_immediately
480492
$aws_rds_db_additional_tags
481493
482494
#-- AURORA --#

operations/deployment/terraform/aws/aws_variables.tf

+36
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,24 @@ variable "aws_rds_db_max_allocated_storage" {
480480
default = "0"
481481
}
482482

483+
variable "aws_rds_db_storage_encrypted" {
484+
type = bool
485+
description = "Toogle storage encryption. Defatuls to false."
486+
default = false
487+
}
488+
489+
variable "aws_rds_db_storage_type" {
490+
type = string
491+
description = "Storage type. Like gp2 / gp3. Defaults to gp2."
492+
default = ""
493+
}
494+
495+
variable "aws_rds_db_kms_key_id" {
496+
type = string
497+
description = "The ARN for the KMS encryption key."
498+
default = ""
499+
}
500+
483501
variable "aws_rds_db_instance_class" {
484502
type = string
485503
description = "Server size"
@@ -504,6 +522,24 @@ variable "aws_rds_db_cloudwatch_logs_exports" {
504522
default = "postgresql"
505523
}
506524

525+
variable "aws_rds_db_multi_az" {
526+
type = bool
527+
description = "Specifies if the RDS instance is multi-AZ"
528+
default = false
529+
}
530+
531+
variable "aws_rds_db_maintenance_window" {
532+
type = string
533+
description = "The window to perform maintenance in. Eg: Mon:00:00-Mon:03:00 "
534+
default = ""
535+
}
536+
537+
variable "aws_rds_db_apply_immediately" {
538+
type = bool
539+
description = "Specifies whether any database modifications are applied immediately, or during the next maintenance window"
540+
default = false
541+
}
542+
507543
variable "aws_rds_db_additional_tags" {
508544
type = string
509545
description = "A list of strings that will be added to created resources"

operations/deployment/terraform/aws/bitops.after-deploy.d/merge-tf-env.sh

+16-8
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,32 @@ set -e
66
echo "BitOps Ansible before script: Merge Terraform Enviornment Variables..."
77

88
ANSIBLE_DIR=ansible/clone_repo
9-
TERRAFORM_PATH=terraform/aws
9+
AWS_TERRAFORM_PATH=terraform/aws
10+
#COMMONS_TERRAFORM_PATH=terraform/commons
1011

1112
# Merging order
12-
order=ec2,efs,rds,aurora,reids,repo,ghv,ghs,aws
13+
order=ec2,efs,rds,aurora,redis,proxy,repo,ghv,ghs,aws
1314

1415
# Ansible dotenv file -> The final destination of all
1516
ENV_OUT_FILE="${BITOPS_ENVROOT}/${ANSIBLE_DIR}/app.env"
1617

1718
# TF dotenv file
18-
ENV_EC2_FILE="${BITOPS_ENVROOT}/${TERRAFORM_PATH}/ec2.env"
19+
ENV_EC2_FILE="${BITOPS_ENVROOT}/${AWS_TERRAFORM_PATH}/ec2.env"
1920

2021
# EFS dotenv file
21-
ENV_EFS_FILE="${BITOPS_ENVROOT}/${TERRAFORM_PATH}/efs.env"
22+
ENV_EFS_FILE="${BITOPS_ENVROOT}/${AWS_TERRAFORM_PATH}/efs.env"
2223

2324
# RDS dotenv file
24-
ENV_RDS_FILE="${BITOPS_ENVROOT}/${TERRAFORM_PATH}/rds.env"
25+
ENV_RDS_FILE="${BITOPS_ENVROOT}/${AWS_TERRAFORM_PATH}/rds.env"
2526

2627
# Aurora dotenv file
27-
ENV_AURORA_FILE="${BITOPS_ENVROOT}/${TERRAFORM_PATH}/aurora.env"
28+
ENV_AURORA_FILE="${BITOPS_ENVROOT}/${AWS_TERRAFORM_PATH}/aurora.env"
2829

2930
# Redis dotenv file
30-
ENV_REDIS_FILE="${BITOPS_ENVROOT}/${TERRAFORM_PATH}/redis.env"
31+
ENV_REDIS_FILE="${BITOPS_ENVROOT}/${AWS_TERRAFORM_PATH}/redis.env"
32+
33+
# Proxy dotenv file
34+
ENV_PROXY_FILE="${BITOPS_ENVROOT}/${AWS_TERRAFORM_PATH}/proxy.env"
3135

3236
# Repo env file
3337
ENV_REPO_FILE="${BITOPS_ENVROOT}/env-files/repo.env"
@@ -39,7 +43,7 @@ ENV_GHV_FILE="${BITOPS_ENVROOT}/env-files/ghv.env"
3943
ENV_GHS_FILE="${BITOPS_ENVROOT}/env-files/ghs.env"
4044

4145
# TF AWS dotenv file
42-
ENV_AWS_SECRET_FILE="${BITOPS_ENVROOT}/${TERRAFORM_PATH}/aws.env"
46+
ENV_AWS_SECRET_FILE="${BITOPS_ENVROOT}/${AWS_TERRAFORM_PATH}/aws.env"
4347

4448
# Make sure app.env is empty, if not, delete it and create one.
4549

@@ -98,6 +102,10 @@ function process {
98102
# Code to be executed for option9
99103
merge $ENV_REDIS_FILE "Redis"
100104
;;
105+
proxy)
106+
# Code to be executed for option9
107+
merge $ENV_PROXY_FILE "Proxy"
108+
;;
101109
*)
102110
# Code to be executed if no matching option is found
103111
echo "Invalid option"

operations/deployment/terraform/aws/bitovi_main.tf

+13
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,16 @@ module "rds" {
146146
aws_rds_db_subnets = var.aws_rds_db_subnets
147147
aws_rds_db_allocated_storage = var.aws_rds_db_allocated_storage
148148
aws_rds_db_max_allocated_storage = var.aws_rds_db_max_allocated_storage
149+
aws_rds_db_storage_encrypted = var.aws_rds_db_storage_encrypted
150+
aws_rds_db_storage_type = var.aws_rds_db_storage_type
151+
aws_rds_db_kms_key_id = var.aws_rds_db_kms_key_id
149152
aws_rds_db_instance_class = var.aws_rds_db_instance_class
150153
aws_rds_db_final_snapshot = var.aws_rds_db_final_snapshot
151154
aws_rds_db_restore_snapshot_identifier = var.aws_rds_db_restore_snapshot_identifier
152155
aws_rds_db_cloudwatch_logs_exports = var.aws_rds_db_cloudwatch_logs_exports
156+
aws_rds_db_multi_az = var.aws_rds_db_multi_az
157+
aws_rds_db_maintenance_window = var.aws_rds_db_maintenance_window
158+
aws_rds_db_apply_immediately = var.aws_rds_db_apply_immediately
153159
# Others
154160
aws_selected_vpc_id = module.vpc.aws_selected_vpc_id
155161
aws_subnets_vpc_subnets_ids = module.vpc.aws_selected_vpc_subnets
@@ -294,6 +300,13 @@ module "db_proxy" {
294300
}
295301
}
296302

303+
module "proxy_dot_env" {
304+
source = "../modules/commons/dot_env"
305+
filename = "proxy.env"
306+
content = join("\n",[try(module.db_proxy_aurora.proxy_dot_env,""),try(module.db_proxy_rds.proxy_dot_env,""),try(module.db_proxy.proxy_dot_env,"")])
307+
depends_on = [ module.db_proxy_aurora,module.db_proxy_rds,module.db_proxy_rds ]
308+
}
309+
297310
module "redis" {
298311
source = "../modules/aws/redis"
299312
count = var.aws_redis_enable ? 1 : 0

operations/deployment/terraform/modules/aws/db_proxy/aws_dotenv_proxy.tf

+6-8
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
locals {
44
var_name = var.aws_rds_db_proxy ? "DB_PROXY" : var.aws_aurora_proxy ? "DBA_PROXY" : "PROXY_ENDPOINT"
55
file_name = var.aws_rds_db_proxy ? "rds" : var.aws_aurora_proxy ? "aurora" : "proxy"
6+
dot_env = <<-EOT
7+
#### Proxy values for ${local.file_name}
8+
${local.var_name}=${aws_db_proxy.rds_proxy[0].endpoint}"
9+
EOT
610
}
711

8-
9-
resource "local_file" "aurora-dotenv" {
10-
filename = format("%s/%s", abspath(path.root), "proxy.${local.file_name}.env")
11-
content = <<-EOT
12-
13-
#### Proxy values
14-
${local.var_name}=${aws_db_proxy.rds_proxy[0].endpoint}
15-
EOT
12+
output "proxy_dot_env" {
13+
value = local.dot_env
1614
}

operations/deployment/terraform/modules/aws/rds/aws_rds.tf

+6
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ resource "aws_db_instance" "default" {
6262
port = var.aws_rds_db_port != null ? tonumber(var.aws_rds_db_port) : null
6363
allocated_storage = tonumber(var.aws_rds_db_allocated_storage)
6464
max_allocated_storage = tonumber(var.aws_rds_db_max_allocated_storage)
65+
storage_encrypted = var.aws_rds_db_storage_encrypted
66+
storage_type = var.aws_rds_db_storage_type
67+
kms_key_id = var.aws_rds_db_kms_key_id
6568
instance_class = var.aws_rds_db_instance_class
6669
username = var.aws_rds_db_user != null ? var.aws_rds_db_user : "dbuser"
6770
password = random_password.rds.result
@@ -71,6 +74,9 @@ resource "aws_db_instance" "default" {
7174
publicly_accessible = var.aws_rds_db_publicly_accessible
7275
enabled_cloudwatch_logs_exports = [var.aws_rds_db_cloudwatch_logs_exports]
7376
vpc_security_group_ids = [aws_security_group.rds_db_security_group.id]
77+
multi_az = var.aws_rds_db_multi_az
78+
maintenance_window = var.aws_rds_db_maintenance_window
79+
apply_immediately = var.aws_rds_db_apply_immediately
7480
tags = {
7581
Name = "${var.aws_resource_identifier}-rds"
7682
}

operations/deployment/terraform/modules/aws/rds/aws_rds_vars.tf

+6
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@ variable "aws_rds_db_port" {}
1212
variable "aws_rds_db_subnets" {}
1313
variable "aws_rds_db_allocated_storage" {}
1414
variable "aws_rds_db_max_allocated_storage" {}
15+
variable "aws_rds_db_storage_encrypted" {}
16+
variable "aws_rds_db_storage_type" {}
17+
variable "aws_rds_db_kms_key_id" {}
1518
variable "aws_rds_db_instance_class" {}
1619
variable "aws_rds_db_final_snapshot" {}
1720
variable "aws_rds_db_restore_snapshot_identifier" {}
1821
variable "aws_rds_db_cloudwatch_logs_exports" {}
22+
variable "aws_rds_db_multi_az" {}
23+
variable "aws_rds_db_maintenance_window" {}
24+
variable "aws_rds_db_apply_immediately" {}
1925
variable "aws_resource_identifier" {}
2026
variable "aws_resource_identifier_supershort" {}
2127
variable "aws_selected_vpc_id" {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
resource "local_file" "file_dotenv" {
2+
filename = format("%s/%s", abspath(path.root), var.filename)
3+
content = sensitive(var.content)
4+
}
5+
6+
variable "content" {
7+
type = string
8+
}
9+
10+
variable "filename" {
11+
type = string
12+
}

0 commit comments

Comments
 (0)