Skip to content

Commit 81895e7

Browse files
committed
Added IGW route for DB subnets (based on #179)
1 parent 57604d2 commit 81895e7

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
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 |

examples/complete-vpc/main.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ module "vpc" {
1717
redshift_subnets = ["10.10.41.0/24", "10.10.42.0/24", "10.10.43.0/24"]
1818
intra_subnets = ["10.10.51.0/24", "10.10.52.0/24", "10.10.53.0/24"]
1919

20-
create_database_subnet_group = false
20+
create_database_subnet_group = true
21+
create_database_subnet_route_table = true
22+
create_database_internet_gateway_route = true
2123

2224
enable_nat_gateway = true
2325
single_nat_gateway = true
2426

2527
enable_vpn_gateway = true
2628

29+
enable_dns_hostnames = true
30+
enable_dns_support = true
31+
2732
enable_s3_endpoint = true
2833
enable_dynamodb_endpoint = true
2934

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)