-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpc-admission-webhook-deploy.tf
112 lines (103 loc) · 2.84 KB
/
vpc-admission-webhook-deploy.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# This data section will collect the existing EKS cluster CA cert data and other informaiton to be used in other section.
data "aws_eks_cluster" "cluster" {
name = var.cluster_name
}
resource "kubernetes_service" "vpc_admission_webhook_svc" {
metadata {
name = "vpc-admission-webhook-svc"
namespace = "kube-system"
labels = {
app = "vpc-admission-webhook"
}
}
spec {
port {
port = 443
target_port = "443"
}
selector = {
app = "vpc-admission-webhook"
}
}
}
resource "kubernetes_deployment" "vpc_admission_webhook_deployment" {
metadata {
name = "vpc-admission-webhook-deployment"
namespace = "kube-system"
labels = {
app = "vpc-admission-webhook"
}
}
spec {
replicas = 1
selector {
match_labels = {
app = "vpc-admission-webhook"
}
}
template {
metadata {
labels = {
app = "vpc-admission-webhook"
}
}
spec {
volume {
name = "webhook-certs"
secret {
secret_name = "vpc-admission-webhook-certs"
}
}
container {
name = "vpc-admission-webhook"
image = "602401143452.dkr.ecr.us-west-2.amazonaws.com/eks/vpc-admission-webhook:v0.2.7"
args = ["-tlsCertFile=/etc/webhook/certs/cert.pem", "-tlsKeyFile=/etc/webhook/certs/key.pem", "-OSLabelSelectorOverride=windows", "-alsologtostderr", "-v=4", "2>&1"]
volume_mount {
name = "webhook-certs"
read_only = true
mount_path = "/etc/webhook/certs"
}
image_pull_policy = "Always"
}
node_selector = {
"beta.kubernetes.io/arch" = "amd64"
"beta.kubernetes.io/os" = "linux"
}
host_network = true
}
}
strategy {
type = "Recreate"
}
}
depends_on = [null_resource.create-signed-cert, kubernetes_deployment.vpc_resource_controller]
}
resource "kubernetes_mutating_webhook_configuration" "vpc_admission_webhook_cfg" {
metadata {
name = "vpc-admission-webhook-cfg"
labels = {
app = "vpc-admission-webhook"
}
}
webhook {
name = "vpc-admission-webhook.amazonaws.com"
admission_review_versions = ["v1", "v1beta1"]
client_config {
service {
namespace = "kube-system"
name = "vpc-admission-webhook-svc"
path = "/mutate"
}
ca_bundle = data.aws_eks_cluster.cluster.certificate_authority[0].data
}
rule {
operations = ["CREATE"]
api_groups = [""]
api_versions = ["v1"]
resources = ["pods"]
}
failure_policy = "Ignore"
side_effects = "None"
}
depends_on = [null_resource.create-signed-cert, kubernetes_service.vpc_admission_webhook_svc]
}