@@ -17,6 +17,12 @@ variable "nat_server_plan" {
17
17
variable "project_id" {}
18
18
variable "syslog_address" {}
19
19
20
+ resource "packet_reserved_ip_block" "ips" {
21
+ project_id = " ${ var . project_id } "
22
+ facility = " ${ var . facility } "
23
+ quantity = 1
24
+ }
25
+
20
26
data "template_file" "duo_config" {
21
27
template = << EOF
22
28
# Written by cloud-init :heart:
@@ -28,18 +34,30 @@ failmode = secure
28
34
EOF
29
35
}
30
36
37
+ data "template_file" "network_env" {
38
+ template = << EOF
39
+ export TRAVIS_NETWORK_ELASTIC_IP=${ cidrhost (packet_reserved_ip_block. ips . cidr_notation , 0 )}
40
+ EOF
41
+ }
42
+
31
43
data "template_file" "cloud_config" {
32
44
template = " ${ file (" ${ path . module } /cloud-config.yml.tpl" )} "
33
45
34
46
vars {
35
47
assets = " ${ path . module } /../../assets"
36
48
github_users_env = " export GITHUB_USERS='${ var . github_users } '"
37
49
here = " ${ path . module } "
50
+ network_env = " ${ data . template_file . network_env . rendered } "
38
51
syslog_address = " ${ var . syslog_address } "
39
52
duo_config = " ${ data . template_file . duo_config . rendered } "
40
53
}
41
54
}
42
55
56
+ resource "local_file" "user_data_dump" {
57
+ filename = " ${ path . module } /../../tmp/packet-${ var . env } -${ var . index } -nat-user-data.yml"
58
+ content = " ${ data . template_file . cloud_config . rendered } "
59
+ }
60
+
43
61
resource "packet_device" "nat" {
44
62
billing_cycle = " ${ var . billing_cycle } "
45
63
facility = " ${ var . facility } "
@@ -50,37 +68,30 @@ resource "packet_device" "nat" {
50
68
user_data = " ${ data . template_file . cloud_config . rendered } "
51
69
}
52
70
53
- resource "packet_reserved_ip_block" "ips" {
54
- project_id = " ${ var . project_id } "
55
- facility = " ${ var . facility } "
56
- quantity = 1
57
- }
58
-
59
- resource "packet_ip_attachment" "nat" {
60
- device_id = " ${ packet_device . nat . id } "
61
- cidr_notation = " ${ packet_reserved_ip_block . ips . cidr_notation } "
62
- }
63
-
64
- resource "null_resource" "nat_post_provisioning_todo" {
71
+ resource "null_resource" "user_data_copy" {
65
72
triggers {
66
- nat_public_ip = " ${ cidrhost (packet_ip_attachment . nat . cidr_notation , 0 )} "
73
+ user_data_sha1 = " ${ sha1 (data . template_file . cloud_config . rendered )} "
67
74
}
68
75
69
- provisioner "local-exec" {
70
- command = << EOF
71
- cat <<EOCAT
72
- TODO: finish configuring the nat with something like
76
+ depends_on = [" packet_device.nat" , " local_file.user_data_dump" ]
73
77
74
- ip addr add ${ cidrhost (packet_ip_attachment . nat . cidr_notation , 0 ) } dev bond0
75
- ip route delete default
76
- ip route add default via ${ cidrhost (packet_ip_attachment . nat . cidr_notation , 0 ) } dev bond0
77
- curl icanhazip.com # <=== should be ${ cidrhost (packet_ip_attachment . nat . cidr_notation , 0 ) }
78
+ provisioner "file" {
79
+ source = " ${ local_file . user_data_dump . filename } "
80
+ destination = " /var/tmp/user-data.yml "
81
+ }
78
82
79
- EOCAT
80
- EOF
83
+ connection {
84
+ type = " ssh"
85
+ user = " root"
86
+ host = " ${ packet_device . nat . access_public_ipv4 } "
81
87
}
82
88
}
83
89
90
+ resource "packet_ip_attachment" "nat" {
91
+ device_id = " ${ packet_device . nat . id } "
92
+ cidr_notation = " ${ packet_reserved_ip_block . ips . cidr_notation } "
93
+ }
94
+
84
95
output "nat_ip" {
85
96
value = " ${ packet_device . nat . access_private_ipv4 } "
86
97
}
@@ -89,6 +100,10 @@ output "nat_public_ip" {
89
100
value = " ${ cidrhost (packet_ip_attachment. nat . cidr_notation , 0 )} "
90
101
}
91
102
103
+ output "nat_maint_ip" {
104
+ value = " ${ packet_device . nat . access_public_ipv4 } "
105
+ }
106
+
92
107
output "facility" {
93
108
value = " ${ var . facility } "
94
109
}
0 commit comments