Skip to content

Commit b8097b5

Browse files
committed
[TEC-56][Added] - VPC endpoints
1 parent 7fc80c6 commit b8097b5

File tree

5 files changed

+93
-53
lines changed

5 files changed

+93
-53
lines changed

environments/dev/vpc/main.tf

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,31 @@ terraform {
22
backend "s3" {}
33
}
44
provider "aws" {
5-
region = "us-west-2"
5+
region = var.region
66
}
77

88
module "vpc" {
9-
source = "../../../modules/vpc"
10-
region = var.region
11-
vpc_cidr_block = var.vpc_cidr_block
12-
instance_tenancy = var.instance_tenancy
13-
enable_dns_support = var.enable_dns_support
14-
enable_dns_hostnames = var.enable_dns_hostnames
15-
domain = var.domain
16-
create_nat_gateway = var.create_nat_gateway
17-
destination_cidr_block = var.destination_cidr_block
18-
map_public_ip_on_launch = var.map_public_ip_on_launch
19-
public_subnet_cidr_blocks = var.public_subnet_cidr_blocks
20-
app_subnet_cidr_blocks = var.app_subnet_cidr_blocks
21-
db_subnet_cidr_blocks = var.db_subnet_cidr_blocks
22-
management_subnet_cidr_blocks = var.management_subnet_cidr_blocks
23-
platform_subnet_cidr_blocks = var.platform_subnet_cidr_blocks
24-
availability_zones = var.availability_zones
25-
owner = var.owner
26-
environment = var.environment
27-
cost_center = var.cost_center
28-
application = var.application
9+
source = "../../../modules/vpc"
10+
region = var.region
11+
vpc_cidr_block = var.vpc_cidr_block
12+
instance_tenancy = var.instance_tenancy
13+
enable_dns_support = var.enable_dns_support
14+
enable_dns_hostnames = var.enable_dns_hostnames
15+
domain = var.domain
16+
create_nat_gateway = var.create_nat_gateway
17+
destination_cidr_block = var.destination_cidr_block
18+
map_public_ip_on_launch = var.map_public_ip_on_launch
19+
public_subnet_cidr_blocks = var.public_subnet_cidr_blocks
20+
app_subnet_cidr_blocks = var.app_subnet_cidr_blocks
21+
db_subnet_cidr_blocks = var.db_subnet_cidr_blocks
22+
management_subnet_cidr_blocks = var.management_subnet_cidr_blocks
23+
platform_subnet_cidr_blocks = var.platform_subnet_cidr_blocks
24+
availability_zones = var.availability_zones
25+
create_s3_endpoint = var.create_s3_endpoint
26+
create_secrets_manager_endpoint = var.create_secrets_manager_endpoint
27+
create_cloudwatch_logs_endpoint = var.create_cloudwatch_logs_endpoint
28+
owner = var.owner
29+
environment = var.environment
30+
cost_center = var.cost_center
31+
application = var.application
2932
}

environments/dev/vpc/variables.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,18 @@ variable "map_public_ip_on_launch" {
105105
description = "whether to map public ip on launch or not"
106106
}
107107

108+
variable "create_s3_endpoint" {
109+
type = bool
110+
description = "whether to create s3 endpoint or not"
111+
}
112+
113+
variable "create_secrets_manager_endpoint" {
114+
type = bool
115+
description = "whether to create secrets-manager endpoint or not"
116+
}
117+
118+
variable "create_cloudwatch_logs_endpoint" {
119+
type = bool
120+
description = "whether to create cloudwatch logs endpoint or not"
121+
}
108122

modules/vpc/endpoint.tf

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
resource "aws_vpc_endpoint" "s3" {
2-
vpc_id = aws_vpc.main.id
3-
service_name = "com.amazonaws.${var.region}.s3"
4-
vpc_endpoint_type = "Interface"
2+
count = var.create_s3_endpoint ? 1 : 0
3+
vpc_id = aws_vpc.main.id
4+
service_name = "com.amazonaws.${var.region}.s3"
5+
vpc_endpoint_type = "Interface"
56

6-
subnet_ids = concat(
7+
subnet_ids = concat(
78
aws_subnet.platform[*].id
89
)
910
tags = merge(
@@ -19,11 +20,12 @@ resource "aws_vpc_endpoint" "s3" {
1920
}
2021

2122
resource "aws_vpc_endpoint" "secrets_manager" {
22-
vpc_id = aws_vpc.main.id
23-
service_name = "com.amazonaws.${var.region}.secretsmanager"
24-
vpc_endpoint_type = "Interface"
23+
count = var.create_secrets_manager_endpoint ? 1 : 0
24+
vpc_id = aws_vpc.main.id
25+
service_name = "com.amazonaws.${var.region}.secretsmanager"
26+
vpc_endpoint_type = "Interface"
2527

26-
subnet_ids = concat(
28+
subnet_ids = concat(
2729
aws_subnet.platform[*].id
2830
)
2931
tags = merge(
@@ -39,11 +41,12 @@ resource "aws_vpc_endpoint" "secrets_manager" {
3941
}
4042

4143
resource "aws_vpc_endpoint" "cloudwatch_logs" {
42-
vpc_id = aws_vpc.main.id
43-
service_name = "com.amazonaws.${var.region}.logs"
44-
vpc_endpoint_type = "Interface"
44+
count = var.create_cloudwatch_logs_endpoint ? 1 : 0
45+
vpc_id = aws_vpc.main.id
46+
service_name = "com.amazonaws.${var.region}.logs"
47+
vpc_endpoint_type = "Interface"
4548

46-
subnet_ids = concat(
49+
subnet_ids = concat(
4750
aws_subnet.platform[*].id
4851
)
4952
tags = merge(
@@ -56,4 +59,4 @@ resource "aws_vpc_endpoint" "cloudwatch_logs" {
5659
},
5760
var.tags
5861
)
59-
}
62+
}

modules/vpc/variables.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,19 @@ variable "destination_cidr_block" {
103103
variable "map_public_ip_on_launch" {
104104
type = bool
105105
description = "whether to map public ip on launch or not"
106+
}
107+
108+
variable "create_s3_endpoint" {
109+
type = bool
110+
description = "whether to create s3 endpoint or not"
111+
}
112+
113+
variable "create_secrets_manager_endpoint" {
114+
type = bool
115+
description = "whether to create secrets-manager endpoint or not"
116+
}
117+
118+
variable "create_cloudwatch_logs_endpoint" {
119+
type = bool
120+
description = "whether to create cloudwatch logs endpoint or not"
106121
}

vars/dev/vpc.tfvars

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11
#vpc
2-
region = "us-west-2"
3-
vpc_cidr_block = "10.0.0.0/16"
4-
instance_tenancy = "default"
5-
enable_dns_support = true
6-
enable_dns_hostnames = true
2+
region = "us-west-2"
3+
vpc_cidr_block = "10.0.0.0/16"
4+
instance_tenancy = "default"
5+
enable_dns_support = true
6+
enable_dns_hostnames = true
77

88
#elastic ip
9-
domain = "vpc"
9+
domain = "vpc"
1010

1111
#nat-gateway
12-
create_nat_gateway = false
12+
create_nat_gateway = false
1313

1414
#route-table
15-
destination_cidr_block = "0.0.0.0/0"
15+
destination_cidr_block = "0.0.0.0/0"
1616

1717
#subnet
18-
map_public_ip_on_launch = true
19-
public_subnet_cidr_blocks = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
20-
app_subnet_cidr_blocks = ["10.0.4.0/24", "10.0.5.0/24", "10.0.6.0/24"]
21-
db_subnet_cidr_blocks = ["10.0.7.0/24", "10.0.8.0/24", "10.0.9.0/24"]
22-
management_subnet_cidr_blocks = ["10.0.10.0/24", "10.0.11.0/24", "10.0.12.0/24"]
23-
platform_subnet_cidr_blocks = ["10.0.13.0/24", "10.0.14.0/24", "10.0.15.0/24"]
24-
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
18+
map_public_ip_on_launch = true
19+
public_subnet_cidr_blocks = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
20+
app_subnet_cidr_blocks = ["10.0.4.0/24", "10.0.5.0/24", "10.0.6.0/24"]
21+
db_subnet_cidr_blocks = ["10.0.7.0/24", "10.0.8.0/24", "10.0.9.0/24"]
22+
management_subnet_cidr_blocks = ["10.0.10.0/24", "10.0.11.0/24", "10.0.12.0/24"]
23+
platform_subnet_cidr_blocks = ["10.0.13.0/24", "10.0.14.0/24", "10.0.15.0/24"]
24+
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
25+
26+
#endpoint
27+
create_s3_endpoint = true
28+
create_secrets_manager_endpoint = true
29+
create_cloudwatch_logs_endpoint = true
2530

2631
#tags
27-
owner = "techiescamp"
28-
environment = "dev"
29-
cost_center = "techiescamp-commerce"
30-
application = "vpc"
32+
owner = "techiescamp"
33+
environment = "dev"
34+
cost_center = "techiescamp-commerce"
35+
application = "vpc"

0 commit comments

Comments
 (0)