Skip to content

Commit

Permalink
Small fixes on naming and to work with secrets manager (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
adenot authored Oct 22, 2021
1 parent bd457a5 commit 9f09559
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions aurora.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource "aws_rds_cluster" "aurora_cluster" {
count = var.db_type == "aurora" ? 1 : 0
cluster_identifier = var.identifier
cluster_identifier = var.identifier == "" ? "${var.environment_name}-${var.name}" : var.identifier
engine = var.engine
engine_version = var.engine_version
database_name = var.database_name
Expand All @@ -17,7 +17,7 @@ resource "aws_rds_cluster" "aurora_cluster" {

resource "aws_rds_cluster_instance" "cluster_instances" {
count = var.db_type == "aurora" ? var.count_aurora_instances : 0
identifier = "${var.identifier}-${count.index}"
identifier = var.identifier == "" ? "${var.environment_name}-${var.name}-${count.index}" : "${var.identifier}-${count.index}"
cluster_identifier = aws_rds_cluster.aurora_cluster[0].id
instance_class = var.instance_class
engine = aws_rds_cluster.aurora_cluster[0].engine
Expand Down
6 changes: 1 addition & 5 deletions secrets-manager.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource "aws_secretsmanager_secret" "rds" {
count = var.secret_method == "secretsmanager" ? 1 : 0
name = "/rds/${var.environment_name}-${var.identifier}"
name = var.identifier == "" ? "/rds/${var.environment_name}-${var.name}" : "/rds/${var.identifier}"
recovery_window_in_days = 0
}

Expand All @@ -16,14 +16,10 @@ locals {
reader_endpoint = var.db_type == "aurora" ? aws_rds_cluster.aurora_cluster[0].reader_endpoint : "null"
}
rds_secret = local.secrets


}


resource "aws_secretsmanager_secret_version" "rds" {
count = var.secret_method == "secretsmanager" ? 1 : 0
secret_id = aws_secretsmanager_secret.rds[0].id
secret_string = jsonencode(local.rds_secret)

}
4 changes: 3 additions & 1 deletion ssm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ resource "aws_ssm_parameter" "rds_db_user" {
}

resource "aws_ssm_parameter" "rds_endpoint" {
count = var.secret_method == "ssm" ? 1 : 0
name = "/rds/${var.environment_name}-${var.name}/ENDPOINT"
description = "RDS Endpoint"
type = "String"
Expand All @@ -27,14 +28,15 @@ resource "aws_ssm_parameter" "rds_endpoint" {


resource "aws_ssm_parameter" "rds_reader_endpoint" {
count = var.db_type == "aurora" ? 1 : 0
count = var.db_type == "aurora" && var.secret_method == "ssm" ? 1 : 0
name = "/rds/${var.environment_name}-${var.name}/READER_ENDPOINT"
description = "RDS Reader Endpoint"
type = "String"
value = aws_rds_cluster.aurora_cluster[0].reader_endpoint
}

resource "aws_ssm_parameter" "rds_db_address" {
count = var.secret_method == "ssm" ? 1 : 0
name = "/rds/${var.environment_name}-${var.name}/HOST"
description = "RDS Hostname"
type = "String"
Expand Down

0 comments on commit 9f09559

Please sign in to comment.