-
Notifications
You must be signed in to change notification settings - Fork 244
feat: migrate Packer templates to HCL2 #7689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 59 commits
878d6ab
ec9eb1d
ae4bd66
bbf594a
2813ae6
b64a1e2
fda2c78
b1e5562
5780d39
7c2414a
5320b51
254cc73
3743cd1
d624b2b
ddfd448
d4c47c6
560285a
27d56e3
621fc07
e7408e0
eb944b6
67a3c1e
c981a91
1870755
3ea4815
633a7a7
817fa00
98bc715
df13038
6d5b1ac
467561c
abe288d
17ff89b
6a35887
d69fbbf
ec0086d
2a736db
f59ea5b
71a4ac9
b93f353
388cb7d
7ed7b8f
65b9fb7
ba1fa16
873008b
8e5f620
9d2fc52
7823d1c
88ee1fd
54e81bc
32f79df
5530482
5685aaf
0db2de7
660f285
ecbf762
8b61c2c
354b240
87d67b2
a4e24c6
3b0d6d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,174 @@ | ||||||||||||||||||
| // This build block is used for all Linux VHD builds with Packer | ||||||||||||||||||
| build { | ||||||||||||||||||
| sources = ["source.azure-arm.nodelifecycle-image-builder"] | ||||||||||||||||||
|
|
||||||||||||||||||
| provisioner "shell" { | ||||||||||||||||||
| inline = ["sudo mkdir -p /opt/azure/containers", "sudo mkdir -p /opt/scripts", "sudo mkdir -p /opt/certs"] | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // These files are common to all VHDs, and will be uploaded to the Packer VM regardless of distro | ||||||||||||||||||
| dynamic "provisioner" { | ||||||||||||||||||
| for_each = "${local.common_file_upload}" | ||||||||||||||||||
| content { | ||||||||||||||||||
| labels = ["azure-arm.nodelifecycle-image-builder"] | ||||||||||||||||||
| type = "file" | ||||||||||||||||||
| source = provisioner.value.source | ||||||||||||||||||
| destination = provisioner.value.destination | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // Ubuntu-specific file uploads | ||||||||||||||||||
| dynamic "provisioner" { | ||||||||||||||||||
| for_each = "${local.ubuntu_file_upload}" | ||||||||||||||||||
|
||||||||||||||||||
| for_each = "${local.ubuntu_file_upload}" | |
| for_each = local.ubuntu_file_upload |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The when condition is checking "os_sku" but should be checking "os_version" to match the logic in the locals block (line 15 of variables.pkr.hcl) which uses os_version for Ubuntu detection. This mismatch will cause Ubuntu-specific files to not be uploaded when they should be.
| when = lower(var.os_sku) == "ubuntu" | |
| when = lower(var.os_version) == "ubuntu" |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conditional 'when' should use 'only_on' in HCL2 Packer provisioners, not 'when'. The 'when' attribute doesn't exist in Packer HCL2 syntax. To conditionally execute provisioners based on variable values, you should use the 'only' or 'except' attributes with build sources, or handle the condition within the provisioner script itself.
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dynamic provisioner blocks use "${local.azlinux_file_upload}" with unnecessary string interpolation. In HCL2, for_each expects a map or set directly, so this should be written as 'for_each = local.azlinux_file_upload' without the quotes and interpolation markers.
| for_each = "${local.azlinux_file_upload}" | |
| for_each = local.azlinux_file_upload |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The when condition is checking "os_sku" but the variable being used should likely match what determines AzureLinux/CBLMariner distribution. The logic may need to check os_version or a combination of conditions. Additionally, the condition checks for "cblmariner" but this provisioner block is labeled for "AzureLinux-specific" files, which suggests a potential naming mismatch.
| when = lower(var.os_sku) == "cblmariner" | |
| when = lower(var.os_sku) == "azlinux" |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dynamic provisioner blocks use "${local.flatcar_file_upload}" with unnecessary string interpolation. In HCL2, for_each expects a map or set directly, so this should be written as 'for_each = local.flatcar_file_upload' without the quotes and interpolation markers.
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The when condition is checking "os_sku" but should be checking "os_version" to match the logic in the locals block (line 15 of variables.pkr.hcl) which uses os_version for Flatcar detection. This mismatch will cause Flatcar-specific files to not be uploaded when they should be.
| when = lower(var.os_sku) == "flatcar" | |
| when = lower(var.os_version) == "flatcar" |
Outdated
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The source and destination are swapped. In a file provisioner, the source should be the local file path and destination should be the remote path. Currently, the aks-node-controller binary path (which should be the source) is set as the destination, and the remote path is set as the source. This should be:
source = "${local.aks_node_controller}"
destination = "/home/packer/aks-node-controller"
| destination = "${var.aks_node_controller}" | |
| source = "/home/packer/aks-node-controller" | |
| source = "${local.aks_node_controller}" | |
| destination = "/home/packer/aks-node-controller" |
Outdated
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect provisioner file configuration. The destination and source parameters are swapped. According to Packer documentation, for file provisioners, source should be the local path and destination should be the remote path. Here, var.aks_node_controller appears to be a local file path but is assigned to destination, while /home/packer/aks-node-controller should be the destination on the VM.
| destination = "${var.aks_node_controller}" | |
| source = "/home/packer/aks-node-controller" | |
| source = "/home/packer/aks-node-controller" | |
| destination = "${var.aks_node_controller}" |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inline command is using string interpolation for a list value. In HCL2, when 'inline' expects a list, you should use array syntax. Change this from 'inline = "${local.reboot_command}"' to 'inline = [local.reboot_command]' (without quotes and with square brackets).
| inline = "${local.reboot_command}" | |
| inline = [local.reboot_command] |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary string interpolation. Change inline = "${local.reboot_command}" to inline = [local.reboot_command] since inline expects a list of strings, not a single interpolated string.
| inline = "${local.reboot_command}" | |
| inline = [local.reboot_command] |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect variable reference. vhd_build_timestamp should be referenced as var.vhd_build_timestamp instead of local.vhd_build_timestamp. The value comes from the settings.json file as a variable, not a local value computed at runtime.
| "VHD_BUILD_TIMESTAMP=${local.vhd_build_timestamp}" | |
| "VHD_BUILD_TIMESTAMP=${var.vhd_build_timestamp}" |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dynamic provisioner blocks use "${local.midway_file_downloads}" with unnecessary string interpolation. In HCL2, for_each expects a map or set directly, so this should be written as 'for_each = local.midway_file_downloads' without the quotes and interpolation markers.
| for_each = "${local.midway_file_downloads}" | |
| for_each = local.midway_file_downloads |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary string interpolation. Change inline = "${local.reboot_command}" to inline = [local.reboot_command] since inline expects a list of strings, not a single interpolated string.
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inline parameter expects an array but the value is incorrectly wrapped in string interpolation syntax. It should be inline = [local.reboot_command] instead of inline = "${local.reboot_command}" to properly pass an array of commands to the shell provisioner.
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dynamic provisioner blocks use "${local.post_build_file_downloads}" with unnecessary string interpolation. In HCL2, for_each expects a map or set directly, so this should be written as 'for_each = local.post_build_file_downloads' without the quotes and interpolation markers.
| for_each = "${local.post_build_file_downloads}" | |
| for_each = local.post_build_file_downloads |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary string interpolation in for_each expressions. In HCL2, when referencing a local variable directly, you don't need the wrapping quotes and dollar sign. Change for_each = "${local.common_file_upload}" to for_each = local.common_file_upload for cleaner syntax. This applies to all for_each expressions in this build block.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,54 @@ | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| "files": [ | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| "type": "file", | ||||||||||||||||||||||
| "source": "parts/linux/cloud-init/artifacts/mariner/cse_install_mariner.sh", | ||||||||||||||||||||||
| "destination": "/home/packer/provision_installs_distro.sh" | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| "type": "file", | ||||||||||||||||||||||
| "source": "parts/linux/cloud-init/artifacts/mariner/cse_helpers_mariner.sh", | ||||||||||||||||||||||
| "destination": "/home/packer/provision_source_distro.sh" | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| "type": "file", | ||||||||||||||||||||||
| "source": "parts/linux/cloud-init/artifacts/mariner/mariner-package-update.sh", | ||||||||||||||||||||||
| "destination": "/home/packer/mariner-package-update.sh" | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| "type": "file", | ||||||||||||||||||||||
| "source": "parts/linux/cloud-init/artifacts/mariner/package-update.service", | ||||||||||||||||||||||
| "destination": "/home/packer/snapshot-update.service" | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| "type": "file", | ||||||||||||||||||||||
| "source": "parts/linux/cloud-init/artifacts/mariner/package-update.timer", | ||||||||||||||||||||||
| "destination": "/home/packer/snapshot-update.timer" | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| "type": "file", | ||||||||||||||||||||||
| "source": "vhdbuilder/scripts/linux/mariner/tool_installs_mariner.sh", | ||||||||||||||||||||||
| "destination": "/home/packer/tool_installs_distro.sh" | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| "type": "file", | ||||||||||||||||||||||
| "source": "parts/linux/cloud-init/artifacts/mariner/pam-d-system-auth", | ||||||||||||||||||||||
| "destination": "/home/packer/pam-d-system-auth" | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| "type": "file", | ||||||||||||||||||||||
| "source": "parts/linux/cloud-init/artifacts/mariner/pam-d-system-password", | ||||||||||||||||||||||
| "destination": "/home/packer/pam-d-system-password" | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| "type": "file", | ||||||||||||||||||||||
| "source": "parts/linux/cloud-init/artifacts/mariner/update_certs_mariner.service", | ||||||||||||||||||||||
| "destination": "/home/packer/update_certs.service" | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| "type": "file", | ||||||||||||||||||||||
| "source": "parts/linux/cloud-init/artifacts/update_certs.service", | ||||||||||||||||||||||
| "destination": "/home/packer/update_certs.service" | ||||||||||||||||||||||
|
Comment on lines
+47
to
+51
|
||||||||||||||||||||||
| }, | |
| { | |
| "type": "file", | |
| "source": "parts/linux/cloud-init/artifacts/update_certs.service", | |
| "destination": "/home/packer/update_certs.service" |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both file entries upload to the same destination /home/packer/update_certs.service, but from different sources. The second upload will overwrite the first one. This appears to be a duplicate or conflicting configuration. Verify which source file is the correct one to use for Azure Linux/Mariner builds.
| }, | |
| { | |
| "type": "file", | |
| "source": "parts/linux/cloud-init/artifacts/update_certs.service", | |
| "destination": "/home/packer/update_certs.service" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dynamic provisioner blocks use "${local.common_file_upload}" with unnecessary string interpolation. In HCL2, for_each expects a map or set directly, so this should be written as 'for_each = local.common_file_upload' without the quotes and interpolation markers.