Skip to content

Commit 1b27b9d

Browse files
sshi100bmonkman
andauthored
add NAT instance (#169)
* add NAT instance * added NAT instance types for user to override * Update templates/terraform/environments/stage/main.tf Co-authored-by: Bill Monkman <bmonkman@gmail.com> * Update templates/terraform/environments/stage/main.tf Co-authored-by: Bill Monkman <bmonkman@gmail.com> * finalized NAT instance types Co-authored-by: Bill Monkman <bmonkman@gmail.com>
1 parent ab2154b commit 1b27b9d

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

templates/terraform/environments/stage/main.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,12 @@ module "stage" {
102102

103103
domain_name = local.domain_name
104104

105-
# This will save some money as there a cost associated to each NAT gateway, but if the AZ with the gateway
106-
# goes down, nothing in the private subnets will be able to reach the internet. Not recommended for production.
105+
# NAT configuration - NAT allows traffic from private subnets to access the public internet
106+
107+
## Instead of using AWS NAT gateway, use a NAT instance which is cheaper by about $30/month, though NAT gateways are more reliable. Only recommended for non-production environments.
108+
vpc_enable_nat_gateway = false
109+
110+
## When using NAT gateway, setting this to true will save some money as there a cost per-gateway of about $35/month. However, if the AZ with the gateway goes down nothing in the private subnets will be able to reach the internet. Not recommended for production. Not used if `vpc_enable_nat_gateway` is `false`.
107111
vpc_use_single_nat_gateway = true
108112

109113
# DB configuration

templates/terraform/modules/environment/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ data "aws_iam_user" "ci_user" {
3838

3939
module "vpc" {
4040
source = "commitdev/zero/aws//modules/vpc"
41-
version = "0.1.11"
41+
version = "0.1.14"
4242

4343
project = var.project
4444
environment = var.environment
4545
region = var.region
4646
kubernetes_cluster_name = local.kubernetes_cluster_name
47+
enable_nat_gateway = var.vpc_enable_nat_gateway
4748
single_nat_gateway = var.vpc_use_single_nat_gateway
49+
nat_instance_types = var.vpc_nat_instance_types
4850
}
4951

5052
# To get the current account id

templates/terraform/modules/environment/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,24 @@ variable "db_storage_gb" {
6868
description = "The amount of storage to allocate for the db, in GB"
6969
}
7070

71+
variable "vpc_enable_nat_gateway" {
72+
description = "Enable nat-gateway"
73+
type = bool
74+
default = true
75+
}
76+
7177
variable "vpc_use_single_nat_gateway" {
7278
description = "Use single nat-gateway instead of nat-gateway per subnet"
7379
type = bool
7480
default = true
7581
}
7682

83+
variable "vpc_nat_instance_types" {
84+
description = "Candidates of instance type for the NAT instance"
85+
type = list
86+
default = ["t3.nano"]
87+
}
88+
7789
variable "database" {
7890
default = "postgres"
7991
description = "Which database engine to use, currently supports postgres or mysql"

0 commit comments

Comments
 (0)