-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathansible.inventory.local_file.resource.tf
37 lines (36 loc) · 1.83 KB
/
ansible.inventory.local_file.resource.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
resource "local_file" "ansible_inventory" {
filename = "${path.module}/ansible_dir/ansible.inventory.cfg"
depends_on = [
aws_lightsail_instance.master,
aws_lightsail_instance.master_lb,
aws_lightsail_instance.worker,
aws_lightsail_instance.worker_lb,
]
file_permission = "0777" # It does not actually work, got -rwxr-xr-x.
# content = templatefile("${path.module}/ansible_inventory.tftpl", {
# aws_lightsail_instances = aws_lightsail_instance.master
# })
content = <<EOT
[masters]
%{ for k, instance in aws_lightsail_instance.master }
master_${k + 1} ansible_host=${instance.public_ip_address} private_ip=${instance.private_ip_address} ansible_user=${instance.username} ansible_ssh_private_key_file=${var.ssh_key_path}.pem
%{ endfor }
[master_lbs]
%{ for k, instance in aws_lightsail_instance.master_lb }
master_lb_${k + 1} ansible_host=${instance.public_ip_address} private_ip=${instance.private_ip_address} ansible_user=${instance.username} ansible_ssh_private_key_file=${var.ssh_key_path}.pem
%{ endfor }
[workers]
%{ for k, instance in aws_lightsail_instance.worker }
worker_${k + 1} ansible_host=${instance.public_ip_address} private_ip=${instance.private_ip_address} ansible_user=${instance.username} ansible_ssh_private_key_file=${var.ssh_key_path}.pem
%{ endfor }
[worker_lbs]
%{ for k, instance in aws_lightsail_instance.worker_lb }
worker_lb_${k + 1} ansible_host=${instance.public_ip_address} private_ip=${instance.private_ip_address} ansible_user=${instance.username} ansible_ssh_private_key_file=${var.ssh_key_path}.pem
%{ endfor }
[all:vars]
apiserver_bind_port=${var.master_ports.tcp_api.port}
control_plane_endpoint_port=${var.master_lb_ports_map.tcp_api_server.port}
worker_http_port_for_ingress=${var.worker_ports["ingress_tcp_http"].port}
worker_https_port_for_ingress=${var.worker_ports["ingress_tcp_https"].port}
EOT
}