Skip to content

Commit 2ca5962

Browse files
committed
Added option to upload secret to secret mannager
1 parent b6048e5 commit 2ca5962

File tree

6 files changed

+56
-31
lines changed

6 files changed

+56
-31
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ module "mysql" {
2121
source = "squareops/mysql/kubernetes"
2222
cluster_name = "dev-cluster"
2323
mysqldb_config = {
24-
name = "mysql"
25-
values_yaml = ""
26-
environment = "prod"
27-
architecture = "replication"
28-
storage_class_name = "gp3"
29-
custom_user_username = "admin"
30-
primary_db_volume_size = "10Gi"
31-
secondary_db_volume_size = "10Gi"
32-
secondary_db_replica_count = 2
24+
name = "mysql"
25+
values_yaml = ""
26+
environment = "prod"
27+
architecture = "replication"
28+
storage_class_name = "gp3"
29+
custom_user_username = "admin"
30+
primary_db_volume_size = "10Gi"
31+
secondary_db_volume_size = "10Gi"
32+
secondary_db_replica_count = 2
33+
store_password_to_secret_manager = true
3334
}
3435
mysqldb_backup_enabled = true
3536
mysqldb_backup_config = {

examples/complete/main.tf

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,23 @@ locals {
77
Expires = "Never"
88
Department = "Engineering"
99
}
10+
store_password_to_secret_manager = true
1011
}
1112

1213
module "mysql" {
1314
source = "squareops/mysql/kubernetes"
1415
cluster_name = ""
1516
mysqldb_config = {
16-
name = local.name
17-
values_yaml = file("./helm/values.yaml")
18-
environment = local.environment
19-
architecture = "replication"
20-
storage_class_name = "gp3"
21-
custom_user_username = "admin"
22-
primary_db_volume_size = "10Gi"
23-
secondary_db_volume_size = "10Gi"
24-
secondary_db_replica_count = 2
17+
name = local.name
18+
values_yaml = file("./helm/values.yaml")
19+
environment = local.environment
20+
architecture = "replication"
21+
storage_class_name = "gp3"
22+
custom_user_username = "admin"
23+
primary_db_volume_size = "10Gi"
24+
secondary_db_volume_size = "10Gi"
25+
secondary_db_replica_count = 2
26+
store_password_to_secret_manager = local.store_password_to_secret_manager
2527
}
2628
mysqldb_backup_enabled = true
2729
mysqldb_backup_config = {

examples/complete/output.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
output "mysql_configuration" {
2-
value = module.mysql.mysqldb
2+
value = module.mysql.mysqldb_endpoints
3+
description = "Mysql_Info"
4+
}
5+
6+
output "mysql_credential" {
7+
value = local.store_password_to_secret_manager ? null : module.mysql.mysqldb_credential
38
description = "Mysql_Info"
49
}

main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ resource "random_password" "mysqldb_exporter_user_password" {
3333
}
3434

3535
resource "aws_secretsmanager_secret" "mysql_user_password" {
36+
count = var.mysqldb_config.store_password_to_secret_manager ? 1 : 0
3637
name = format("%s/%s/%s", var.mysqldb_config.environment, var.mysqldb_config.name, "mysql")
3738
recovery_window_in_days = var.recovery_window_aws_secret
3839
}
3940

4041
resource "aws_secretsmanager_secret_version" "mysql_user_password" {
41-
secret_id = aws_secretsmanager_secret.mysql_user_password.id
42+
count = var.mysqldb_config.store_password_to_secret_manager ? 1 : 0
43+
secret_id = aws_secretsmanager_secret.mysql_user_password[0].id
4244
secret_string = <<EOF
4345
{
4446
"root_user": "root",

output.tf

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1-
output "mysqldb" {
1+
output "mysqldb_endpoints" {
22
description = "Mysql_Info"
33
value = {
44
mysqlport = "3306",
55
mysql_primary_endpoint = "mysqldb-primary.${var.namespace}.svc.cluster.local",
66
mysql_primary_headless_endpoint = "mysqldb-primary-headless.${var.namespace}.svc.cluster.local",
77
mysql_secondary_endpoint = "mysqldb-secondary.${var.namespace}.svc.cluster.local",
8-
mysql_secondary_headless_endpoint = "mysqldb-secondary-headless.${var.namespace}.svc.cluster.local"
8+
mysql_secondary_headless_endpoint = "mysqldb-secondary-headless.${var.namespace}.svc.cluster.local",
9+
}
10+
}
11+
12+
output "mysqldb_credential" {
13+
description = "Mysql_Info"
14+
value = var.mysqldb_config.store_password_to_secret_manager ? null : {
15+
root_user = "root",
16+
root_password = nonsensitive(random_password.mysqldb_root_password.result),
17+
custom_username = var.mysqldb_config.custom_user_username,
18+
custom_user_password = nonsensitive(random_password.mysqldb_custom_user_password.result),
19+
replication_user = "replicator",
20+
replication_password = nonsensitive(random_password.mysqldb_replication_user_password.result),
21+
exporter_user = "mysqld_exporter",
22+
exporter_password = nonsensitive(random_password.mysqldb_exporter_user_password.result)
923
}
1024
}

variables.tf

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
variable "mysqldb_config" {
22
type = any
33
default = {
4-
name = ""
5-
environment = ""
6-
values_yaml = ""
7-
architecture = ""
8-
storage_class_name = ""
9-
custom_user_username = ""
10-
primary_db_volume_size = ""
11-
secondary_db_volume_size = ""
12-
secondary_db_replica_count = 1
4+
name = ""
5+
environment = ""
6+
values_yaml = ""
7+
architecture = ""
8+
storage_class_name = ""
9+
custom_user_username = ""
10+
primary_db_volume_size = ""
11+
secondary_db_volume_size = ""
12+
secondary_db_replica_count = 1
13+
store_password_to_secret_manager = true
1314
}
1415
description = "Specify the configuration settings for MySQL, including the name, environment, storage options, replication settings, and custom YAML values."
1516
}

0 commit comments

Comments
 (0)