-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
43 lines (35 loc) · 1.03 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
locals {
kubeconfig_path = "${pathexpand("${var.kubeconfig}/${var.cluster_name}-${var.region}")}"
}
data "template_file" "aws_auth_cm" {
template = "${file("${path.module}/templates/aws-auth-cm.tpl")}"
vars {
rolearn = "${var.role}"
}
}
data "template_file" "kubeconfig" {
template = "${file("${path.module}/templates/kubeconfig.tpl")}"
vars {
endpoint = "${var.cluster_endpoint}"
ca = "${var.cluster_ca}"
cluster_name = "${var.cluster_name}"
region = "${var.region}"
}
}
resource "local_file" "kubeconfig" {
content = "${data.template_file.kubeconfig.rendered}"
filename = "${local.kubeconfig_path}"
}
resource "local_file" "aws_auth_cm" {
content = "${data.template_file.aws_auth_cm.rendered}"
filename = "/tmp/aws-auth-cm.yaml"
}
resource "null_resource" "join_cluster" {
provisioner "local-exec" {
command = "kubectl --kubeconfig=${local.kubeconfig_path} apply -f /tmp/aws-auth-cm.yaml"
}
depends_on = [
"local_file.aws_auth_cm",
"local_file.kubeconfig",
]
}