@@ -2,6 +2,10 @@ variable "name" {
2
2
description = " RDS instance name"
3
3
}
4
4
5
+ variable "environment" {
6
+ description = " Environment tag, e.g prod, if missing defaults to name"
7
+ }
8
+
5
9
variable "engine" {
6
10
description = " Database engine: mysql, postgres, etc."
7
11
default = " postgres"
@@ -112,6 +116,10 @@ variable "subnet_ids" {
112
116
type = " list"
113
117
}
114
118
119
+ locals {
120
+ environment = " ${ coalesce (var. environment , var. name )} "
121
+ }
122
+
115
123
resource "aws_security_group" "main" {
116
124
name = " ${ var . name } -rds"
117
125
description = " Allows traffic to RDS from other security groups"
@@ -139,14 +147,20 @@ resource "aws_security_group" "main" {
139
147
}
140
148
141
149
tags {
142
- Name = " RDS (${ var . name } )"
150
+ Name = " RDS ${ var . name } "
151
+ Environment = " ${ local . environment } "
143
152
}
144
153
}
145
154
146
155
resource "aws_db_subnet_group" "main" {
147
156
name = " ${ var . name } "
148
157
description = " RDS subnet group"
149
158
subnet_ids = [" ${ var . subnet_ids } " ]
159
+
160
+ tags {
161
+ Name = " RDS Subnet ${ var . name } "
162
+ Environment = " ${ local . environment } "
163
+ }
150
164
}
151
165
152
166
resource "aws_db_instance" "main" {
@@ -179,6 +193,11 @@ resource "aws_db_instance" "main" {
179
193
db_subnet_group_name = " ${ aws_db_subnet_group . main . id } "
180
194
vpc_security_group_ids = [" ${ aws_security_group . main . id } " ]
181
195
publicly_accessible = " ${ var . publicly_accessible } "
196
+
197
+ tags {
198
+ Name = " RDS Instance ${ var . name } "
199
+ Environment = " ${ local . environment } "
200
+ }
182
201
}
183
202
184
203
output "addr" {
0 commit comments