Chore: Update common-packer to latest v0.14.0
[releng/builder.git] / packer / templates / helm.pkr.hcl
1 packer {
2   required_plugins {
3     openstack = {
4       version = ">= 1.0.0"
5       source  = "github.com/hashicorp/openstack"
6     }
7   }
8 }
9
10 variable "ansible_roles_path" {
11   type    = string
12   default = ".galaxy"
13 }
14
15 variable "arch" {
16   type    = string
17   default = "x86_64"
18 }
19
20 variable "base_image" {
21   type = string
22   default = null
23 }
24
25 variable "cloud_network" {
26   type = string
27   default = null
28 }
29
30 variable "cloud_region" {
31   type    = string
32   default = "ca-ymq-1"
33 }
34
35 variable "cloud_auth_url" {
36   type    = string
37   default = null
38 }
39
40 variable "cloud_tenant" {
41   type    = string
42   default = null
43 }
44
45 variable "cloud_user" {
46   type    = string
47   default = null
48 }
49
50 variable "cloud_pass" {
51   type    = string
52   default = null
53 }
54
55 variable "cloud_user_data" {
56   type = string
57   default = null
58 }
59
60 variable "distro" {
61   type = string
62   default = null
63 }
64
65 variable "docker_source_image" {
66   type = string
67   default = null
68 }
69
70 variable "flavor" {
71   type    = string
72   default = "v3-standard-2"
73 }
74
75 variable "ssh_proxy_host" {
76   type    = string
77   default = ""
78 }
79
80 variable "source_ami_filter_name" {
81   type    = string
82   default = null
83 }
84
85 variable "source_ami_filter_product_code" {
86   type    = string
87   default = null
88 }
89
90 variable "source_ami_filter_owner" {
91   type    = string
92   default = null
93 }
94
95 variable "ssh_user" {
96   type = string
97 }
98
99 variable "vm_image_disk_format" {
100   type    = string
101   default = ""
102 }
103
104 variable "vm_use_block_storage" {
105   type    = string
106   default = "true"
107 }
108
109 variable "vm_volume_size" {
110   type    = string
111   default = "20"
112 }
113
114 source "docker" "helm" {
115   changes = ["ENTRYPOINT [\"\"]", "CMD [\"\"]"]
116   commit  = true
117   image   = "${var.docker_source_image}"
118 }
119
120 source "openstack" "helm" {
121   domain_name       = "Default"
122   flavor            = "v1-standard-1"
123   identity_endpoint = "${var.cloud_auth_url}"
124   image_disk_format = "${var.vm_image_disk_format}"
125   image_name        = "ZZCI - ${var.distro} - helm - ${var.arch} - ${legacy_isotime("20060102-150405.000")}"
126   instance_name     = "${var.distro}-builder-${uuidv4()}"
127   metadata = {
128     ci_managed = "yes"
129   }
130   networks                = ["${var.cloud_network}"]
131   password                = "${var.cloud_pass}"
132   region                  = "ca-ymq-1"
133   source_image_name       = "${var.base_image}"
134   ssh_proxy_host          = "${var.ssh_proxy_host}"
135   ssh_username            = "${var.ssh_user}"
136   tenant_name             = "${var.cloud_tenant}"
137   use_blockstorage_volume = "${var.vm_use_block_storage}"
138   user_data_file          = "${var.cloud_user_data}"
139   username                = "${var.cloud_user}"
140   volume_size             = "${var.vm_volume_size}"
141 }
142
143 # a build block invokes sources and runs provisioning steps on them. The
144 # documentation for build blocks can be found here:
145 # https://www.packer.io/docs/templates/hcl_templates/blocks/build
146 build {
147   sources = ["source.docker.helm", "source.openstack.helm"]
148
149   provisioner "shell" {
150     execute_command = "chmod +x {{ .Path }}; if [ \"$UID\" == \"0\" ]; then {{ .Vars }} '{{ .Path }}'; else {{ .Vars }} sudo -E '{{ .Path }}'; fi"
151     scripts         = ["common-packer/provision/install-python.sh"]
152   }
153
154   provisioner "shell-local" {
155     command = "./common-packer/ansible-galaxy.sh ${var.ansible_roles_path}"
156   }
157
158   provisioner "ansible" {
159     ansible_env_vars   = ["ANSIBLE_NOCOWS=1", "ANSIBLE_PIPELINING=True", "ANSIBLE_ROLES_PATH=${var.ansible_roles_path}", "ANSIBLE_CALLBACK_WHITELIST=profile_tasks", "ANSIBLE_STDOUT_CALLBACK=debug"]
160     command            = "./common-packer/ansible-playbook.sh"
161     extra_arguments    = ["--scp-extra-args", "'-O'", "--ssh-extra-args", "-o IdentitiesOnly=yes -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedAlgorithms=+ssh-rsa"]
162     playbook_file      = "provision/helm.yaml"
163     skip_version_check = true
164   }
165 }