-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathartifacts.tf
61 lines (56 loc) · 1.69 KB
/
artifacts.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
# create ssh keypair for local node access
resource "tls_private_key" "private_key" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "local_file" "private_key" {
content = tls_private_key.private_key.private_key_pem
filename = "${path.module}/out/aws_private_key.pem"
file_permission = "0600"
}
resource "aws_key_pair" "generated_key" {
key_name = "worker_key"
public_key = tls_private_key.private_key.public_key_openssh
}
# create Kubeconfig file based on below template
data "aws_eks_cluster" "rancher_data" {
name = aws_eks_cluster.rancher_cluster.name
}
data "aws_eks_cluster_auth" "rancher_auth" {
name = aws_eks_cluster.rancher_cluster.name
}
locals {
kubeconfig = <<KUBECONFIG
apiVersion: v1
clusters:
- cluster:
server: ${data.aws_eks_cluster.rancher_data.endpoint}
certificate-authority-data: ${data.aws_eks_cluster.rancher_data.certificate_authority[0].data}
name: ${data.aws_eks_cluster.rancher_data.name}
contexts:
- context:
cluster: ${data.aws_eks_cluster.rancher_data.name}
user: ${data.aws_eks_cluster.rancher_data.name}
name: ${data.aws_eks_cluster.rancher_data.name}
current-context: ${data.aws_eks_cluster.rancher_data.name}
kind: Config
preferences: {}
users:
- name: ${data.aws_eks_cluster.rancher_data.name}
user:
exec:
apiVersion: client.authentication.k8s.io/v1beta1
command: aws
args:
- "eks"
- "get-token"
- "--cluster-name"
- "${data.aws_eks_cluster.rancher_data.name}"
KUBECONFIG
}
# Create the eksRancher.yaml file
resource "local_file" "eks_rancher_config" {
filename = "${path.module}/out/eksRancher.yaml"
content = local.kubeconfig
file_permission = "600"
}