forked from provectus/sak-vpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
59 lines (47 loc) · 1.97 KB
/
main.tf
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
51
52
53
54
55
56
57
58
59
locals {
zones = coalescelist(var.availability_zones, data.aws_availability_zones.available.names)
cidr = var.cidr != null ? var.cidr : "10.${var.network}.0.0/16"
private = var.cidr != null ? [for i, z in local.zones : cidrsubnet(local.cidr, var.network_delimiter, i)] : data.template_file.private.*.rendered
public = var.cidr != null ? [for i, z in local.zones : cidrsubnet(local.cidr, var.network_delimiter, pow(2, var.network_delimiter) - i)] : data.template_file.public.*.rendered
}
data "aws_availability_zones" "available" {}
data "template_file" "public" {
count = length(local.zones)
template = "10.${var.network}.${count.index}.0/24"
}
data "template_file" "private" {
count = length(local.zones)
template = "10.${var.network}.20${count.index}.0/24"
}
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "v2.64.0"
name = "${var.environment}-${var.cluster_name}"
cidr = local.cidr
azs = local.zones
private_subnets = local.private
public_subnets = local.public
enable_nat_gateway = true
single_nat_gateway = var.single_nat
enable_dns_hostnames = true
enable_dns_support = true
public_subnet_tags = {
Name = "${var.environment}-${var.cluster_name}-public"
KubernetesCluster = var.cluster_name
Environment = var.environment
Project = var.project
"kubernetes.io/role/elb" = ""
"kubernetes.io/cluster/${var.cluster_name}" = "owned"
"kubernetes.io/cluster/${var.cluster_name}" = "shared"
}
private_subnet_tags = {
Name = "${var.environment}-${var.cluster_name}-private"
"kubernetes.io/cluster/${var.cluster_name}" = "shared"
}
tags = {
Name = "${var.environment}-${var.cluster_name}"
Environment = var.environment
Project = var.project
Terraform = "true"
}
}