4a0916026103c4a605e1de1a8b37c46a4d14760e
[csit.git] / fdio.infra.packer / aws_c5n / ubuntu_focal.pkr.hcl
1 packer {
2   required_plugins {
3     amazon = {
4       version = ">= 1.0.1"
5       source  = "github.com/hashicorp/amazon"
6     }
7   }
8 }
9
10 variable "first_run_commands" {
11   description = "Commands to run before deployment via remote-exec"
12   type        = list(string)
13   default     = [
14     ""
15   ]
16 }
17
18 variable "last_run_commands" {
19   description = "Commands to run after deployment via remote-exec"
20   type        = list(string)
21   default     = [
22     "sudo sed -i 's/Unattended-Upgrade \"1\"/Unattended-Upgrade \"0\"/g' /etc/apt/apt.conf.d/20auto-upgrades"
23   ]
24 }
25
26 variable "ansible_file_path" {
27   description = "Path to Ansible playbook"
28   type        = string
29   default     = "../../fdio.infra.ansible/site.yaml"
30 }
31
32 variable "ansible_python_executable" {
33   description = "Path to Python interpreter"
34   type        = string
35   default     = "/usr/bin/python3"
36 }
37
38 variable "ansible_topology_path" {
39   description = "Path to Ansible playbook which creates a topology file"
40   type        = string
41   default     = "../../fdio.infra.ansible/cloud_topology.yaml"
42 }
43
44 variable "ansible_provision_pwd" {
45   description = "Password used for ansible provisioning (ansible_ssh_pass)"
46   type        = string
47   default     = "Csit1234"
48 }
49
50 source "amazon-ebs" "csit_c5n_ubuntu_focal_sut" {
51   ami_name         = "csit_c5n_ubuntu_focal_sut"
52   ami_description  = "CSIT SUT image based on Ubuntu Focal"
53   ena_support      = true
54   instance_type    = "c5n.4xlarge"
55   launch_block_device_mappings {
56     device_name = "/dev/sda1"
57     volume_size = 40
58     volume_type = "gp2"
59   }
60   force_deregister = true
61   region           = "eu-central-1"
62   skip_create_ami  = false
63   source_ami       = "ami-0a875db8a031a9efb"
64   ssh_username     = "ubuntu"
65 }
66
67 source "amazon-ebs" "csit_c5n_ubuntu_focal_tg" {
68   ami_name         = "csit_c5n_ubuntu_focal_tg"
69   ami_description  = "CSIT TG image based on Ubuntu Focal"
70   ena_support      = true
71   instance_type    = "c5n.4xlarge"
72   launch_block_device_mappings {
73     device_name = "/dev/sda1"
74     volume_size = 40
75     volume_type = "gp2"
76   }
77   force_deregister = true
78   region           = "eu-central-1"
79   skip_create_ami  = false
80   source_ami       = "ami-0a875db8a031a9efb"
81   ssh_username     = "ubuntu"
82 }
83
84 build {
85   name = "csit_c5n_ubuntu_focal_sut-packer"
86   sources = [
87     "source.amazon-ebs.csit_c5n_ubuntu_focal_sut"
88   ]
89   provisioner "shell" {
90     inline = var.first_run_commands
91   }
92   provisioner "ansible" {
93     playbook_file = var.ansible_file_path
94     user          = "ubuntu"
95     groups        = ["sut_aws"]
96     extra_arguments = [
97       "--extra-vars", "ansible_ssh_pass=${var.ansible_provision_pwd}",
98       "--extra-vars", "ansible_python_interpreter=${var.ansible_python_executable}",
99       "--extra-vars", "aws=true"
100     ]
101   }
102   provisioner "shell" {
103     inline = var.last_run_commands
104   }
105 }
106
107 build {
108   name = "csit_c5n_ubuntu_focal_tg-packer"
109   sources = [
110     "source.amazon-ebs.csit_c5n_ubuntu_focal_tg"
111   ]
112   provisioner "shell" {
113     inline = var.first_run_commands
114   }
115   provisioner "ansible" {
116     playbook_file = var.ansible_file_path
117     user          = "ubuntu"
118     groups        = ["tg_aws"]
119     extra_arguments = [
120       "--extra-vars", "ansible_ssh_pass=${var.ansible_provision_pwd}",
121       "--extra-vars", "ansible_python_interpreter=${var.ansible_python_executable}",
122       "--extra-vars", "aws=true"
123     ]
124   }
125   provisioner "shell" {
126     inline = var.last_run_commands
127   }
128 }