Skip to content

Commit d21dc8f

Browse files
authored
Merge branch 'hashicorp:main' into add-manual-mount-command-option
2 parents 9a2cd4c + 0d07e87 commit d21dc8f

File tree

6 files changed

+119
-17
lines changed

6 files changed

+119
-17
lines changed

.web-docs/components/builder/arm/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,9 @@ Providing `temp_resource_group_name` or `location` in combination with
523523
- `custom_resource_build_prefix` (string) - specify custom azure resource names during build limited to max 10 characters
524524
this will set the prefix for the resources. The actual resource names will be
525525
`custom_resource_build_prefix` + resourcetype + 5 character random alphanumeric string
526+
527+
You can also set this via the environment variable `PACKER_AZURE_CUSTOM_RESOURCE_BUILD_PREFIX`.
528+
If both the config field and the environment variable are present, the config field takes precedence.
526529

527530
- `license_type` (string) - Specify a license type for the build VM to enable Azure Hybrid Benefit. If not set, Pay-As-You-Go license
528531
model (default) will be used. Valid values are:

builder/azure/arm/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,9 @@ type Config struct {
614614
// specify custom azure resource names during build limited to max 10 characters
615615
// this will set the prefix for the resources. The actual resource names will be
616616
// `custom_resource_build_prefix` + resourcetype + 5 character random alphanumeric string
617+
//
618+
// You can also set this via the environment variable `PACKER_AZURE_CUSTOM_RESOURCE_BUILD_PREFIX`.
619+
// If both the config field and the environment variable are present, the config field takes precedence.
617620
CustomResourcePrefix string `mapstructure:"custom_resource_build_prefix" required:"false"`
618621

619622
// Specify a license type for the build VM to enable Azure Hybrid Benefit. If not set, Pay-As-You-Go license
@@ -1431,6 +1434,12 @@ func assertRequiredParametersSet(c *Config, errs *packersdk.MultiError) {
14311434
}
14321435
}
14331436

1437+
if c.CustomResourcePrefix == "" {
1438+
val, ok := os.LookupEnv("PACKER_AZURE_CUSTOM_RESOURCE_BUILD_PREFIX")
1439+
if ok {
1440+
c.CustomResourcePrefix = val
1441+
}
1442+
}
14341443
if c.CustomResourcePrefix != "" {
14351444
if ok, err := assertResourceNamePrefix(c.CustomResourcePrefix, "custom_resource_build_prefix"); !ok {
14361445
errs = packersdk.MultiErrorAppend(errs, err)

builder/azure/arm/config_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,6 +2772,56 @@ func TestConfigShouldAcceptValidCustomResourceBuildPrefix(t *testing.T) {
27722772
}
27732773
}
27742774

2775+
func TestEnvVarSetsCustomResourceBuildPrefix_Invalid(t *testing.T) {
2776+
// Invalid env var should cause validation to fail when field not explicitly set
2777+
t.Setenv("PACKER_AZURE_CUSTOM_RESOURCE_BUILD_PREFIX", "pkr_123456")
2778+
2779+
config := map[string]interface{}{
2780+
"location": "ignore",
2781+
"subscription_id": "ignore",
2782+
"image_offer": "ignore",
2783+
"image_publisher": "ignore",
2784+
"image_sku": "ignore",
2785+
"os_type": "linux",
2786+
"resource_group_name": "ignore",
2787+
"storage_account": "ignore",
2788+
"capture_container_name": "ignore",
2789+
"capture_name_prefix": "ignore",
2790+
}
2791+
2792+
var c Config
2793+
if _, err := c.Prepare(config, getPackerConfiguration()); err == nil {
2794+
t.Fatal("expected config to reject invalid env var value for custom_resource_build_prefix")
2795+
}
2796+
}
2797+
2798+
func TestConfigCustomResourceBuildPrefixTakesPrecedenceOverEnv(t *testing.T) {
2799+
// When both are present, the config value should win
2800+
t.Setenv("PACKER_AZURE_CUSTOM_RESOURCE_BUILD_PREFIX", "pkr-env99")
2801+
2802+
config := map[string]interface{}{
2803+
"location": "ignore",
2804+
"subscription_id": "ignore",
2805+
"image_offer": "ignore",
2806+
"image_publisher": "ignore",
2807+
"image_sku": "ignore",
2808+
"os_type": "linux",
2809+
"resource_group_name": "ignore",
2810+
"storage_account": "ignore",
2811+
"capture_container_name": "ignore",
2812+
"capture_name_prefix": "ignore",
2813+
"custom_resource_build_prefix": "pkr-12345-",
2814+
}
2815+
2816+
var c Config
2817+
if _, err := c.Prepare(config, getPackerConfiguration()); err != nil {
2818+
t.Fatalf("expected config to succeed when both env and config set, got error: %s", err)
2819+
}
2820+
if c.CustomResourcePrefix != "pkr-12345-" {
2821+
t.Fatalf("expected CustomResourcePrefix to be set from config (precedence), got %q", c.CustomResourcePrefix)
2822+
}
2823+
}
2824+
27752825
func TestConfigShouldNormalizeLicenseTypeCase(t *testing.T) {
27762826
config := map[string]string{
27772827
"capture_name_prefix": "ignore",

docs-partials/builder/azure/arm/Config-not-required.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,9 @@
385385
- `custom_resource_build_prefix` (string) - specify custom azure resource names during build limited to max 10 characters
386386
this will set the prefix for the resources. The actual resource names will be
387387
`custom_resource_build_prefix` + resourcetype + 5 character random alphanumeric string
388+
389+
You can also set this via the environment variable `PACKER_AZURE_CUSTOM_RESOURCE_BUILD_PREFIX`.
390+
If both the config field and the environment variable are present, the config field takes precedence.
388391

389392
- `license_type` (string) - Specify a license type for the build VM to enable Azure Hybrid Benefit. If not set, Pay-As-You-Go license
390393
model (default) will be used. Valid values are:

go.mod

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ require (
99
github.com/google/go-cmp v0.6.0
1010
github.com/hashicorp/go-azure-helpers v0.67.0
1111
github.com/hashicorp/hcl/v2 v2.19.1
12-
github.com/hashicorp/packer-plugin-sdk v0.6.2
13-
github.com/masterzen/winrm v0.0.0-20210623064412-3b76017826b0
12+
github.com/hashicorp/packer-plugin-sdk v0.6.4
13+
github.com/masterzen/winrm v0.0.0-20250927112105-5f8e6c707321
1414
github.com/mitchellh/mapstructure v1.5.0
1515
github.com/mitchellh/reflectwalk v1.0.2
1616
github.com/stretchr/testify v1.10.0
@@ -38,7 +38,7 @@ require (
3838
cloud.google.com/go/storage v1.35.1 // indirect
3939
github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.1 // indirect
4040
github.com/Azure/azure-sdk-for-go/sdk/keyvault/internal v0.7.1 // indirect
41-
github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c // indirect
41+
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 // indirect
4242
github.com/AzureAD/microsoft-authentication-library-for-go v1.4.2 // indirect
4343
github.com/ChrisTrenkamp/goxpath v0.0.0-20210404020558-97928f7e12b6 // indirect
4444
github.com/Microsoft/go-winio v0.6.2 // indirect
@@ -49,13 +49,16 @@ require (
4949
github.com/armon/go-metrics v0.4.1 // indirect
5050
github.com/aws/aws-sdk-go v1.45.6 // indirect
5151
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
52+
github.com/bodgit/ntlmssp v0.0.0-20240506230425-31973bb52d9b // indirect
53+
github.com/bodgit/windows v1.0.1 // indirect
5254
github.com/cenkalti/backoff/v3 v3.2.2 // indirect
5355
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
5456
github.com/dylanmei/iso8601 v0.1.0 // indirect
5557
github.com/fatih/color v1.16.0 // indirect
5658
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
59+
github.com/go-logr/logr v1.4.1 // indirect
5760
github.com/gofrs/flock v0.8.1 // indirect
58-
github.com/gofrs/uuid v4.0.0+incompatible // indirect
61+
github.com/gofrs/uuid v4.4.0+incompatible // indirect
5962
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
6063
github.com/golang/protobuf v1.5.3 // indirect
6164
github.com/google/s2a-go v0.1.7 // indirect
@@ -89,6 +92,12 @@ require (
8992
github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1 // indirect
9093
github.com/hashicorp/vault/api v1.14.0 // indirect
9194
github.com/hashicorp/yamux v0.1.1 // indirect
95+
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
96+
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
97+
github.com/jcmturner/gofork v1.7.6 // indirect
98+
github.com/jcmturner/goidentity/v6 v6.0.1 // indirect
99+
github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect
100+
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
92101
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect
93102
github.com/jmespath/go-jmespath v0.4.0 // indirect
94103
github.com/klauspost/compress v1.11.2 // indirect
@@ -108,6 +117,7 @@ require (
108117
github.com/pkg/sftp v1.13.2 // indirect
109118
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
110119
github.com/ryanuber/go-glob v1.0.0 // indirect
120+
github.com/tidwall/transform v0.0.0-20201103190739-32f242e2dbde // indirect
111121
github.com/ugorji/go/codec v1.2.6 // indirect
112122
github.com/ulikunitz/xz v0.5.15 // indirect
113123
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect

0 commit comments

Comments
 (0)