aboutsummaryrefslogtreecommitdiffstats
path: root/fdio.infra/packer-aws-sut/ubuntu_jammy_arm.pkr.hcl
blob: 6a81b70e563b1e2a8e8c0ff4b041436dc63576b9 (plain)
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
packer {
  required_plugins {
    amazon = {
      version = ">= 1.2.6"
      source  = "github.com/hashicorp/amazon"
    }
  }
}

variable "first_run_commands" {
  description = "Commands to run before deployment via remote-exec"
  type        = list(string)
  default = [
    ""
  ]
}

variable "last_run_commands" {
  description = "Commands to run after deployment via remote-exec"
  type        = list(string)
  default = [
    "sudo sed -i 's/Unattended-Upgrade \"1\"/Unattended-Upgrade \"0\"/g' /etc/apt/apt.conf.d/20auto-upgrades"
  ]
}

variable "ansible_file_path" {
  description = "Path to Ansible playbook"
  type        = string
  default     = "../../fdio.infra.ansible/site.yaml"
}

variable "ansible_python_executable" {
  description = "Path to Python interpreter"
  type        = string
  default     = "/usr/bin/python3"
}

variable "ansible_topology_path" {
  description = "Path to Ansible playbook which creates a topology file"
  type        = string
  default     = "../../fdio.infra.ansible/cloud_topology.yaml"
}

variable "ansible_provision_pwd" {
  description = "Password used for ansible provisioning (ansible_ssh_pass)"
  type        = string
  default     = "Csit1234"
}

source "amazon-ebs" "csit_ubuntu_jammy_arm_sut" {
  ami_name        = "csit_ubuntu_jammy_arm_sut"
  ami_description = "CSIT SUT image based on Ubuntu jammy"
  ena_support     = true
  instance_type   = "c6gn.4xlarge"
  launch_block_device_mappings {
    device_name = "/dev/sda1"
    volume_size = 40
    volume_type = "gp2"
  }
  force_deregister = true
  region           = "eu-central-1"
  skip_create_ami  = false
  source_ami       = "ami-0329d3839379bfd15"
  ssh_username     = "ubuntu"
}

source "amazon-ebs" "csit_ubuntu_jammy_arm_tg" {
  ami_name        = "csit_ubuntu_jammy_arm_tg"
  ami_description = "CSIT TG image based on Ubuntu jammy"
  ena_support     = true
  instance_type   = "c6gn.4xlarge"
  launch_block_device_mappings {
    device_name = "/dev/sda1"
    volume_size = 40
    volume_type = "gp2"
  }
  force_deregister = true
  region           = "eu-central-1"
  skip_create_ami  = false
  source_ami       = "ami-0329d3839379bfd15"
  ssh_username     = "ubuntu"
}

build {
  name = "csit_ubuntu_jammy_arm_sut-packer"
  sources = [
    "source.amazon-ebs.csit_ubuntu_jammy_arm_sut"
  ]
  provisioner "shell" {
    inline = var.first_run_commands
  }
  provisioner "ansible" {
    playbook_file = var.ansible_file_path
    user          = "ubuntu"
    groups        = ["sut_aws"]
    extra_arguments = [
      "--extra-vars", "ansible_ssh_pass=${var.ansible_provision_pwd}",
      "--extra-vars", "ansible_python_interpreter=${var.ansible_python_executable}",
      "--extra-vars", "aws=true"
    ]
  }
  provisioner "shell" {
    inline = var.last_run_commands
  }
}

build {
  name = "csit_ubuntu_jammy_arm_tg-packer"
  sources = [
    "source.amazon-ebs.csit_ubuntu_jammy_arm_tg"
  ]
  provisioner "shell" {
    inline = var.first_run_commands
  }
  provisioner "ansible" {
    playbook_file = var.ansible_file_path
    user          = "ubuntu"
    groups        = ["tg_aws"]
    extra_arguments = [
      "--extra-vars", "ansible_ssh_pass=${var.ansible_provision_pwd}",
      "--extra-vars", "ansible_python_interpreter=${var.ansible_python_executable}",
      "--extra-vars", "aws=true"
    ]
  }
  provisioner "shell" {
    inline = var.last_run_commands
  }
}