Skip to content

Commit 44bb589

Browse files
authored
Merge pull request #191 from terraform-aws-modules/feature-db-igw-public-access
Added IGW route for DB subnets (based on #179)
2 parents 57604d2 + 14b4237 commit 44bb589

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,19 @@ module "vpc" {
150150
}
151151
```
152152

153+
## Public access to RDS instances
154+
155+
Sometimes it is handy to have public access to RDS instances (it is not recommended for production) by specifying these arguments:
156+
157+
```hcl
158+
create_database_subnet_group = true
159+
create_database_subnet_route_table = true
160+
create_database_internet_gateway_route = true
161+
162+
enable_dns_hostnames = true
163+
enable_dns_support = true
164+
```
165+
153166
## Terraform version
154167

155168
Terraform version 0.10.3 or newer is required for this module to work.
@@ -170,6 +183,7 @@ Terraform version 0.10.3 or newer is required for this module to work.
170183
| assign\_generated\_ipv6\_cidr\_block | Requests an Amazon-provided IPv6 CIDR block with a /56 prefix length for the VPC. You cannot specify the range of IP addresses, or the size of the CIDR block | string | `false` | no |
171184
| azs | A list of availability zones in the region | list | `[]` | no |
172185
| cidr | The CIDR block for the VPC. Default value is a valid CIDR, but not acceptable by AWS and should be overridden | string | `0.0.0.0/0` | no |
186+
| create\_database\_internet\_gateway\_route | Controls if an internet gateway route for public database access should be created | string | `false` | no |
173187
| create\_database\_subnet\_group | Controls if database subnet group should be created | string | `true` | no |
174188
| create\_database\_subnet\_route\_table | Controls if separate route table for database should be created | string | `false` | no |
175189
| create\_elasticache\_subnet\_route\_table | Controls if separate route table for elasticache should be created | string | `false` | no |

main.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ resource "aws_route_table" "database" {
121121
tags = "${merge(var.tags, var.database_route_table_tags, map("Name", "${var.name}-${var.database_subnet_suffix}"))}"
122122
}
123123

124+
resource "aws_route" "database_internet_gateway" {
125+
count = "${var.create_vpc && var.create_database_subnet_route_table && length(var.database_subnets) > 0 && var.create_database_internet_gateway_route ? 1 : 0}"
126+
127+
route_table_id = "${aws_route_table.database.id}"
128+
destination_cidr_block = "0.0.0.0/0"
129+
gateway_id = "${aws_internet_gateway.this.id}"
130+
131+
timeouts {
132+
create = "5m"
133+
}
134+
}
135+
124136
#################
125137
# Redshift routes
126138
#################

variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ variable "create_database_subnet_group" {
107107
default = true
108108
}
109109

110+
variable "create_database_internet_gateway_route" {
111+
description = "Controls if an internet gateway route for public database access should be created"
112+
default = false
113+
}
114+
110115
variable "azs" {
111116
description = "A list of availability zones in the region"
112117
default = []

0 commit comments

Comments
 (0)