1
- data "aws_availability_zones" "available" {}
2
-
3
1
data "aws_eks_cluster_auth" "this" {
4
2
count = var. enable_eks ? 1 : 0
5
3
name = module. comet_eks [0 ]. cluster_name
6
4
}
7
5
8
6
locals {
9
7
resource_name = " comet-${ var . environment } "
10
- vpc_cidr = " 10.0.0.0/16"
11
- azs = slice (data. aws_availability_zones . available . names , 0 , 3 )
12
8
13
9
# set environment here, and use local.environment for the environment variables in all of the module calls
14
-
15
10
tags = {
16
11
Terraform = " true"
17
12
Environment = var.environment
18
13
}
19
14
}
20
15
21
- module "vpc" {
22
- source = " terraform-aws-modules/vpc/aws"
23
- version = " ~> 5.0.0"
24
-
25
- name = local. resource_name
26
- cidr = local. vpc_cidr
27
-
28
- azs = local. azs
29
- public_subnets = [for k , v in local . azs : cidrsubnet (local. vpc_cidr , 8 , k)]
30
- private_subnets = [for k , v in local . azs : cidrsubnet (local. vpc_cidr , 8 , k + 10 )]
31
-
32
- enable_nat_gateway = true
33
- single_nat_gateway = true
34
- enable_dns_hostnames = true
35
-
36
- # Manage so we can name
37
- manage_default_network_acl = true
38
- default_network_acl_tags = { Name = " ${ local . resource_name } -default" }
39
- manage_default_route_table = true
40
- default_route_table_tags = { Name = " ${ local . resource_name } -default" }
41
- manage_default_security_group = true
42
- default_security_group_tags = { Name = " ${ local . resource_name } -default" }
43
-
44
- # if EKS deployment, set subnet tags for AWS Load Balancer Controller auto-discovery
45
- public_subnet_tags = var. enable_eks ? {" kubernetes.io/role/elb" = 1 } : null
46
- private_subnet_tags = var. enable_eks ? {" kubernetes.io/role/internal-elb" = 1 } : null
47
-
48
- tags = local. tags
16
+ module "comet_vpc" {
17
+ source = " ./modules/comet_vpc"
18
+ count = var. enable_vpc ? 1 : 0
19
+ environment = var. environment
20
+
21
+ eks_enabled = var. enable_eks
22
+ single_nat_gateway = var. single_nat_gateway
49
23
}
50
24
51
25
module "comet_ec2" {
52
26
source = " ./modules/comet_ec2"
53
27
count = var. enable_ec2 ? 1 : 0
54
28
environment = var. environment
55
29
56
- vpc_id = module. vpc . vpc_id
57
- comet_ec2_subnet = module. vpc . public_subnets [count . index % length (module . vpc . public_subnets ) ]
30
+ vpc_id = var . enable_vpc ? module. comet_vpc [ 0 ] . vpc_id : var . comet_vpc_id
31
+ comet_ec2_subnet = var . enable_vpc ? module. comet_vpc [ 0 ] . public_subnets [0 ] : var . comet_public_subnets [ 0 ]
58
32
comet_ec2_ami_type = var. comet_ec2_ami_type
59
33
comet_ec2_instance_type = var. comet_ec2_instance_type
60
34
comet_ec2_instance_count = var. comet_ec2_instance_count
@@ -74,8 +48,8 @@ module "comet_ec2_alb" {
74
48
count = var. enable_ec2_alb ? 1 : 0
75
49
environment = var. environment
76
50
77
- vpc_id = module. vpc . vpc_id
78
- public_subnets = module. vpc . public_subnets
51
+ vpc_id = var . enable_vpc ? module. comet_vpc [ 0 ] . vpc_id : var . comet_vpc_id
52
+ public_subnets = var . enable_vpc ? module. comet_vpc [ 0 ] . public_subnets : var . comet_public_subnets
79
53
ssl_certificate_arn = var. enable_ec2_alb ? var. ssl_certificate_arn : null
80
54
}
81
55
@@ -84,8 +58,8 @@ module "comet_eks" {
84
58
count = var. enable_eks ? 1 : 0
85
59
environment = var. environment
86
60
87
- vpc_id = module. vpc . vpc_id
88
- eks_private_subnets = module. vpc . private_subnets
61
+ vpc_id = var . enable_vpc ? module. comet_vpc [ 0 ] . vpc_id : var . comet_vpc_id
62
+ eks_private_subnets = var . enable_vpc ? module. comet_vpc [ 0 ] . private_subnets : var . comet_private_subnets
89
63
eks_cluster_name = var. eks_cluster_name
90
64
eks_cluster_version = var. eks_cluster_version
91
65
eks_mng_name = var. eks_mng_name
@@ -110,8 +84,8 @@ module "comet_elasticache" {
110
84
ec2_enabled = var. enable_ec2
111
85
eks_enabled = var. enable_eks
112
86
113
- vpc_id = module. vpc . vpc_id
114
- elasticache_private_subnets = module. vpc . private_subnets
87
+ vpc_id = var . enable_vpc ? module. comet_vpc [ 0 ] . vpc_id : var . comet_vpc_id
88
+ elasticache_private_subnets = var . enable_vpc ? module. comet_vpc [ 0 ] . private_subnets : var . comet_private_subnets
115
89
elasticache_allow_ec2_sg = var. enable_ec2 ? module. comet_ec2 [0 ]. comet_ec2_sg_id : null
116
90
elasticache_allow_eks_sg = var. enable_eks ? module. comet_eks [0 ]. nodegroup_sg_id : null
117
91
elasticache_engine = var. elasticache_engine
@@ -129,9 +103,9 @@ module "comet_rds" {
129
103
ec2_enabled = var. enable_ec2
130
104
eks_enabled = var. enable_eks
131
105
132
- availability_zones = local . azs
133
- vpc_id = module. vpc . vpc_id
134
- rds_private_subnets = module. vpc . private_subnets
106
+ availability_zones = var . enable_vpc ? module . comet_vpc [ 0 ] . azs : var . availability_zones
107
+ vpc_id = var . enable_vpc ? module. comet_vpc [ 0 ] . vpc_id : var . comet_vpc_id
108
+ rds_private_subnets = var . enable_vpc ? module. comet_vpc [ 0 ] . private_subnets : var . comet_private_subnets
135
109
rds_allow_ec2_sg = var. enable_ec2 ? module. comet_ec2 [0 ]. comet_ec2_sg_id : null
136
110
rds_allow_eks_sg = var. enable_eks ? module. comet_eks [0 ]. nodegroup_sg_id : null
137
111
rds_engine = var. rds_engine
0 commit comments