-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
locals { | ||
stack = var.stack != "" ? var.stack : var.environment | ||
} | ||
|
||
resource "random_password" "random_db_password" { | ||
length = 30 | ||
special = true | ||
override_special = "!#$%&_" | ||
} | ||
|
||
resource "random_id" "final_snapshot_id" { | ||
byte_length = 4 | ||
} | ||
|
||
resource "aws_db_instance" "db" { | ||
identifier = "${local.stack}-${var.app_name}" | ||
snapshot_identifier = var.snapshot_identifier | ||
allocated_storage = var.snapshot_identifier != "" ? null : var.allocated_storage | ||
storage_type = "gp2" | ||
engine = var.snapshot_identifier != "" ? null : "${var.db_engine}" | ||
engine_version = var.snapshot_identifier != "" ? null : "${var.db_engine_version}" | ||
instance_class = "${var.db_instance_class}" | ||
name = var.snapshot_identifier != "" ? null : "${var.db_name}" | ||
username = var.snapshot_identifier != "" ? null : "${var.db_username}" | ||
password = "${aws_ssm_parameter.password.value}" | ||
vpc_security_group_ids = "${var.vpc_security_group_ids}" | ||
db_subnet_group_name = "${var.subnet_group_name}" | ||
|
||
final_snapshot_identifier = "A${random_id.final_snapshot_id.hex}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
resource "aws_ssm_parameter" "password" { | ||
name = "/${var.environment}/${var.app_name}/${local.stack}/DB_PASSWORD" | ||
description = "db password" | ||
type = "SecureString" | ||
value = "${random_password.random_db_password.result}" | ||
overwrite = "true" | ||
tags = { | ||
environment = "${var.environment}" | ||
} | ||
} | ||
|
||
resource "aws_ssm_parameter" "host" { | ||
name = "/${var.environment}/${var.app_name}/${local.stack}/DB_HOST" | ||
description = "db host" | ||
type = "SecureString" | ||
value = "${aws_db_instance.db.address}" | ||
overwrite = "true" | ||
|
||
tags = { | ||
environment = "${var.environment}" | ||
} | ||
} | ||
|
||
resource "aws_ssm_parameter" "name" { | ||
name = "/${var.environment}/${var.app_name}/${local.stack}/DB_NAME" | ||
description = "db name" | ||
type = "SecureString" | ||
value = "${aws_db_instance.db.name}" | ||
overwrite = "true" | ||
|
||
tags = { | ||
environment = "${var.environment}" | ||
} | ||
} | ||
|
||
resource "aws_ssm_parameter" "username" { | ||
name = "/${var.environment}/${var.app_name}/${local.stack}/DB_USERNAME" | ||
description = "db username" | ||
type = "SecureString" | ||
value = "${aws_db_instance.db.username}" | ||
overwrite = "true" | ||
|
||
tags = { | ||
environment = "${var.environment}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
variable "app_name" { | ||
type = string | ||
description = "Name of the app to create an RDS instance for" | ||
} | ||
|
||
variable "environment" { | ||
type = string | ||
description = "Infrastructure environment, e.g. staging or production" | ||
default = "staging" | ||
} | ||
|
||
variable "stack" { | ||
type = string | ||
description = "Name to differentiate applications deployed in the same infrastructure environment" | ||
default = "" | ||
} | ||
|
||
variable "subnet_group_name" { | ||
type = string | ||
default = "db_subnet_group" | ||
} | ||
|
||
variable "allocated_storage" { | ||
|
||
|
||
} | ||
|
||
variable "db_engine" { | ||
|
||
|
||
} | ||
|
||
variable "db_engine_version" { | ||
|
||
|
||
} | ||
|
||
variable "db_instance_class" { | ||
|
||
|
||
} | ||
|
||
variable "db_name" { | ||
|
||
|
||
} | ||
|
||
variable "db_username" { | ||
|
||
|
||
} | ||
|
||
variable "vpc_security_group_ids" { | ||
type = list(string) | ||
} | ||
|
||
variable "snapshot_identifier" { | ||
type = string | ||
default = "" | ||
} |