135d1c353e8d45b65a6441ffcae949eb68d5e465
[csit.git] / fdio.infra / packer-aws-sut / ubuntu_jammy_arm.pkr.hcl
1 packer {
2   required_plugins {
3     amazon = {
4       version = ">= 1.2.6"
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_ubuntu_jammy_arm_sut" {
51   ami_name        = "csit_ubuntu_jammy_arm_sut"
52   ami_description = "CSIT SUT image based on Ubuntu jammy"
53   ena_support     = true
54   instance_type   = "c6gn.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-0329d3839379bfd15"
64   ssh_username     = "ubuntu"
65 }
66
67 build {
68   name = "csit_ubuntu_jammy_arm_sut-packer"
69   sources = [
70     "source.amazon-ebs.csit_ubuntu_jammy_arm_sut"
71   ]
72   provisioner "shell" {
73     inline = var.first_run_commands
74   }
75   provisioner "ansible" {
76     playbook_file = var.ansible_file_path
77     user          = "ubuntu"
78     groups        = ["sut_aws"]
79     extra_arguments = [
80       "--extra-vars", "ansible_ssh_pass=${var.ansible_provision_pwd}",
81       "--extra-vars", "ansible_python_interpreter=${var.ansible_python_executable}",
82       "--extra-vars", "aws=true"
83     ]
84   }
85   provisioner "shell" {
86     inline = var.last_run_commands
87   }
88 }