-
Notifications
You must be signed in to change notification settings - Fork 2
/
output.tf
82 lines (71 loc) · 1.92 KB
/
output.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
output "loadbalancer_ip" {
value = digitalocean_loadbalancer.public.ip
depends_on = [digitalocean_loadbalancer.public]
}
output "vpc_cidr_block" {
value = var.cidr_block
}
output "gateway" {
value = {
public_ip = digitalocean_droplet.gateway.ipv4_address
private_ip = digitalocean_droplet.gateway.ipv4_address_private
}
}
output "app1" {
value = {
public_ip = digitalocean_droplet.app1.ipv4_address
private_ip = digitalocean_droplet.app1.ipv4_address_private
}
}
output "app2" {
value = {
public_ip = digitalocean_droplet.app2.ipv4_address
private_ip = digitalocean_droplet.app2.ipv4_address_private
}
}
resource "terraform_data" "ssh_config" {
depends_on = [digitalocean_droplet.gateway, digitalocean_droplet.app1, digitalocean_droplet.app2]
provisioner "local-exec" {
command = <<-EOT
sed -i '/# BOF DO_VPC/,/# EOF DO_VPC/d' ~/.ssh/config
cat <<EOF >temp_conf
# BOF DO_VPC
# Created on $(date)
Host gateway
HostName ${digitalocean_droplet.gateway.ipv4_address}
User root
Host app1
HostName ${digitalocean_droplet.app1.ipv4_address_private}
User root
ProxyCommand ssh -W %h:%p gateway
Host app2
HostName ${digitalocean_droplet.app2.ipv4_address_private}
User root
ProxyCommand ssh -W %h:%p gateway
# EOF DO_VPC
EOF
cat temp_conf >> ~/.ssh/config
rm -rf temp_conf
EOT
}
}
resource "terraform_data" "json_output" {
depends_on = [digitalocean_droplet.app1, digitalocean_droplet.app2, digitalocean_droplet.gateway, digitalocean_loadbalancer.public]
provisioner "local-exec" {
working_dir = path.module
command = <<-EOT
sleep 5
terraform output -json > ansible/output.json;
EOT
}
}
resource "terraform_data" "destroy_time_provisioner" {
provisioner "local-exec" {
working_dir = path.module
when = destroy
command = <<-EOT
sed -i '/# BOF DO_VPC/,/# EOF DO_VPC/d' ~/.ssh/config
rm -rf ansible/output.json
EOT
}
}