-
Notifications
You must be signed in to change notification settings - Fork 0
/
firehawk-ami.pkr.hcl
1192 lines (1108 loc) · 49 KB
/
firehawk-ami.pkr.hcl
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Ensure you first build the ./firehawk-base-ami first to produce a manifest.
# The firehawk-base-ami is used to build this ami.
variable "aws_region" {
type = string
}
variable "account_id" {
type = string
}
variable "ami_role" {
description = "A descriptive name for the purpose of the image."
type = string
}
variable "commit_hash" {
description = "The hash of the commit in the current git repository contining this file."
type = string
}
variable "commit_hash_short" {
description = "The hash of the commit in the current git repository contining this file."
type = string
}
variable "ingress_commit_hash" {
description = "The hash of the commit in the git repository contining the source file."
type = string
}
variable "ingress_commit_hash_short" {
description = "The hash of the commit in the git repository contining the source file."
type = string
}
variable "resourcetier" {
description = "The current environment ( dev / green / blue / main )"
type = string
}
variable "terraform_version" {
description = "The current environment ( dev / green / blue / main )"
type = string
default = "1.1.7"
}
variable "terragrunt_version" {
description = "The current environment ( dev / green / blue / main )"
type = string
default = "0.36.0"
}
variable "firehawk_deadline_installer_version" {
description = "The firehawk repo aws-thinkbox-deadline version to install/configure Deadline"
type = string
default = "v0.0.23" # This should always be a semantic version for a release, not main.
}
variable "ca_public_key_path" {
type = string
# default = "/home/ec2-user/.ssh/tls/ca.crt.pem"
}
variable "consul_download_url" {
type = string
default = ""
}
variable "install_auth_signing_script" {
type = string
default = "true"
}
variable "tls_private_key_path" {
type = string
# default = "/home/ec2-user/.ssh/tls/vault.key.pem"
}
variable "tls_public_key_path" {
type = string
# default = "/home/ec2-user/.ssh/tls/vault.crt.pem"
}
variable "vault_download_url" {
type = string
default = ""
}
variable "consul_version" {
type = string
default = "1.9.2"
}
### Only required if testing consul during build
variable "consul_cluster_tag_key" {
type = string
default = ""
}
variable "consul_cluster_tag_value" {
type = string
default = ""
}
variable "packer_iam_profile_name" { # Required for some builds requiring S3 Installers
type = string
}
variable "test_consul" { # If a consul cluster is running, attempt to join the cluster. This can be useful for debugging, but will prevent inital builds if you have no infrastructure running yet. This test may not also work unless the appropriate role is assigned.
type = bool
default = false
}
variable "deadlineuser_name" {
description = "The deadline user name for render nodes and deadline DB"
type = string
default = "deadlineuser"
}
variable "db_host_name" {
description = "The hostname for deadline DB"
type = string
default = "deadlinedb.service.consul"
}
variable "installers_bucket" {
description = "The installer bucket to persist installations to"
type = string
}
# Required for render node AMI
variable "sesi_client_id" {
description = "The client ID generated from your Side FX Account to automatically download Houdini."
type = string
}
variable "sesi_client_secret_key" {
description = "The secret key generated from your Side FX Account to automatically download Houdini."
type = string
}
variable "houdini_license_server_address" {
description = "The IP or host name of your Houdini license server (IP Address is recommended to simplify usage across sites with DNS)."
type = string
}
variable "SSL_expiry" {
description = "The Expiry resulting from the TTL on the SSL Certificates"
type = string
}
locals {
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
template_dir = path.root
deadline_version = "10.1.23.6"
installers_bucket = var.installers_bucket
common_ami_tags = {
"packer_template" : "firehawk-ami",
"commit_hash" : var.commit_hash,
"commit_hash_short" : var.commit_hash_short,
"resourcetier" : var.resourcetier,
"sslexpiry" : var.SSL_expiry,
"deadline_version" : local.deadline_version
}
syscontrol_gid = "9003"
deployuser_uid = "9004"
deadlineuser_uid = "9001"
houdini_build = "daily"
sesi_client_id = var.sesi_client_id
sesi_client_secret_key = var.sesi_client_secret_key
houdini_license_server_address = var.houdini_license_server_address
# python_libs_folder will change between 2.7 and 3.7 depending on your installer
# You may require a different version of houdini for hserver
houdini_json_vars = {
"houdini_version_list" = [
{
"houdini_major_version" = "19.0",
"python_libs_folder" = "python3.7libs",
"houdini_auto_version" = "true",
"houdini_minor_version" = "auto",
"houdini_linux_tar_filename" = "auto",
"houdini_build" = "production"
}
]
}
# deprecated: this is only needed if installing a license server
# "houdini_license_server_version_list" : [
# {
# "houdini_major_version" = "19.0",
# "houdini_auto_version" = "true",
# "houdini_minor_version" = "auto",
# "houdini_linux_tar_filename" = "auto",
# "houdini_build" = "production"
# }
# ]
}
source "amazon-ebs" "openvpn-server-ami" {
tags = merge(
{ "packer_source" : "amazon-ebs.openvpn-server-ami" },
{ "ami_role" : "firehawk_openvpn_server_ami" },
{ "Name" : "firehawk_openvpn_server_ami" },
local.common_ami_tags
)
ami_description = "An Open VPN Access Server AMI configured for Firehawk"
ami_name = "firehawk-openvpn-server-${local.timestamp}-{{uuid}}"
instance_type = "t2.micro"
region = var.aws_region
# source_ami = "${var.openvpn_server_base_ami}"
source_ami_filter {
filters = {
"tag:ami_role" : "openvpn_server_base_ami",
"tag:packer_template" : "firehawk-base-ami",
"tag:commit_hash" : var.ingress_commit_hash,
"tag:commit_hash_short" : var.ingress_commit_hash_short,
"tag:resourcetier" : var.resourcetier,
}
most_recent = true
owners = [var.account_id]
}
# We generate a random pass for the image build. It will never need to be reused. When the ami is started, the password is reset to a vault provided value.
user_data = <<EOF
#! /bin/bash
admin_user=openvpnas
admin_pw="$(openssl rand -base64 12)"
EOF
ssh_username = "openvpnas"
}
source "amazon-ebs" "amazonlinux2-ami" {
tags = merge(
{ "packer_source" : "amazon-ebs.amazonlinux2-ami" },
{ "ami_role" : "firehawk_amazonlinux2_ami" },
{ "Name" : "firehawk_amazonlinux2_ami" },
local.common_ami_tags
)
ami_description = "An Amazon Linux 2 AMI that will accept connections from hosts with TLS Certs."
ami_name = "firehawk-bastion-amazonlinux2-${local.timestamp}-{{uuid}}"
instance_type = "t2.micro"
region = var.aws_region
# source_ami = "${var.amazon_linux_2_ami}"
source_ami_filter {
filters = {
"tag:ami_role" : "amazonlinux2_base_ami",
"tag:packer_template" : "firehawk-base-ami",
"tag:commit_hash" : var.ingress_commit_hash,
"tag:commit_hash_short" : var.ingress_commit_hash_short,
"tag:resourcetier" : var.resourcetier,
}
most_recent = true
owners = [var.account_id]
}
ssh_username = "ec2-user"
}
source "amazon-ebs" "amazonlinux2-nicedcv-nvidia-ami" {
tags = merge(
{ "packer_source" : "amazon-ebs.amazonlinux2-nicedcv-nvidia-ami" },
{ "ami_role" : "firehawk_amazonlinux2_nicedcv_ami" },
{ "Name" : "firehawk_amazonlinux2_nicedcv_ami" },
local.common_ami_tags
)
ami_description = "A Graphical Amazon Linux 2 NICE DCV AMI that will accept connections from hosts with TLS Certs."
ami_name = "firehawk-workstation-amazonlinux2-nicedcv-${local.timestamp}-{{uuid}}"
instance_type = "t2.micro"
region = var.aws_region
# source_ami = "${var.amazon_linux_2_ami}"
source_ami_filter {
filters = {
"tag:ami_role" : "amazonlinux2_nicedcv_base_ami",
"tag:packer_template" : "firehawk-base-ami",
"tag:commit_hash" : var.ingress_commit_hash,
"tag:commit_hash_short" : var.ingress_commit_hash_short,
"tag:resourcetier" : var.resourcetier,
}
most_recent = true
owners = [var.account_id]
}
# launch_block_device_mappings {
# device_name = "/dev/xvda1"
# volume_size = 20
# volume_type = "gp2"
# delete_on_termination = true
# }
# ami_block_device_mappings {
# device_name = "/dev/sdb"
# virtual_name = "ephemeral0"
# }
# ami_block_device_mappings {
# device_name = "/dev/sdc"
# virtual_name = "ephemeral1"
# }
ssh_username = "ec2-user"
iam_instance_profile = var.packer_iam_profile_name # provide read and write s3 access for updating and retrieving installers
}
#could not parse template for following block: "template: generated:4: function \"clean_resource_name\" not defined"
source "amazon-ebs" "centos7-ami" {
tags = merge(
{ "packer_source" : "amazon-ebs.centos7-ami" },
{ "ami_role" : "firehawk_centos7_ami" },
{ "Name" : "firehawk_centos7_ami" },
local.common_ami_tags
)
ami_description = "A Cent OS 7 AMI that will accept connections from hosts with TLS Certs."
ami_name = "firehawk-bastion-centos7-${local.timestamp}-{{uuid}}"
instance_type = "t2.micro"
region = var.aws_region
# source_ami = "${var.centos7_ami}"
source_ami_filter {
filters = {
"tag:ami_role" : "centos7_base_ami",
"tag:packer_template" : "firehawk-base-ami",
"tag:commit_hash" : var.ingress_commit_hash,
"tag:commit_hash_short" : var.ingress_commit_hash_short,
"tag:resourcetier" : var.resourcetier,
}
most_recent = true
owners = [var.account_id]
}
ssh_username = "centos"
}
source "amazon-ebs" "centos7-rendernode-ami" {
tags = merge(
{ "packer_source" : "amazon-ebs.centos7-rendernode-ami" },
{ "ami_role" : "firehawk_centos7_rendernode_ami" },
{ "Name" : "firehawk_centos7_rendernode_ami" },
{ "firehawk_deadline_installer_version" : "${var.firehawk_deadline_installer_version}" },
{ "houdini_major_version" : local.houdini_json_vars["houdini_version_list"][0]["houdini_major_version"] },
local.common_ami_tags
)
ami_description = "A Cent OS 7 AMI rendernode."
ami_name = "firehawk-rendernode-centos7-${local.timestamp}-{{uuid}}"
instance_type = "t2.micro"
region = var.aws_region
# source_ami = "${var.centos7_ami}"
source_ami_filter {
filters = {
"tag:ami_role" : "centos7_base_ami",
"tag:packer_template" : "firehawk-base-ami",
"tag:commit_hash" : var.ingress_commit_hash,
"tag:commit_hash_short" : var.ingress_commit_hash_short,
"tag:resourcetier" : var.resourcetier,
}
most_recent = true
owners = [var.account_id]
}
ssh_username = "centos"
iam_instance_profile = var.packer_iam_profile_name # provide read and write s3 access for updating and retrieving installers
launch_block_device_mappings {
device_name = "/dev/sda1"
volume_size = 17
volume_type = "gp2"
delete_on_termination = true
}
# ami_block_device_mappings {
# device_name = "/dev/sdb"
# virtual_name = "ephemeral0"
# }
# ami_block_device_mappings {
# device_name = "/dev/sdc"
# virtual_name = "ephemeral1"
# }
}
source "amazon-ebs" "ubuntu18-ami" {
tags = merge(
{ "packer_source" : "amazon-ebs.ubuntu18-ami" },
{ "ami_role" : "firehawk_ubuntu18_ami" },
{ "Name" : "firehawk_ubuntu18_ami" },
local.common_ami_tags
)
ami_description = "An Ubuntu 18.04 AMI that will accept connections from hosts with TLS Certs."
ami_name = "firehawk-bastion-ubuntu18-${local.timestamp}-{{uuid}}"
instance_type = "t2.micro"
region = var.aws_region
# source_ami = "${var.ubuntu18_ami}"
source_ami_filter {
filters = {
"tag:ami_role" : "ubuntu18_base_ami",
"tag:packer_template" : "firehawk-base-ami",
"tag:commit_hash" : var.ingress_commit_hash,
"tag:commit_hash_short" : var.ingress_commit_hash_short,
"tag:resourcetier" : var.resourcetier,
}
most_recent = true
owners = [var.account_id]
}
ssh_username = "ubuntu"
}
source "amazon-ebs" "ubuntu18-vault-consul-server-ami" {
tags = merge(
{ "packer_source" : "amazon-ebs.ubuntu18-vault-consul-server-ami" },
{ "ami_role" : "firehawk_ubuntu18_vault_consul_server_ami" },
{ "Name" : "firehawk_ubuntu18_vault_consul_server_ami" },
local.common_ami_tags
)
ami_description = "An Ubuntu 18.04 AMI Vault and Consul Server."
ami_name = "firehawk-vault-consul-server-ubuntu18-${local.timestamp}-{{uuid}}"
instance_type = "t2.micro"
region = var.aws_region
# source_ami = "${var.ubuntu18_ami}"
source_ami_filter { # Uses firehawk base ami
filters = {
"tag:ami_role" : "ubuntu18_base_ami",
"tag:packer_template" : "firehawk-base-ami",
"tag:commit_hash" : var.ingress_commit_hash,
"tag:commit_hash_short" : var.ingress_commit_hash_short,
"tag:resourcetier" : var.resourcetier,
}
most_recent = true
owners = [var.account_id]
}
# source_ami_filter { # uses default ami from hashicorp template
# filters = {
# architecture = "x86_64"
# "block-device-mapping.volume-type" = "gp2"
# name = "ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"
# root-device-type = "ebs"
# virtualization-type = "hvm"
# }
# most_recent = true
# owners = ["099720109477"]
# }
ssh_username = "ubuntu"
}
source "amazon-ebs" "deadline-db-ubuntu18-ami" {
tags = merge(
{ "packer_source" : "amazon-ebs.deadline-db-ubuntu18-ami" },
{ "ami_role" : "firehawk_deadlinedb_ami" },
{ "Name" : "firehawk_deadlinedb_ami" },
{ "firehawk_deadline_installer_version" : "${var.firehawk_deadline_installer_version}" },
{ "houdini_major_version" : local.houdini_json_vars["houdini_version_list"][0]["houdini_major_version"] },
local.common_ami_tags
)
ami_description = "An Ubuntu 18.04 AMI with Deadline DB ${local.deadline_version} server."
ami_name = "firehawk-deadlinedb-ubuntu18-${local.timestamp}-{{uuid}}"
instance_type = "t2.micro"
region = var.aws_region
# source_ami = "${var.ubuntu18_ami}"
source_ami_filter {
filters = {
"tag:ami_role" : "ubuntu18_base_ami",
"tag:packer_template" : "firehawk-base-ami",
"tag:commit_hash" : var.ingress_commit_hash,
"tag:commit_hash_short" : var.ingress_commit_hash_short,
"tag:resourcetier" : var.resourcetier,
}
most_recent = true
owners = [var.account_id]
}
ssh_username = "ubuntu"
iam_instance_profile = var.packer_iam_profile_name
launch_block_device_mappings {
device_name = "/dev/sda1"
volume_size = 20
volume_type = "gp2"
delete_on_termination = true
}
# ami_block_device_mappings {
# device_name = "/dev/sdb"
# virtual_name = "ephemeral0"
# }
# ami_block_device_mappings {
# device_name = "/dev/sdc"
# virtual_name = "ephemeral1"
# }
# assume_role { # Since we need to read files from s3, we require a role with read access.
# role_arn = "arn:aws:iam::972620357255:role/provisioner_instance_role_pipeid0" # This needs to be replaced with a terraform output
# session_name = "SESSION_NAME"
# # external_id = "EXTERNAL_ID"
# }
}
build {
sources = [
"source.amazon-ebs.amazonlinux2-ami",
"source.amazon-ebs.amazonlinux2-nicedcv-nvidia-ami",
"source.amazon-ebs.centos7-ami",
"source.amazon-ebs.centos7-rendernode-ami",
"source.amazon-ebs.ubuntu18-ami",
"source.amazon-ebs.ubuntu18-vault-consul-server-ami",
"source.amazon-ebs.deadline-db-ubuntu18-ami",
"source.amazon-ebs.openvpn-server-ami"
]
### Open VPN - Wait for updates to finish and change daily update timer ###
provisioner "shell" {
inline = [
"echo 'Init success'",
"unset HISTFILE",
"history -cw",
"echo === Waiting for Cloud-Init ===",
"timeout 180 /bin/bash -c 'until stat /var/lib/cloud/instance/boot-finished &>/dev/null; do echo waiting...; sleep 6; done'",
"echo === System Packages ===",
"echo 'Connected success. Wait for updates to finish...'", # Open VPN AMI runs apt daily update which must end before we continue.
"sudo systemd-run --property='After=apt-daily.service apt-daily-upgrade.service' --wait /bin/true; echo \"exit $?\""
]
environment_vars = ["DEBIAN_FRONTEND=noninteractive"]
inline_shebang = "/bin/bash -e"
only = ["amazon-ebs.ubuntu18-ami", "amazon-ebs.deadline-db-ubuntu18-ami", "amazon-ebs.openvpn-server-ami", "amazon-ebs.ubuntu18-vault-consul-server-ami"]
}
provisioner "file" { # fix apt upgrades to not hold up boot
destination = "/tmp/override.conf"
source = "${local.template_dir}/override.conf"
}
provisioner "shell" {
inline = [
"sudo mkdir -p /etc/systemd/system/apt-daily.timer.d",
"sudo cp /tmp/override.conf /etc/systemd/system/apt-daily.timer.d/override.conf",
"sudo mkdir -p /etc/systemd/system/apt-daily-upgrade.timer.d",
"sudo cp /tmp/override.conf /etc/systemd/system/apt-daily-upgrade.timer.d/override.conf",
"sudo rm -f /tmp/override.conf",
"sudo chmod 0644 /etc/systemd/system/apt-daily.timer.d/override.conf",
"sudo systemctl daemon-reload",
"sudo systemctl cat apt-daily{,-upgrade}.timer",
"sudo systemctl --all list-timers apt-daily{,-upgrade}.timer"
]
inline_shebang = "/bin/bash -e"
only = ["amazon-ebs.ubuntu18-ami", "amazon-ebs.deadline-db-ubuntu18-ami", "amazon-ebs.openvpn-server-ami"]
}
### Public cert block to verify other consul agents ###
# provisioner "shell" {
# inline = ["mkdir -p /tmp/terraform-aws-vault/modules"]
# }
# provisioner "file" {
# destination = "/tmp/terraform-aws-vault/modules"
# source = "${local.template_dir}/../../../terraform-aws-vault/modules/"
# }
### This block will install Vault and Consul Agent for DNS
# Ensure no more updates are running
provisioner "shell" {
inline = [
"sudo systemd-run --property='After=apt-daily.service apt-daily-upgrade.service' --wait /bin/true; echo \"exit $?\""
]
inline_shebang = "/bin/bash -e"
only = ["amazon-ebs.ubuntu18-ami", "amazon-ebs.deadline-db-ubuntu18-ami", "amazon-ebs.openvpn-server-ami"]
}
provisioner "shell" { # Install amazon systems manager for centos intelx86/amd64
inline = [
"sudo yum install -y https://s3.${var.aws_region}.amazonaws.com/amazon-ssm-${var.aws_region}/latest/linux_amd64/amazon-ssm-agent.rpm",
"sudo systemctl enable amazon-ssm-agent",
"sudo systemctl start amazon-ssm-agent",
"sudo yum install -y ruby", # the following steps are to install codedeploy agent
"sudo yum install -y wget",
# "CODEDEPLOY_BIN=\"/opt/codedeploy-agent/bin/codedeploy-agent\"", # only required if there is an existing version
# "$CODEDEPLOY_BIN stop",
# "sudo yum erase codedeploy-agent -y",
"cd /home/centos; sudo wget https://aws-codedeploy-${var.aws_region}.s3.${var.aws_region}.amazonaws.com/latest/install; sudo chmod +x ./install; sudo ./install auto",
"sudo service codedeploy-agent start",
"sudo service codedeploy-agent status",
"sudo service codedeploy-agent enable",
]
inline_shebang = "/bin/bash -e"
only = ["amazon-ebs.centos7-rendernode-ami"]
}
### Install cloudwatch logs agent
provisioner "shell" {
inline = [
"cd /tmp; sudo wget https://s3.${var.aws_region}.amazonaws.com/amazoncloudwatch-agent-${var.aws_region}/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm; sudo rpm -U ./amazon-cloudwatch-agent.rpm",
"sudo rm -f /tmp/amazon-cloudwatch-agent.rpm",
"sudo yum install -y jq"
]
only = [
"amazon-ebs.amazonlinux2-ami",
"amazon-ebs.centos7-rendernode-ami"
]
}
# Install terraform, terragrunt, packer for Amazon Linux
provisioner "shell" {
inline = [
"python3.7 -m pip install ansible boto3 botocore", #: Install ansible using the same method we use to install it to codebuild
"wget https://releases.hashicorp.com/terraform/${var.terraform_version}/terraform_${var.terraform_version}_linux_amd64.zip -P /tmp/ --quiet", # Get terraform
"sudo unzip /tmp/terraform_${var.terraform_version}_linux_amd64.zip -d /tmp/",
"sudo mv /tmp/terraform /usr/local/bin/.",
"wget https://github.com/gruntwork-io/terragrunt/releases/download/v${var.terragrunt_version}/terragrunt_linux_386 -P /tmp/ --quiet", # Get Terragrunt
"sudo mv /tmp/terragrunt_linux_386 /usr/local/bin/terragrunt",
"sudo chmod +x /usr/local/bin/terragrunt"
]
only = [
"amazon-ebs.amazonlinux2-ami",
]
}
### Init ansible collections for all hosts.
provisioner "ansible" { # See https://github.com/hashicorp/packer-plugin-ansible/issues/47#issuecomment-852443057
playbook_file = "./ansible/ansible_init.yaml"
user = "centos"
extra_arguments = [
"-v",
"--extra-vars",
"variable_host=default package_python_interpreter=/usr/bin/python2.7"
]
collections_path = "./ansible/collections"
roles_path = "./ansible/roles"
ansible_env_vars = ["ANSIBLE_CONFIG=ansible/ansible.cfg"]
galaxy_file = "./requirements.yml"
only = [
"amazon-ebs.centos7-ami",
"amazon-ebs.centos7-rendernode-ami",
]
}
provisioner "ansible" { # See https://github.com/hashicorp/packer-plugin-ansible/issues/47#issuecomment-852443057
playbook_file = "./ansible/ansible_init.yaml"
user = "ec2-user"
extra_arguments = [
"-v",
"--extra-vars",
"variable_host=default package_python_interpreter=/usr/bin/python2.7"
]
collections_path = "./ansible/collections"
roles_path = "./ansible/roles"
ansible_env_vars = ["ANSIBLE_CONFIG=ansible/ansible.cfg"]
galaxy_file = "./requirements.yml"
only = [
"amazon-ebs.amazonlinux2-ami",
"amazon-ebs.amazonlinux2-nicedcv-nvidia-ami",
"amazon-ebs.ubuntu18-ami",
"amazon-ebs.deadline-db-ubuntu18-ami",
"amazon-ebs.openvpn-server-ami",
"ubuntu18-vault-consul-server-ami"
]
}
provisioner "shell" { # Vault client probably wont be installed on bastions in future, but most hosts that will authenticate will require it.
inline = [
"git config --global advice.detachedHead false", # disable warning about detached head because we dont care, it is a software installation
"set -x; git clone --branch v0.17.0 https://github.com/hashicorp/terraform-aws-vault.git /tmp/terraform-aws-vault", # This can be replaced with a local copy if required.
"if test -n '${var.vault_download_url}'; then",
" set -x; /tmp/terraform-aws-vault/modules/install-vault/install-vault --download-url ${var.vault_download_url} --skip-package-update",
"else",
" set -x; /tmp/terraform-aws-vault/modules/install-vault/install-vault --version 1.6.1 --skip-package-update",
"fi"
# "if [[ -n \"$(command -v yum)\" ]]; then sudo yum remove awscli -y; fi", # uninstall AWS CLI v1
# "if [[ -n \"$(command -v apt-get)\" ]]; then sudo apt-get remove awscli -y; fi", # uninstall AWS CLI v1
# "if sudo test -f /bin/aws; then sudo rm -f /bin/aws; fi" # Ensure AWS CLI v1 doesn't exist
]
}
### Install certs for clients and servers
provisioner "file" {
destination = "/tmp/sign-request.py"
source = "${local.template_dir}/auth/sign-request.py"
}
provisioner "file" {
destination = "/tmp/ca.crt.pem"
source = var.ca_public_key_path
}
### Clients only require the CA cert.
provisioner "shell" {
inline = [
"if [[ '${var.install_auth_signing_script}' == 'true' ]]; then",
"sudo mkdir -p /opt/vault/scripts/",
"sudo mv /tmp/sign-request.py /opt/vault/scripts/",
"else",
"sudo rm /tmp/sign-request.py",
"fi",
"sudo mkdir -p /opt/vault/tls/",
"sudo mv /tmp/ca.crt.pem /opt/vault/tls/",
"sudo chmod -R 600 /opt/vault/tls",
"sudo chmod 700 /opt/vault/tls",
"sudo /tmp/terraform-aws-vault/modules/update-certificate-store/update-certificate-store --cert-file-path /opt/vault/tls/ca.crt.pem"
]
inline_shebang = "/bin/bash -e"
only = [
"amazon-ebs.amazonlinux2-ami",
"amazon-ebs.amazonlinux2-nicedcv-nvidia-ami",
"amazon-ebs.centos7-ami",
"amazon-ebs.centos7-rendernode-ami",
"amazon-ebs.ubuntu18-ami",
"amazon-ebs.deadline-db-ubuntu18-ami",
"amazon-ebs.openvpn-server-ami"
]
}
# ### Only Vault and Consul servers should have the private keys.
provisioner "file" {
destination = "/tmp/vault.crt.pem"
source = var.tls_public_key_path
only = ["amazon-ebs.ubuntu18-vault-consul-server-ami"]
}
provisioner "file" {
destination = "/tmp/vault.key.pem"
source = var.tls_private_key_path
only = ["amazon-ebs.ubuntu18-vault-consul-server-ami"]
}
provisioner "shell" {
inline = [
"if [[ '${var.install_auth_signing_script}' == 'true' ]]; then",
"sudo mv /tmp/sign-request.py /opt/vault/scripts/",
"else",
"sudo rm /tmp/sign-request.py",
"fi",
"sudo mv /tmp/ca.crt.pem /opt/vault/tls/",
"sudo mv /tmp/vault.crt.pem /opt/vault/tls/",
"sudo mv /tmp/vault.key.pem /opt/vault/tls/",
"sudo chown -R vault:vault /opt/vault/tls/",
"sudo chmod -R 600 /opt/vault/tls",
"sudo chmod 700 /opt/vault/tls",
"sudo /tmp/terraform-aws-vault/modules/update-certificate-store/update-certificate-store --cert-file-path /opt/vault/tls/ca.crt.pem"]
inline_shebang = "/bin/bash -e"
only = ["amazon-ebs.ubuntu18-vault-consul-server-ami"]
}
provisioner "shell" {
inline = [
"sudo DEBIAN_FRONTEND=noninteractive apt-get install -y git",
"if [[ '${var.install_auth_signing_script}' == 'true' ]]; then",
"sudo DEBIAN_FRONTEND=noninteractive apt-get install -y python-pip",
"LC_ALL=C && sudo pip install boto3",
"fi"]
inline_shebang = "/bin/bash -e"
only = ["amazon-ebs.ubuntu18-vault-consul-server-ami"]
}
provisioner "shell" {
inline = ["sudo systemd-run --property='After=apt-daily.service apt-daily-upgrade.service' --wait /bin/true"]
inline_shebang = "/bin/bash -e"
only = ["amazon-ebs.ubuntu18-ami", "amazon-ebs.deadline-db-ubuntu18-ami"]
}
### requirements for deadline SSL
provisioner "shell" {
inline = [
"apt-get install python-openssl",
"cd /home/ubuntu/Downloads",
"git clone https://github.com/ThinkboxSoftware/SSLGeneration.git" # https://docs.thinkboxsoftware.com/products/deadline/10.1/1_User%20Manual/manual/proxy-sslgen.html?highlight=ssl%20certificate%20generation
]
inline_shebang = "/bin/bash -e"
only = ["amazon-ebs.amazon-ebs.deadline-db-ubuntu18-ami"]
}
### End public cert block to verify other consul agents ###
provisioner "ansible" { # Disable SELINUX for rendernodes until tested and working when enabled.
playbook_file = "./ansible/selinux.yaml"
user = "centos"
extra_arguments = [
"-vvvv",
"--extra-vars",
"variable_host=default set_selinux=disabled package_python_interpreter=/usr/bin/python2.7"
]
collections_path = "./ansible/collections"
roles_path = "./ansible/roles"
ansible_env_vars = ["ANSIBLE_CONFIG=ansible/ansible.cfg"]
galaxy_file = "./requirements.yml"
only = [
"amazon-ebs.centos7-rendernode-ami"
]
}
provisioner "ansible" { # Add user deployuser
playbook_file = "./ansible/newuser.yaml"
user = "centos"
extra_arguments = [
"-v",
"--extra-vars",
"variable_user=deployuser sudo=true passwordless_sudo=true add_to_group_syscontrol=true variable_connect_as_user=centos variable_uid=${local.deployuser_uid} syscontrol_gid=${local.syscontrol_gid} variable_host=default delegate_host=localhost"
# package_python_interpreter=/usr/bin/python2.7"
]
collections_path = "./ansible/collections"
roles_path = "./ansible/roles"
ansible_env_vars = ["ANSIBLE_CONFIG=ansible/ansible.cfg"]
galaxy_file = "./requirements.yml"
only = [
"amazon-ebs.centos7-rendernode-ami",
"amazon-ebs.amazonlinux2-nicedcv-nvidia-ami"
]
}
provisioner "ansible" {
playbook_file = "./ansible/newuser.yaml"
user = "centos"
extra_arguments = [
"-v",
"--extra-vars",
"variable_user=deadlineuser sudo=true passwordless_sudo=true add_to_group_syscontrol=false variable_connect_as_user=centos variable_uid=${local.deadlineuser_uid} syscontrol_gid=${local.syscontrol_gid} variable_host=default delegate_host=localhost"
# package_python_interpreter=/usr/bin/python2.7"
]
collections_path = "./ansible/collections"
roles_path = "./ansible/roles"
ansible_env_vars = ["ANSIBLE_CONFIG=ansible/ansible.cfg"]
galaxy_file = "./requirements.yml"
only = [
"amazon-ebs.centos7-rendernode-ami",
"amazon-ebs.amazonlinux2-nicedcv-nvidia-ami"
]
}
provisioner "ansible" {
playbook_file = "./ansible/newuser.yaml"
user = "ubuntu"
extra_arguments = [
"-v",
"--extra-vars",
"variable_user=deadlineuser sudo=true passwordless_sudo=true add_to_group_syscontrol=false variable_connect_as_user=ubuntu variable_uid=${local.deadlineuser_uid} syscontrol_gid=${local.syscontrol_gid} variable_host=default delegate_host=localhost"
# package_python_interpreter=/usr/bin/python2.7"
]
collections_path = "./ansible/collections"
roles_path = "./ansible/roles"
ansible_env_vars = ["ANSIBLE_CONFIG=ansible/ansible.cfg"]
galaxy_file = "./requirements.yml"
only = [
"amazon-ebs.deadline-db-ubuntu18-ami"
]
}
### Install Mongo / Deadline DB
provisioner "shell" {
### Install Deadline DB Ubuntu Dependencies
inline = [
"sudo DEBIAN_FRONTEND=noninteractive apt-get install -y xdg-utils lsb python-openssl netcat nfs-common",
"sudo mkdir -p /usr/share/desktop-directories"
]
only = ["amazon-ebs.deadline-db-ubuntu18-ami"]
}
provisioner "shell" {
### Install Deadline Worker Centos Dependencies. nc is also used to ensure a connection can be established with a port.
inline = [
"sudo yum install -y redhat-lsb samba-client samba-common cifs-utils nfs-utils tree bzip2 nmap wget nc"
]
only = [
"amazon-ebs.centos7-rendernode-ami",
"amazon-ebs.amazonlinux2-nicedcv-nvidia-ami"
]
}
# Install Powershell
provisioner "shell" {
inline = [
"sudo DEBIAN_FRONTEND=noninteractive apt-get install -y wget apt-transport-https software-properties-common",
"wget -q \"https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb\"",
"sudo dpkg -i packages-microsoft-prod.deb",
"sudo DEBIAN_FRONTEND=noninteractive apt-get update", # this needs to go into the base image.
"sudo DEBIAN_FRONTEND=noninteractive apt-get install -y powershell"
]
only = ["amazon-ebs.deadline-db-ubuntu18-ami"]
}
provisioner "shell" {
inline = [
"curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo",
"sudo yum makecache",
"sudo yum install powershell -y"
]
only = [
"amazon-ebs.centos7-rendernode-ami",
"amazon-ebs.amazonlinux2-nicedcv-nvidia-ami"
]
}
provisioner "shell" {
### Install Deadline Worker Amazon Linux 2 Dependencies - https://docs.thinkboxsoftware.com/products/deadline/10.1/1_User%20Manual/manual/install-client.html
inline = [
"sudo yum install -y lsb"
]
only = [
"amazon-ebs.amazonlinux2-nicedcv-nvidia-ami"
]
}
provisioner "ansible" {
playbook_file = "./ansible/transparent-hugepages-disable.yml"
user = "ubuntu"
extra_arguments = [
"-v",
"--extra-vars",
# "user_deadlineuser_pw=${local.user_deadlineuser_pw} user_deadlineuser_name=deadlineuser variable_host=default variable_connect_as_user=ubuntu delegate_host=localhost"
"resourcetier=${var.resourcetier} user_deadlineuser_name=ubuntu variable_host=default variable_connect_as_user=ubuntu delegate_host=localhost"
]
collections_path = "./ansible/collections"
roles_path = "./ansible/roles"
ansible_env_vars = ["ANSIBLE_CONFIG=ansible/ansible.cfg"]
galaxy_file = "./requirements.yml"
only = ["amazon-ebs.deadline-db-ubuntu18-ami"]
}
provisioner "file" { # fix apt upgrades to not hold up boot
destination = "/tmp/zip-each-folder"
source = "${local.template_dir}/scripts/zip-each-folder"
only = ["amazon-ebs.deadline-db-ubuntu18-ami"]
}
provisioner "shell" { ### Download Deadline install script
inline = [
"set -x; cd /var/tmp; git clone --branch ${var.firehawk_deadline_installer_version} https://github.com/firehawkvfx/aws-thinkbox-deadline.git",
"set -x; sudo chown -R ${var.deadlineuser_name}:${var.deadlineuser_name} /var/tmp/aws-thinkbox-deadline"
]
only = [
"amazon-ebs.deadline-db-ubuntu18-ami",
"amazon-ebs.centos7-rendernode-ami"
]
}
provisioner "shell" { ### Install Deadline for DB, RCS Client
inline = [
"set -x; sudo su - ${var.deadlineuser_name} -c \"/var/tmp/aws-thinkbox-deadline/install-deadline --verbose --deadline-version ${local.deadline_version} --db-host-name ${var.db_host_name} --skip-certgen-during-db-install --skip-certgen-during-rcs-install --skip-install-validation --skip-install-packages --installers-bucket ${local.installers_bucket}\"",
"sudo rm -frv /var/log/Thinkbox/Deadline10/*", # cleanup logs
"sudo rm -fv /var/tmp/downloads/AWSPortalLink*",
"sudo rm /tmp/Deadline-${local.deadline_version}-linux-installers.tar",
"sudo apt-get install -y zip unzip",
"sudo su - ${var.deadlineuser_name} -c \"/tmp/zip-each-folder /opt/Thinkbox/DeadlineRepository10/submission\"",
"sudo su - ${var.deadlineuser_name} -c \"aws s3 sync /opt/Thinkbox/DeadlineRepository10/submission \"s3://${local.installers_bucket}/Deadline-${local.deadline_version}/Thinkbox/DeadlineRepository10/submission\"\""
]
only = ["amazon-ebs.deadline-db-ubuntu18-ami"]
}
provisioner "file" { # fix apt upgrades to not hold up boot
destination = "/tmp/retry"
source = "${local.template_dir}/scripts/retry"
only = [
"amazon-ebs.centos7-rendernode-ami"
]
}
provisioner "shell" { ### Install Deadline for Client Worker
inline = [
"sudo su - ${var.deadlineuser_name} -c \"mkdir -p /home/${var.deadlineuser_name}/Thinkbox/Deadline10\"",
"sudo su - ${var.deadlineuser_name} -c \"touch /home/${var.deadlineuser_name}/Thinkbox/Deadline10/secure.ini\"", # to fix a bug introduced by Thinkbox in 10.1.17.x
"sudo su - ${var.deadlineuser_name} -c \"/var/tmp/aws-thinkbox-deadline/install-deadline --verbose --deadline-version ${local.deadline_version} --db-host-name ${var.db_host_name} --install-worker --skip-install-validation --skip-download-mongo --skip-install-packages --installers-bucket ${local.installers_bucket}\"",
"sudo rm -fv /tmp/Deadline-${local.deadline_version}-linux-installers.tar",
"sudo rm -fv $deadline_installer_dir/AWSPortalLink*",
"sudo rm -fv $deadline_installer_dir/DeadlineRepository*",
"sudo rm -frv /var/log/Thinkbox/Deadline10/*", # cleanup logs
"echo '...Wait for Submission/Client plugin from bucket'",
# The need to wait for this dependency is unfortunate... the deadline repository /submission scripts for the render node are not available until the repostory is installed. Rather than break the parallel build workflow, we test for existance of the required file in the s3 bucket for a duration limit (15 mins) before failing the render node build. The deadline DB places those files in the bucket when installing, so if this fails, it should be because the Deadline repository build failed.
"sudo su - ${var.deadlineuser_name} -c \"/tmp/retry 'aws s3api head-object --bucket ${local.installers_bucket} --key Deadline-${local.deadline_version}/Thinkbox/DeadlineRepository10/submission/Houdini.zip' 'Wait for file to arrive in bucket...'\"",
"echo '...Retrieve file...'",
"sudo su - ${var.deadlineuser_name} -c \"aws s3api get-object --bucket ${local.installers_bucket} --key Deadline-${local.deadline_version}/Thinkbox/DeadlineRepository10/submission/Houdini.zip /tmp/Houdini.zip\"",
"sudo su - ${var.deadlineuser_name} -c \"/tmp/retry 'aws s3api head-object --bucket ${local.installers_bucket} --key Deadline-${local.deadline_version}/Thinkbox/DeadlineRepository10/submission/HServer.zip' 'Wait for file to arrive in bucket...'\"",
"echo '...Retrieve file...'",
"sudo su - ${var.deadlineuser_name} -c \"aws s3api get-object --bucket ${local.installers_bucket} --key Deadline-${local.deadline_version}/Thinkbox/DeadlineRepository10/submission/HServer.zip /tmp/HServer.zip\"",
"echo '...Create /var/tmp/submission'",
"sudo su - ${var.deadlineuser_name} -c \"mkdir -p /var/tmp/submission\"",
"sudo su - ${var.deadlineuser_name} -c \"unzip /tmp/Houdini.zip -d /var/tmp/submission\"",
"sudo su - ${var.deadlineuser_name} -c \"unzip /tmp/HServer.zip -d /var/tmp/submission\"",
"sudo ls -ltriah /var/tmp/submission/Houdini/Client",
"sudo systemctl disable deadline10launcher", # Ensure the launcher does not start automatically on first boot. User data must aquire the certificates first, then the service will be started and enabled for subsequent reboots.
"sudo systemctl stop deadline10launcher"
]
only = [
"amazon-ebs.centos7-rendernode-ami"
# "amazon-ebs.amazonlinux2-nicedcv-nvidia-ami"
]
}
### Install Houdini Plugin for Deadline DB ###
provisioner "ansible" {
playbook_file = "./ansible/deadline_db_houdini_plugin.yml"
user = "ubuntu"
extra_arguments = [
"-vvv",
"--extra-vars",
jsonencode(local.houdini_json_vars),
"--extra-vars",
"resourcetier=${var.resourcetier} variable_host=default variable_connect_as_user=ubuntu delegate_host=localhost",
"--tags",
"install_houdini,install_deadline_db"
]
collections_path = "./ansible/collections"
roles_path = "./ansible/roles"
ansible_env_vars = ["ANSIBLE_CONFIG=ansible/ansible.cfg"]
galaxy_file = "./requirements.yml"
only = ["amazon-ebs.deadline-db-ubuntu18-ami"]
}
### Install FSX fsx_packages.yaml
provisioner "ansible" {
playbook_file = "./ansible/fsx_packages.yaml"
user = "centos"
extra_arguments = [
"-vv",
"--extra-vars",
"variable_user=deadlineuser resourcetier=${var.resourcetier} variable_host=default user_deadlineuser_pw='' package_python_interpreter=/usr/bin/python2.7"
]
collections_path = "./ansible/collections"
roles_path = "./ansible/roles"
ansible_env_vars = ["ANSIBLE_CONFIG=ansible/ansible.cfg"]
galaxy_file = "./requirements.yml"
only = [
"amazon-ebs.centos7-rendernode-ami",
# "amazon-ebs.amazonlinux2-nicedcv-nvidia-ami"
]
}
### Install Houdini ### Requires you create a SESI API Key on the Side FX website to auto download.
provisioner "ansible" {
playbook_file = "./ansible/houdini_module.yaml"
user = "centos"
extra_arguments = [
"-vv",
"--extra-vars",
jsonencode(local.houdini_json_vars),
"--extra-vars",