@@ -29,74 +29,18 @@ module "service" {
2929 create_version_parameter = true
3030
3131 environment_variables = {
32- DATABASE_HOST = module.mssql.db_instance_endpoint
32+ DATABASE_HOST = module.database.host
33+ DATABASE_PORT = module.database.port
3334 }
3435
3536 environment_secrets = {
36- DATABASE_USERNAME = " ${ module . mssql . db_instance_master_user_secret_arn } :username"
37- DATABASE_PASSWORD = " ${ module . mssql . db_instance_master_user_secret_arn } :password"
37+ DATABASE_USERNAME = " ${ module . database . secret_arn } :username"
38+ DATABASE_PASSWORD = " ${ module . database . secret_arn } :password"
3839 }
3940
4041 tags = local. tags
4142}
4243
43- module "mssql" {
44- source = " terraform-aws-modules/rds/aws"
45- version = " >= 6.12"
46-
47- identifier = local. prefix
48- instance_use_identifier_prefix = true
49- engine = local. database_engine
50- engine_version = data. aws_rds_engine_version . this . version
51- auto_minor_version_upgrade = true
52- apply_immediately = ! local. production
53- subnet_ids = var. private_subnets
54- create_db_subnet_group = true
55- create_db_option_group = false
56- family = data. aws_rds_engine_version . this . parameter_group_family
57- instance_class = " db.t3.small"
58- allocated_storage = 20
59- max_allocated_storage = 100
60- username = " root"
61- storage_type = " gp3"
62- kms_key_id = aws_kms_key. database . arn
63- master_user_secret_kms_key_id = module. secrets . kms_key_arn
64- performance_insights_kms_key_id = var. logging_key_arn
65- cloudwatch_log_group_kms_key_id = var. logging_key_arn
66- cloudwatch_log_group_retention_in_days = local. production ? 31 : 7
67- create_cloudwatch_log_group = true
68- create_monitoring_role = true
69- enabled_cloudwatch_logs_exports = data. aws_rds_engine_version . this . exportable_log_types
70- vpc_security_group_ids = [module . database_security_group . security_group_id ]
71-
72- allow_major_version_upgrade = ! local. production
73-
74- tags = local. tags
75- }
76-
77- # Create an empty security group for the database. To avoid a circular
78- # dependency between the database and the services, we create the security group
79- # here and then add the ingress rules in a separate resource.
80- module "database_security_group" {
81- source = " terraform-aws-modules/security-group/aws"
82- version = " ~> 5.3"
83-
84- name = " ${ local . prefix } -database"
85- vpc_id = var. vpc_id
86-
87- tags = local. tags
88- }
89-
90- resource "aws_vpc_security_group_ingress_rule" "database" {
91- for_each = module. service
92- security_group_id = module. database_security_group . security_group_id
93-
94- ip_protocol = " tcp"
95- from_port = module. mssql . db_instance_port
96- to_port = module. mssql . db_instance_port
97- referenced_security_group_id = each. value . security_group_id
98- }
99-
10044resource "aws_cloudwatch_log_subscription_filter" "datadog" {
10145 depends_on = [module . service ]
10246 for_each = length (local. datadog_lambda ) > 0 ? local. log_groups : toset ([])
0 commit comments