-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvpc.tf
More file actions
50 lines (45 loc) · 1.68 KB
/
vpc.tf
File metadata and controls
50 lines (45 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones
data "aws_availability_zones" "available" {
state = "available"
}
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc
resource "aws_vpc" "main" {
cidr_block = var.vpc_cidr
enable_dns_hostnames = true
enable_dns_support = true
tags = {
Name = var.name
}
#checkov:skip=CKV2_AWS_11: Ensure VPC flow logging is enabled in all VPCs
#Reason: VPC flow logging is not the primary use case for this project
}
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/subnet
resource "aws_subnet" "private" {
count = length(var.subnet_cidr_private)
vpc_id = aws_vpc.main.id
cidr_block = var.subnet_cidr_private[count.index]
availability_zone = data.aws_availability_zones.available.names[count.index]
tags = {
Name = "${var.name}-private-${count.index + 1}"
}
}
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table
resource "aws_route_table" "private" {
vpc_id = aws_vpc.main.id
tags = {
Name = "${var.name}-private-rt"
}
}
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table_association
resource "aws_route_table_association" "private" {
count = length(var.subnet_cidr_private)
subnet_id = aws_subnet.private[count.index].id
route_table_id = aws_route_table.private.id
}
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/default_security_group
resource "aws_default_security_group" "default" {
vpc_id = aws_vpc.main.id
tags = {
Name = "${var.name}-default-sg"
}
}