-
Notifications
You must be signed in to change notification settings - Fork 986
/
main.tf
95 lines (82 loc) · 2.54 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
89
90
91
92
93
94
95
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.0.0"
}
helm = {
source = "hashicorp/helm"
version = ">= 2.0.1"
}
aws = {
source = "hashicorp/aws"
version = "3.22.0"
}
}
}
data "aws_eks_cluster" "default" {
name = module.cluster.cluster_id
}
data "aws_eks_cluster_auth" "default" {
name = module.cluster.cluster_id
}
provider "kubernetes" {
host = data.aws_eks_cluster.default.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.default.certificate_authority[0].data)
exec {
api_version = "client.authentication.k8s.io/v1alpha1"
args = ["eks", "get-token", "--cluster-name", var.cluster_name]
command = "aws"
}
}
# This configuration is also valid, but the token may expire during long-running applies.
#provider "kubernetes" {
# host = data.aws_eks_cluster.default.endpoint
# cluster_ca_certificate = base64decode(data.aws_eks_cluster.default.certificate_authority[0].data)
# token = data.aws_eks_cluster_auth.default.token
#}
provider "helm" {
kubernetes {
host = data.aws_eks_cluster.default.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.default.certificate_authority[0].data)
token = data.aws_eks_cluster_auth.default.token
exec {
api_version = "client.authentication.k8s.io/v1alpha1"
args = ["eks", "get-token", "--cluster-name", var.cluster_name]
command = "aws"
}
}
}
provider "aws" {
region = var.region
}
module "vpc" {
source = "./vpc"
}
module "cluster" {
source = "terraform-aws-modules/eks/aws"
version = "v13.2.1"
vpc_id = module.vpc.vpc_id
subnets = module.vpc.subnets
cluster_name = module.vpc.cluster_name
cluster_version = var.kubernetes_version
manage_aws_auth = false # Managed in ./kubernetes-config/main.tf instead.
# This kubeconfig expires in 15 minutes, so we'll use an exec block instead.
# See ./kubernetes-config/main.tf provider block for details.
write_kubeconfig = false
worker_groups = [
{
instance_type = var.workers_type
asg_desired_capacity = var.workers_count
asg_max_size = "10"
},
]
tags = {
environment = "test"
}
}
module "kubernetes-config" {
cluster_name = module.cluster.cluster_id # creates dependency on cluster creation
source = "./kubernetes-config"
k8s_node_role_arn = module.cluster.worker_iam_role_arn
}