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 support for replica #3

Merged
merged 3 commits into from
Aug 23, 2021
Merged
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
54 changes: 38 additions & 16 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,45 @@ locals {
filename = var.rotation_type == "single" ? "SecretsManagerRDSMySQLRotationSingleUser.zip" : "SecretsManagerRDSMySQLRotationMultiUser.zip"
lambda_description = var.rotation_type == "single" ? "Conducts an AWS SecretsManager secret rotation for RDS MySQL using single user rotation scheme" : "Conducts an AWS SecretsManager secret rotation for RDS MySQL using multi user rotation scheme"

secret_string_single = {
username = var.mysql_username
password = var.mysql_password
engine = "mysql"
host = var.mysql_host
port = var.mysql_port
dbname = var.mysql_dbname
secret_string_single_bare = {
username = var.mysql_username
password = var.mysql_password
engine = "mysql"
host = var.mysql_host
port = var.mysql_port
dbname = var.mysql_dbname
}
secret_string_multi = {
username = var.mysql_username
password = var.mysql_password
engine = "mysql"
host = var.mysql_host
port = var.mysql_port
dbname = var.mysql_dbname
masterarn = var.secretsmanager_masterarn
secret_string_single_replica = {
username = var.mysql_username
password = var.mysql_password
engine = "mysql"
host = var.mysql_host
port = var.mysql_port
dbname = var.mysql_dbname
replicahost = var.mysql_replicahost
}
secret_string_single = var.mysql_replicahost == null ? local.secret_string_single_bare : local.secret_string_single_replica

secret_string_multi_bare = {
username = var.mysql_username
password = var.mysql_password
engine = "mysql"
host = var.mysql_host
port = var.mysql_port
dbname = var.mysql_dbname
masterarn = var.secretsmanager_masterarn
}
secret_string_multi_replica = {
username = var.mysql_username
password = var.mysql_password
engine = "mysql"
host = var.mysql_host
port = var.mysql_port
dbname = var.mysql_dbname
replicahost = var.mysql_replicahost
masterarn = var.secretsmanager_masterarn
}
secret_string_multi = var.mysql_replicahost == null ? local.secret_string_multi_bare : local.secret_string_multi_replica
}

resource "aws_iam_role" "default" {
Expand Down Expand Up @@ -118,7 +140,7 @@ resource "aws_lambda_function" "default" {
SECRETS_MANAGER_ENDPOINT = "https://secretsmanager.${data.aws_region.current.name}.amazonaws.com"
}
}
tags = module.this.tags
tags = module.this.tags
}

resource "aws_lambda_permission" "default" {
Expand Down
12 changes: 9 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ variable "rotation_days" {
}

variable "subnets_lambda" {
type = list
type = list(any)
description = "The subnets where the Lambda Function will be run"
}

Expand Down Expand Up @@ -54,12 +54,18 @@ variable "secretsmanager_masterarn" {
#}

variable "security_group" {
type = list
type = list(any)
description = "The security group(s) where the Lambda Function will be run. This must have access to the RDS instance. The best option is to make this the RDS' security group and allow the SG to access itself"
}

variable "mysql_replicahost" {
type = string
description = "The RDS replica endpoint to connect to your read-only database"
default = null
}

variable "secret_label_order" {
type = list
type = list(any)
default = ["namespace", "environment", "stage", "name", "attributes"]
description = <<-EOT
The naming order of the id output and Name tag.
Expand Down