Merge "[CPS] Migrate CPS jobs to Java 17"
[ci-management.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 "cloud_auth_url" {
11   type    = string
12   default = null
13 }
14
15 variable "cloud_tenant" {
16   type    = string
17   default = null
18 }
19
20 variable "cloud_user" {
21   type    = string
22   default = null
23 }
24
25 variable "cloud_pass" {
26   type    = string
27   default = null
28 }
29
30 variable "source_ami_filter_name" {
31   type    = string
32   default = null
33 }
34
35 variable "source_ami_filter_product_code" {
36   type    = string
37   default = null
38 }
39
40 variable "source_ami_filter_owner" {
41   type    = string
42   default = null
43 }
44
45 variable "ansible_roles_path" {
46   type    = string
47   default = ".galaxy"
48 }
49
50 variable "arch" {
51   type    = string
52   default = "x86_64"
53 }
54
55 variable "base_image" {
56   type = string
57   default = null
58 }
59
60 variable "cloud_network" {
61   type = string
62   default = null
63 }
64
65 variable "cloud_region" {
66   type    = string
67   default = "ca-ymq-1"
68 }
69
70 variable "cloud_user_data" {
71   type = string
72   default = null
73 }
74
75 variable "distro" {
76   type = string
77   default = null
78 }
79
80 variable "docker_source_image" {
81   type = string
82   default = null
83 }
84
85 variable "flavor" {
86   type    = string
87   default = "v2-highcpu-1"
88 }
89
90 variable "ssh_proxy_host" {
91   type    = string
92   default = ""
93 }
94
95 variable "ssh_user" {
96   type = string
97   default = null
98 }
99
100 variable "vm_image_disk_format" {
101   type    = string
102   default = ""
103 }
104
105 variable "vm_use_block_storage" {
106   type    = string
107   default = "true"
108 }
109
110 variable "vm_volume_size" {
111   type    = string
112   default = "20"
113 }
114
115 source "docker" "helm" {
116   changes = ["ENTRYPOINT [\"\"]", "CMD [\"\"]"]
117   commit  = true
118   image   = "${var.docker_source_image}"
119 }
120
121 source "openstack" "helm" {
122   domain_name       = "Default"
123   flavor            = "${var.flavor}"
124   identity_endpoint = "${var.cloud_auth_url}"
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   user_data_file    = "${var.cloud_user_data}"
138   username          = "${var.cloud_user}"
139 }
140
141 build {
142   sources = ["source.docker.helm", "source.openstack.helm"]
143
144   provisioner "shell" {
145     execute_command = "chmod +x {{ .Path }}; if [ \"$UID\" == \"0\" ]; then {{ .Vars }} '{{ .Path }}'; else {{ .Vars }} sudo -E '{{ .Path }}'; fi"
146     scripts         = ["common-packer/provision/install-python.sh"]
147   }
148
149   provisioner "shell-local" {
150     command = "./common-packer/ansible-galaxy.sh ${var.ansible_roles_path}"
151   }
152
153   provisioner "ansible" {
154     ansible_env_vars   = [
155       "ANSIBLE_NOCOWS=1",
156       "ANSIBLE_PIPELINING=True",
157       "ANSIBLE_ROLES_PATH=${var.ansible_roles_path}",
158       "ANSIBLE_CALLBACK_WHITELIST=profile_tasks",
159       "ANSIBLE_STDOUT_CALLBACK=debug"
160     ]
161     command            = "./common-packer/ansible-playbook.sh"
162     extra_arguments    = [
163       "--scp-extra-args", "'-O'",
164       "--ssh-extra-args", "-o IdentitiesOnly=yes -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedAlgorithms=+ssh-rsa"
165     ]
166     playbook_file      = "provision/helm.yaml"
167     skip_version_check = true
168   }
169 }