Skip to content

Commit 8e8dd7e

Browse files
authored
Merge pull request #577 from hashicorp/backport-2.5.2
Backport Release v2.5.2
2 parents c41a85c + ca29cb2 commit 8e8dd7e

46 files changed

Lines changed: 509 additions & 147 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/acceptance-tests.yaml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,31 @@ jobs:
8181
echo "ARM_SUBSCRIPTION_ID=${{ secrets.ARM_SUBSCRIPTION_ID}}" >> $GITHUB_ENV
8282
echo "ARM_CLIENT_ID=${{ secrets.ARM_CLIENT_ID}}" >> $GITHUB_ENV
8383
echo "ARM_CLIENT_SECRET=${{ secrets.ARM_CLIENT_SECRET}}" >> $GITHUB_ENV
84-
echo "ARM_RESOURCE_GROUP_NAME=packercigroup" >> $GITHUB_ENV
85-
echo "ARM_STORAGE_ACCOUNT=packerciaccount" >> $GITHUB_ENV
86-
echo "ARM_RESOURCE_PREFIX=packerci" >> $GITHUB_ENV
84+
BASE_RG="packercigroup"
85+
BASE_STORAGE="packerciaccount"
86+
BASE_PREFIX="packerci"
87+
SUFFIX=$(printf "%s" "${GITHUB_RUN_ID}" | tail -c 6)
88+
STORAGE_BASE=$(echo "${BASE_STORAGE}" | tr '[:upper:]' '[:lower:]' | tr -d '-')
89+
MAX_STORAGE_LEN=$((24 - ${#SUFFIX}))
90+
STORAGE_BASE=${STORAGE_BASE:0:${MAX_STORAGE_LEN}}
91+
92+
echo "ARM_RESOURCE_GROUP_NAME_BASE=${BASE_RG}" >> $GITHUB_ENV
93+
echo "ARM_STORAGE_ACCOUNT_BASE=${BASE_STORAGE}" >> $GITHUB_ENV
94+
echo "ARM_RESOURCE_PREFIX_BASE=${BASE_PREFIX}" >> $GITHUB_ENV
95+
echo "ARM_RESOURCE_SUFFIX=${SUFFIX}" >> $GITHUB_ENV
96+
97+
echo "ARM_RESOURCE_GROUP_NAME=${BASE_RG}-${SUFFIX}" >> $GITHUB_ENV
98+
echo "ARM_STORAGE_ACCOUNT=${STORAGE_BASE}${SUFFIX}" >> $GITHUB_ENV
99+
echo "ARM_RESOURCE_PREFIX=${BASE_PREFIX}_${SUFFIX}" >> $GITHUB_ENV
100+
echo "ARM_STORAGE_CONTAINER_NAME=packeracc" >> $GITHUB_ENV
101+
echo "ARM_TEMP_RESOURCE_GROUP_NAME=${BASE_PREFIX}-${SUFFIX}-acceptance-test-managed-cli" >> $GITHUB_ENV
87102
echo "ARM_TENANT_ID=${{ secrets.ARM_TENANT_ID }}" >> $GITHUB_ENV
88103
104+
KV_BASE=$(echo "${BASE_PREFIX}" | tr '[:upper:]' '[:lower:]' | tr -d '-' | tr -d '_')
105+
KV_BASE_MAX=$((24 - ${#SUFFIX} - 2))
106+
KV_BASE=${KV_BASE:0:${KV_BASE_MAX}}
107+
echo "ARM_KEY_VAULT_NAME=${KV_BASE}kv${SUFFIX}" >> $GITHUB_ENV
108+
89109
OBJECT_ID=$(az ad sp show --id "${{ secrets.ARM_CLIENT_ID }}" | jq -r '.id')
90110
echo "AZURE_OBJECT_ID=${OBJECT_ID}" >> $GITHUB_ENV
91111

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@
33
Please refer to [releases](https://github.com/hashicorp/packer-plugin-azure/releases) for the latest CHANGELOG information.
44

55
---
6+
## 2.5.2 (February 4, 2026)
7+
8+
## What's Changed
9+
### Exciting New Features
10+
11+
### Bug Fixes
12+
* BUG: Updates tests for permissions and polling [GH-572](https://github.com/hashicorp/packer-plugin-azure/pull/572)
13+
14+
### Other Changes
15+
* Adds dynamic resource name suffixing for isolation of Acceptance tests [GH-575](https://github.com/hashicorp/packer-plugin-azure/pull/575)
16+
* Updates Go version to 1.24.12 in module file [GH-573](https://github.com/hashicorp/packer-plugin-azure/pull/573)
17+
* Fix various lint warnings. [GH-566](https://github.com/hashicorp/packer-plugin-azure/pull/566)
18+
* Staticcheck/QF1003: Replace if-else with switch-case for OSType checks. [GH-565](https://github.com/hashicorp/packer-plugin-azure/pull/565)
19+
* Replace deprecated ui.Message with ui.Say [GH-564](https://github.com/hashicorp/packer-plugin-azure/pull/564)
20+
21+
**Full Changelog**: https://github.com/hashicorp/packer-plugin-azure/compare/v2.5.1...v2.5.2
22+
623
## 2.5.1 (December 18, 2025)
724

825
## What's Changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Then, run [`packer init`](https://www.packer.io/docs/commands/init).
1919
packer {
2020
required_plugins {
2121
azure = {
22-
version = ">= 2.5.1"
22+
version = ">= 2.5.2"
2323
source = "github.com/hashicorp/azure"
2424
}
2525
}

builder/azure/arm/artifact_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ SharedImageGalleryReplicatedRegions: fake-region-1, fake-region-2
258258
"sig_replicated_regions",
259259
}
260260
for _, key := range expectedSIGLabels {
261-
key := key
262261
v, ok := image.Labels[key]
263262
if !ok {
264263
t.Errorf("expected labels to have %q but no entry was found", key)
@@ -352,7 +351,6 @@ SharedImageGalleryReplicatedRegions: fake-region-1, fake-region-2
352351
"sig_replicated_regions",
353352
}
354353
for _, key := range expectedSIGLabels {
355-
key := key
356354
v, ok := image.Labels[key]
357355
if !ok {
358356
t.Errorf("expected labels to have %q but no entry was found", key)

builder/azure/arm/builder.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
120120
OidcRequestToken: b.config.ClientConfig.OidcRequestToken,
121121
}
122122

123-
ui.Message("Creating Azure Resource Manager (ARM) client ...")
123+
ui.Say("Creating Azure Resource Manager (ARM) client ...")
124124
azureClient, err := NewAzureClient(
125125
ctx,
126126
b.config.StorageAccount,
@@ -132,7 +132,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
132132
if err != nil {
133133
return nil, err
134134
}
135-
ui.Message("ARM Client successfully created")
135+
ui.Say("ARM Client successfully created")
136136

137137
resolver := newResourceResolver(azureClient)
138138
if err := resolver.Resolve(&b.config); err != nil {
@@ -145,7 +145,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
145145
if b.config.ClientConfig.ObjectID == "" {
146146
b.config.ClientConfig.ObjectID = objectID
147147
} else {
148-
ui.Message("You have provided Object_ID which is no longer needed, Azure Packer ARM builder determines this automatically using the Azure Access Token")
148+
ui.Say("You have provided Object_ID which is no longer needed, Azure Packer ARM builder determines this automatically using the Azure Access Token")
149149
}
150150

151151
if b.config.ClientConfig.ObjectID == "" && b.config.OSType != constants.Target_Linux {
@@ -155,7 +155,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
155155
// If the user is bringing their own vnet, don't warn, if its an invalid SKU it will get disabled at a different date and Microsoft will send out warings
156156
if b.config.VirtualNetworkName == "" {
157157
if b.config.PublicIpSKU == string(publicipaddresses.PublicIPAddressSkuNameBasic) {
158-
ui.Message(publicIPWarning)
158+
ui.Say(publicIPWarning)
159159
}
160160
}
161161

@@ -422,7 +422,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
422422
}
423423

424424
if b.config.SkipCreateBuildKeyVault {
425-
ui.Message("Skipping build keyvault creation...")
425+
ui.Say("Skipping build keyvault creation...")
426426
} else if b.config.BuildKeyVaultName == "" {
427427
keyVaultDeploymentName := b.stateBag.Get(constants.ArmKeyVaultDeploymentName).(string)
428428
steps = append(steps,
@@ -513,12 +513,12 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
513513
steps = append(steps, captureSteps...)
514514

515515
if b.config.PackerDebug {
516-
ui.Message(fmt.Sprintf("temp admin user: '%s'", b.config.UserName))
517-
ui.Message(fmt.Sprintf("temp admin password: '%s'", b.config.Password))
516+
ui.Say(fmt.Sprintf("temp admin user: '%s'", b.config.UserName))
517+
ui.Say(fmt.Sprintf("temp admin password: '%s'", b.config.Password))
518518

519519
if len(b.config.Comm.SSHPrivateKey) != 0 {
520520
debugKeyPath := fmt.Sprintf("%s-%s.pem", b.config.PackerBuildName, b.config.tmpComputeName)
521-
ui.Message(fmt.Sprintf("temp ssh key: %s", debugKeyPath))
521+
ui.Say(fmt.Sprintf("temp ssh key: %s", debugKeyPath))
522522

523523
b.writeSSHPrivateKey(ui, debugKeyPath)
524524
}
@@ -782,7 +782,7 @@ func (b *Builder) getVHDArtifact(vhdArtifact *VHDArtifact) {
782782
additionalDiskCount := len(b.config.AdditionalDiskSize)
783783
if additionalDiskCount > 0 {
784784
dataDisks := make([]AdditionalDiskArtifact, additionalDiskCount)
785-
for i := 0; i < additionalDiskCount; i++ {
785+
for i := range additionalDiskCount {
786786
dataDisks[i].AdditionalDiskUri = fmt.Sprintf("%s%s/%s%s-%d.vhd",
787787
b.config.storageAccountBlobEndpoint, b.config.CaptureContainerName, b.config.CaptureNamePrefix, b.config.tmpDataDiskName, i+1)
788788
}

builder/azure/arm/builder_acc_test.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package arm
1919
// ** ARM_RESOURCE_GROUP_NAME - Resource group
2020
// ** ARM_STORAGE_ACCOUNT - a storage account located in above resource group
2121
// ** ARM_RESOURCE_PREFIX - String prefix for resources unique name constraints
22+
// ** ARM_STORAGE_CONTAINER_NAME - storage container name for blob-based tests
23+
// ** ARM_TEMP_RESOURCE_GROUP_NAME - temp resource group name for CLI-based tests
2224
// ** For example SIG gallery names must be unique not just within the resource group, but within a subscription, and a user may not have access to all SIGs in a subscription.
2325
// * As well as the following misc env variables
2426
// ** ARM_SSH_PRIVATE_KEY_FILE - the file location of a PEM encoded RSA SSH Private Key (ed25519 is not supported by Azure),
@@ -337,7 +339,8 @@ func testBuilderUserDataLinux(userdata string) string {
337339
"client_secret": "{{env `+"`ARM_CLIENT_SECRET`"+`}}",
338340
"subscription_id": "{{env `+"`ARM_SUBSCRIPTION_ID`"+`}}",
339341
"storage_account": "{{env `+"`ARM_STORAGE_ACCOUNT`"+`}}",
340-
"resource_group_name": "{{env `+"`ARM_RESOURCE_GROUP_NAME`"+`}}"
342+
"resource_group_name": "{{env `+"`ARM_RESOURCE_GROUP_NAME`"+`}}",
343+
"capture_container_name": "{{env `+"`ARM_STORAGE_CONTAINER_NAME`"+`}}"
341344
},
342345
"builders": [{
343346
"type": "azure-arm",
@@ -348,7 +351,7 @@ func testBuilderUserDataLinux(userdata string) string {
348351
349352
"storage_account": "{{user `+"`storage_account`"+`}}",
350353
"resource_group_name": "{{user `+"`resource_group_name`"+`}}",
351-
"capture_container_name": "packeracc",
354+
"capture_container_name": "{{user `+"`capture_container_name`"+`}}",
352355
"capture_name_prefix": "testBuilderUserDataLinux",
353356
354357
"os_type": "Linux",
@@ -517,7 +520,8 @@ const testBuilderAccBlobWindows = `
517520
"client_secret": "{{env ` + "`ARM_CLIENT_SECRET`" + `}}",
518521
"subscription_id": "{{env ` + "`ARM_SUBSCRIPTION_ID`" + `}}",
519522
"storage_account": "{{env ` + "`ARM_STORAGE_ACCOUNT`" + `}}",
520-
"resource_group_name": "{{env ` + "`ARM_RESOURCE_GROUP_NAME`" + `}}"
523+
"resource_group_name": "{{env ` + "`ARM_RESOURCE_GROUP_NAME`" + `}}",
524+
"capture_container_name": "{{env ` + "`ARM_STORAGE_CONTAINER_NAME`" + `}}"
521525
},
522526
"builders": [{
523527
"type": "azure-arm",
@@ -528,7 +532,7 @@ const testBuilderAccBlobWindows = `
528532
529533
"storage_account": "{{user ` + "`storage_account`" + `}}",
530534
"resource_group_name": "{{user ` + "`resource_group_name`" + `}}",
531-
"capture_container_name": "packeracc",
535+
"capture_container_name": "{{user ` + "`capture_container_name`" + `}}",
532536
"capture_name_prefix": "testBuilderAccBlobWin",
533537
534538
"os_type": "Windows",
@@ -555,7 +559,8 @@ const testBuilderAccBlobLinux = `
555559
"resource_group_name": "{{env ` + "`ARM_RESOURCE_GROUP_NAME`" + `}}",
556560
"client_secret": "{{env ` + "`ARM_CLIENT_SECRET`" + `}}",
557561
"subscription_id": "{{env ` + "`ARM_SUBSCRIPTION_ID`" + `}}",
558-
"storage_account": "{{env ` + "`ARM_STORAGE_ACCOUNT`" + `}}"
562+
"storage_account": "{{env ` + "`ARM_STORAGE_ACCOUNT`" + `}}",
563+
"capture_container_name": "{{env ` + "`ARM_STORAGE_CONTAINER_NAME`" + `}}"
559564
},
560565
"builders": [{
561566
"type": "azure-arm",
@@ -566,7 +571,7 @@ const testBuilderAccBlobLinux = `
566571
567572
"storage_account": "{{user ` + "`storage_account`" + `}}",
568573
"resource_group_name": "{{user ` + "`resource_group_name`" + `}}",
569-
"capture_container_name": "packeracc",
574+
"capture_container_name": "{{user ` + "`capture_container_name`" + `}}",
570575
"capture_name_prefix": "testBuilderAccBlobLinux",
571576
572577
"os_type": "Linux",
@@ -583,7 +588,8 @@ const testBuilderAccBlobLinux = `
583588
const testBuilderAccManagedDiskLinuxAzureCLI = `
584589
{
585590
"variables": {
586-
"resource_group_name": "{{env ` + "`ARM_RESOURCE_GROUP_NAME`" + `}}"
591+
"resource_group_name": "{{env ` + "`ARM_RESOURCE_GROUP_NAME`" + `}}",
592+
"temp_resource_group_name": "{{env ` + "`ARM_TEMP_RESOURCE_GROUP_NAME`" + `}}"
587593
},
588594
"builders": [{
589595
"type": "azure-arm",
@@ -592,7 +598,7 @@ const testBuilderAccManagedDiskLinuxAzureCLI = `
592598
593599
"managed_image_resource_group_name": "{{user ` + "`resource_group_name`" + `}}",
594600
"managed_image_name": "testBuilderAccManagedDiskLinuxAzureCLI-{{timestamp}}",
595-
"temp_resource_group_name": "packer-acceptance-test-managed-cli",
601+
"temp_resource_group_name": "{{user ` + "`temp_resource_group_name`" + `}}",
596602
597603
"os_type": "Linux",
598604
"image_publisher": "Canonical",

builder/azure/arm/config.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ func (c *Config) formatCertificateForKeyVault(privateKey *rsa.PrivateKey) (strin
817817
return "", err
818818
}
819819

820-
pfxBytes, err := pkcs12.Encode(derBytes, privateKey, c.tmpCertificatePassword)
820+
pfxBytes, err := pkcs12.EncodeModern(derBytes, privateKey, c.tmpCertificatePassword)
821821
if err != nil {
822822
err = fmt.Errorf("Failed to encode certificate as PFX: %s", err)
823823
return "", err
@@ -1197,9 +1197,8 @@ func assertRequiredParametersSet(c *Config, errs *packersdk.MultiError) {
11971197
toInt := func(b bool) int {
11981198
if b {
11991199
return 1
1200-
} else {
1201-
return 0
12021200
}
1201+
return 0
12031202
}
12041203

12051204
isImageUrl := c.ImageUrl != ""
@@ -1576,15 +1575,16 @@ func assertRequiredParametersSet(c *Config, errs *packersdk.MultiError) {
15761575
if c.LicenseType != "" {
15771576
// Assumes OS is case-sensitive match as it has already been
15781577
// normalized earlier in function
1579-
if c.OSType == constants.Target_Linux {
1578+
switch c.OSType {
1579+
case constants.Target_Linux:
15801580
if strings.EqualFold(c.LicenseType, constants.License_RHEL) {
15811581
c.LicenseType = constants.License_RHEL
15821582
} else if strings.EqualFold(c.LicenseType, constants.License_SUSE) {
15831583
c.LicenseType = constants.License_SUSE
15841584
} else {
15851585
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("The license_type %q is invalid for Linux, only RHEL_BYOS or SLES_BYOS are supported", c.LicenseType))
15861586
}
1587-
} else if c.OSType == constants.Target_Windows {
1587+
case constants.Target_Windows:
15881588
if strings.EqualFold(c.LicenseType, constants.License_Windows_Client) {
15891589
c.LicenseType = constants.License_Windows_Client
15901590
} else if strings.EqualFold(c.LicenseType, constants.License_Windows_Server) {
@@ -1724,7 +1724,7 @@ func isValidAzureName(re *regexp.Regexp, rgn string) bool {
17241724
// 4) Contains a special character
17251725
// 5) Control characters are not allowed (a very specific case - not included in this validation)
17261726
func isValidPassword(password string) bool {
1727-
if !(len(password) >= 8 && len(password) <= 123) {
1727+
if len(password) < 8 || len(password) > 123 {
17281728
return false
17291729
}
17301730

@@ -1775,7 +1775,6 @@ func (c *Config) validateLocationZoneResiliency(say func(s string)) {
17751775
zones["switzerlandnorth"] = struct{}{}
17761776
zones["uksouth"] = struct{}{}
17771777
zones["usgovvirginia"] = struct{}{}
1778-
zones["westeurope"] = struct{}{}
17791778
zones["westus2"] = struct{}{}
17801779
zones["westus3"] = struct{}{}
17811780

builder/azure/arm/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ func TestConfigShouldAcceptTag(t *testing.T) {
933933

934934
func TestConfigShouldRejectTagsInExcessOf50AcceptTags(t *testing.T) {
935935
tooManyTags := map[string]string{}
936-
for i := 0; i < 51; i++ {
936+
for i := range 51 {
937937
tooManyTags[fmt.Sprintf("tag%.2d", i)] = "ignored"
938938
}
939939

@@ -2096,7 +2096,7 @@ func TestPlanInfoPromotionCode(t *testing.T) {
20962096
// exceeds the max tag amount, the builder should reject the configuration.
20972097
func TestPlanInfoTooManyTagsErrors(t *testing.T) {
20982098
exactMaxNumberOfTags := map[string]string{}
2099-
for i := 0; i < 50; i++ {
2099+
for i := range 50 {
21002100
exactMaxNumberOfTags[fmt.Sprintf("tag%.2d", i)] = "ignored"
21012101
}
21022102

builder/azure/arm/step_capture_image.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (s *StepCaptureImage) Run(ctx context.Context, state multistep.StateBag) mu
192192
var dataDiskName = s.config.tmpDataDiskName
193193
s.say(fmt.Sprintf(" -> dataDiskName : '%s'", dataDiskName))
194194

195-
for i := 0; i < additionalDiskCount; i++ {
195+
for i := range additionalDiskCount {
196196
subDataDiskName := fmt.Sprintf("%s-%d", dataDiskName, i+1)
197197

198198
err = s.captureVHD(ctx, subscriptionId, resourceGroupName, subDataDiskName)

builder/azure/arm/step_deploy_template_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,10 @@ func TestStepDeployTemplateCleanupShouldDeleteVirtualMachineAndNetworkResourcesI
229229
}
230230
if mockTrackers.actualNetworkResources == nil {
231231
t.Fatalf("Expected DeployTemplate to call delete network resources but it didn't")
232-
} else {
233-
expectedResources := map[string]string{"Microsoft.Network/publicIPAddresses": "ip", "Microsoft.Network/virtualNetworks": "vnet"}
234-
if diff := cmp.Diff(expectedResources, *mockTrackers.actualNetworkResources); diff != "" {
235-
t.Fatalf("Unexpected difference in expected parameter deleteNetworkResources.resources %s", diff)
236-
}
232+
}
233+
expectedResources := map[string]string{"Microsoft.Network/publicIPAddresses": "ip", "Microsoft.Network/virtualNetworks": "vnet"}
234+
if diff := cmp.Diff(expectedResources, *mockTrackers.actualNetworkResources); diff != "" {
235+
t.Fatalf("Unexpected difference in expected parameter deleteNetworkResources.resources %s", diff)
237236
}
238237
}
239238
func TestStepDeployTemplateCleanupShouldDeleteKeyVault(t *testing.T) {

0 commit comments

Comments
 (0)