-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
executable file
·59 lines (46 loc) · 1.57 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
provider "aws" {
region = "ap-south-1"
}
resource "aws_key_pair" "deployer" {
key_name = "deployer-key"
public_key = var.deployer-public-key
}
resource "aws_instance" "master" {
ami = var.ami_id
instance_type = var.worker_instance_type
key_name = aws_key_pair.deployer.key_name
user_data = templatefile("data/main-server.tmpl", {
})
}
resource "null_resource" "echo_master_ip" {
provisioner "local-exec" {
command = "sleep 210s && echo ${aws_instance.master.public_ip}"
}
}
resource "null_resource" "copy-kubeconfig" {
provisioner "local-exec" {
command = "scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ec2-user@${aws_instance.master.public_ip}:/home/ec2-user/k3s.yaml ./k3s-kubeconfig.yaml"
}
depends_on = [null_resource.echo_master_ip]
}
resource "null_resource" "copy-nodetoken" {
provisioner "local-exec" {
command = "scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ec2-user@${aws_instance.master.public_ip}:/home/ec2-user/node-token ./node-token"
}
depends_on = [null_resource.echo_master_ip]
}
### Install worker node
resource "aws_instance" "worker-node" {
ami = var.ami_id
instance_type = var.worker_instance_type
key_name = aws_key_pair.deployer.key_name
user_data = templatefile("data/agent-server.tmpl", {
master_ip = aws_instance.master.public_ip,
master_local_ip = aws_instance.master.private_ip,
node_token = var.k3s_token,
cluster_name = var.cluster_name,
})
}
output "Master_public_ip" {
value = aws_instance.master.public_ip
}