-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
88 lines (69 loc) · 2.5 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Environment entrypoint
locals {
kubernetes_cluster_name = "${var.project}-${var.environment}-${var.region}"
}
module "vpc" {
source = "../../modules/vpc"
project = var.project
environment = var.environment
region = var.region
kubernetes_cluster_name = local.kubernetes_cluster_name
}
# Data sources for EKS IAM
data "aws_caller_identity" "current" {}
data "aws_iam_policy_document" "assumerole_root_policy" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
}
}
}
#
# Provision the EKS cluster
module "eks" {
source = "../../modules/eks"
project = var.project
environment = var.environment
cluster_name = local.kubernetes_cluster_name
iam_account_id = data.aws_caller_identity.current.account_id
assume_role_policy = data.aws_iam_policy_document.assumerole_root_policy.json
private_subnets = module.vpc.private_subnets
vpc_id = module.vpc.vpc_id
worker_instance_type = var.eks_worker_instance_type
worker_asg_min_size = var.eks_worker_asg_min_size
worker_asg_max_size = var.eks_worker_asg_max_size
worker_ami = var.eks_worker_ami # EKS-Optimized AMI for your region: https://docs.aws.amazon.com/eks/latest/userguide/eks-optimized-ami.html
}
module "kube2iam" {
source = "../../modules/kube2iam"
environment = var.environment
eks_worker_iam_role_arn = module.eks.worker_iam_role_arn
eks_worker_iam_role_name = module.eks.worker_iam_role_name
iam_account_id = data.aws_caller_identity.current.account_id
}
data "aws_iam_user" "ci_user" {
user_name = "ci-user" # Should have been created in the bootstrap process
}
module "s3_hosting" {
source = "../../modules/s3_hosting"
buckets = var.s3_hosting_buckets
cert_domain = var.s3_hosting_cert_domain
project = var.project
}
module "db" {
source = "../../modules/database"
project = var.project
environment = var.environment
vpc_id = module.vpc.vpc_id
allowed_security_group_id = module.eks.worker_security_group_id
instance_class = var.db_instance_class
storage_gb = var.db_storage_gb
}
module "ecr" {
source = "../../modules/ecr"
environment = var.environment
ecr_repositories = var.ecr_repositories
ecr_principals = [data.aws_iam_user.ci_user.arn]
}