Skip to content

Commit 2eee005

Browse files
Variabilize several elements in Packer templates (#12231)
1 parent ff069dc commit 2eee005

File tree

5 files changed

+80
-50
lines changed

5 files changed

+80
-50
lines changed

images/ubuntu/templates/ubuntu-22.04.pkr.hcl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
locals {
2-
managed_image_name = var.managed_image_name != "" ? var.managed_image_name : "packer-${var.image_os}-${var.image_version}"
3-
}
4-
51
variable "allowed_inbound_ip_addresses" {
62
type = list(string)
73
default = []
@@ -14,7 +10,7 @@ variable "azure_tags" {
1410

1511
variable "build_resource_group_name" {
1612
type = string
17-
default = "${env("BUILD_RESOURCE_GROUP_NAME")}"
13+
default = "${env("BUILD_RG_NAME")}"
1814
}
1915

2016
variable "client_cert_path" {
@@ -81,7 +77,7 @@ variable "install_password" {
8177

8278
variable "location" {
8379
type = string
84-
default = "${env("ARM_RESOURCE_LOCATION")}"
80+
default = ""
8581
}
8682

8783
variable "managed_image_name" {
@@ -156,7 +152,7 @@ variable "gallery_name" {
156152

157153
variable "gallery_resource_group_name" {
158154
type = string
159-
default = "${env("GALLERY_RESOURCE_GROUP_NAME")}"
155+
default = "${env("GALLERY_RG_NAME")}"
160156
}
161157

162158
variable "gallery_image_name" {
@@ -179,6 +175,16 @@ variable "use_azure_cli_auth" {
179175
default = false
180176
}
181177

178+
variable "os_disk_size_gb" {
179+
type = number
180+
default = 75
181+
}
182+
183+
variable "image_os_type" {
184+
type = string
185+
default = "Linux"
186+
}
187+
182188
source "azure-arm" "build_image" {
183189
allowed_inbound_ip_addresses = "${var.allowed_inbound_ip_addresses}"
184190
build_resource_group_name = "${var.build_resource_group_name}"
@@ -190,10 +196,10 @@ source "azure-arm" "build_image" {
190196
image_publisher = "${var.image_publisher}"
191197
image_sku = "${var.image_sku}"
192198
location = "${var.location}"
193-
managed_image_name = "${local.managed_image_name}"
199+
managed_image_name = "${var.managed_image_name}"
194200
managed_image_resource_group_name = "${var.managed_image_resource_group_name}"
195-
os_disk_size_gb = "75"
196-
os_type = "Linux"
201+
os_disk_size_gb = var.os_disk_size_gb
202+
os_type = var.image_os_type
197203
private_virtual_network_with_public_ip = "${var.private_virtual_network_with_public_ip}"
198204
subscription_id = "${var.subscription_id}"
199205
temp_resource_group_name = "${var.temp_resource_group_name}"

images/ubuntu/templates/ubuntu-24.04.pkr.hcl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
locals {
2-
managed_image_name = var.managed_image_name != "" ? var.managed_image_name : "packer-${var.image_os}-${var.image_version}"
3-
}
4-
51
variable "allowed_inbound_ip_addresses" {
62
type = list(string)
73
default = []
@@ -14,7 +10,7 @@ variable "azure_tags" {
1410

1511
variable "build_resource_group_name" {
1612
type = string
17-
default = "${env("BUILD_RESOURCE_GROUP_NAME")}"
13+
default = "${env("BUILD_RG_NAME")}"
1814
}
1915

2016
variable "client_cert_path" {
@@ -81,7 +77,7 @@ variable "install_password" {
8177

8278
variable "location" {
8379
type = string
84-
default = "${env("ARM_RESOURCE_LOCATION")}"
80+
default = ""
8581
}
8682

8783
variable "managed_image_name" {
@@ -156,7 +152,7 @@ variable "gallery_name" {
156152

157153
variable "gallery_resource_group_name" {
158154
type = string
159-
default = "${env("GALLERY_RESOURCE_GROUP_NAME")}"
155+
default = "${env("GALLERY_RG_NAME")}"
160156
}
161157

162158
variable "gallery_image_name" {
@@ -179,6 +175,16 @@ variable "use_azure_cli_auth" {
179175
default = false
180176
}
181177

178+
variable "os_disk_size_gb" {
179+
type = number
180+
default = 75
181+
}
182+
183+
variable "image_os_type" {
184+
type = string
185+
default = "Linux"
186+
}
187+
182188
source "azure-arm" "build_image" {
183189
allowed_inbound_ip_addresses = "${var.allowed_inbound_ip_addresses}"
184190
build_resource_group_name = "${var.build_resource_group_name}"
@@ -190,10 +196,10 @@ source "azure-arm" "build_image" {
190196
image_publisher = "${var.image_publisher}"
191197
image_sku = "${var.image_sku}"
192198
location = "${var.location}"
193-
managed_image_name = "${local.managed_image_name}"
199+
managed_image_name = "${var.managed_image_name}"
194200
managed_image_resource_group_name = "${var.managed_image_resource_group_name}"
195-
os_disk_size_gb = "75"
196-
os_type = "Linux"
201+
os_disk_size_gb = var.os_disk_size_gb
202+
os_type = var.image_os_type
197203
private_virtual_network_with_public_ip = "${var.private_virtual_network_with_public_ip}"
198204
subscription_id = "${var.subscription_id}"
199205
temp_resource_group_name = "${var.temp_resource_group_name}"

images/windows/templates/windows-2019.pkr.hcl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
locals {
2-
managed_image_name = var.managed_image_name != "" ? var.managed_image_name : "packer-${var.image_os}-${var.image_version}"
3-
}
4-
51
variable "agent_tools_directory" {
62
type = string
73
default = "C:\\hostedtoolcache\\windows"
@@ -19,7 +15,7 @@ variable "azure_tags" {
1915

2016
variable "build_resource_group_name" {
2117
type = string
22-
default = "${env("BUILD_RESOURCE_GROUP_NAME")}"
18+
default = "${env("BUILD_RG_NAME")}"
2319
}
2420

2521
variable "client_cert_path" {
@@ -81,7 +77,7 @@ variable "install_user" {
8177

8278
variable "location" {
8379
type = string
84-
default = "${env("ARM_RESOURCE_LOCATION")}"
80+
default = ""
8581
}
8682

8783
variable "managed_image_name" {
@@ -166,7 +162,7 @@ variable "gallery_name" {
166162

167163
variable "gallery_resource_group_name" {
168164
type = string
169-
default = "${env("GALLERY_RESOURCE_GROUP_NAME")}"
165+
default = "${env("GALLERY_RG_NAME")}"
170166
}
171167

172168
variable "gallery_image_name" {
@@ -199,6 +195,16 @@ variable "use_azure_cli_auth" {
199195
default = false
200196
}
201197

198+
variable "os_disk_size_gb" {
199+
type = number
200+
default = 256
201+
}
202+
203+
variable "image_os_type" {
204+
type = string
205+
default = "Windows"
206+
}
207+
202208
source "azure-arm" "image" {
203209
allowed_inbound_ip_addresses = "${var.allowed_inbound_ip_addresses}"
204210
build_resource_group_name = "${var.build_resource_group_name}"
@@ -211,12 +217,12 @@ source "azure-arm" "image" {
211217
image_publisher = "${var.image_publisher}"
212218
image_sku = "${var.image_sku}"
213219
location = "${var.location}"
214-
managed_image_name = "${local.managed_image_name}"
220+
managed_image_name = "${var.managed_image_name}"
215221
managed_image_resource_group_name = "${var.managed_image_resource_group_name}"
216222
managed_image_storage_account_type = "${var.managed_image_storage_account_type}"
217223
object_id = "${var.object_id}"
218-
os_disk_size_gb = "256"
219-
os_type = "Windows"
224+
os_disk_size_gb = var.os_disk_size_gb
225+
os_type = var.image_os_type
220226
private_virtual_network_with_public_ip = "${var.private_virtual_network_with_public_ip}"
221227
subscription_id = "${var.subscription_id}"
222228
temp_resource_group_name = "${var.temp_resource_group_name}"

images/windows/templates/windows-2022.pkr.hcl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
locals {
2-
managed_image_name = var.managed_image_name != "" ? var.managed_image_name : "packer-${var.image_os}-${var.image_version}"
3-
}
4-
51
variable "agent_tools_directory" {
62
type = string
73
default = "C:\\hostedtoolcache\\windows"
@@ -19,7 +15,7 @@ variable "azure_tags" {
1915

2016
variable "build_resource_group_name" {
2117
type = string
22-
default = "${env("BUILD_RESOURCE_GROUP_NAME")}"
18+
default = "${env("BUILD_RG_NAME")}"
2319
}
2420

2521
variable "client_cert_path" {
@@ -81,7 +77,7 @@ variable "install_user" {
8177

8278
variable "location" {
8379
type = string
84-
default = "${env("ARM_RESOURCE_LOCATION")}"
80+
default = ""
8581
}
8682

8783
variable "managed_image_name" {
@@ -166,7 +162,7 @@ variable "gallery_name" {
166162

167163
variable "gallery_resource_group_name" {
168164
type = string
169-
default = "${env("GALLERY_RESOURCE_GROUP_NAME")}"
165+
default = "${env("GALLERY_RG_NAME")}"
170166
}
171167

172168
variable "gallery_image_name" {
@@ -199,6 +195,16 @@ variable "use_azure_cli_auth" {
199195
default = false
200196
}
201197

198+
variable "os_disk_size_gb" {
199+
type = number
200+
default = 256
201+
}
202+
203+
variable "image_os_type" {
204+
type = string
205+
default = "Windows"
206+
}
207+
202208
source "azure-arm" "image" {
203209
allowed_inbound_ip_addresses = "${var.allowed_inbound_ip_addresses}"
204210
build_resource_group_name = "${var.build_resource_group_name}"
@@ -211,12 +217,12 @@ source "azure-arm" "image" {
211217
image_publisher = "${var.image_publisher}"
212218
image_sku = "${var.image_sku}"
213219
location = "${var.location}"
214-
managed_image_name = "${local.managed_image_name}"
220+
managed_image_name = "${var.managed_image_name}"
215221
managed_image_resource_group_name = "${var.managed_image_resource_group_name}"
216222
managed_image_storage_account_type = "${var.managed_image_storage_account_type}"
217223
object_id = "${var.object_id}"
218-
os_disk_size_gb = "256"
219-
os_type = "Windows"
224+
os_disk_size_gb = var.os_disk_size_gb
225+
os_type = var.image_os_type
220226
private_virtual_network_with_public_ip = "${var.private_virtual_network_with_public_ip}"
221227
subscription_id = "${var.subscription_id}"
222228
temp_resource_group_name = "${var.temp_resource_group_name}"

images/windows/templates/windows-2025.pkr.hcl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
locals {
2-
managed_image_name = var.managed_image_name != "" ? var.managed_image_name : "packer-${var.image_os}-${var.image_version}"
3-
}
4-
51
variable "agent_tools_directory" {
62
type = string
73
default = "C:\\hostedtoolcache\\windows"
@@ -19,7 +15,7 @@ variable "azure_tags" {
1915

2016
variable "build_resource_group_name" {
2117
type = string
22-
default = "${env("BUILD_RESOURCE_GROUP_NAME")}"
18+
default = "${env("BUILD_RG_NAME")}"
2319
}
2420

2521
variable "client_cert_path" {
@@ -81,7 +77,7 @@ variable "install_user" {
8177

8278
variable "location" {
8379
type = string
84-
default = "${env("ARM_RESOURCE_LOCATION")}"
80+
default = ""
8581
}
8682

8783
variable "managed_image_name" {
@@ -166,7 +162,7 @@ variable "gallery_name" {
166162

167163
variable "gallery_resource_group_name" {
168164
type = string
169-
default = "${env("GALLERY_RESOURCE_GROUP_NAME")}"
165+
default = "${env("GALLERY_RG_NAME")}"
170166
}
171167

172168
variable "gallery_image_name" {
@@ -199,6 +195,16 @@ variable "use_azure_cli_auth" {
199195
default = false
200196
}
201197

198+
variable "os_disk_size_gb" {
199+
type = number
200+
default = 150
201+
}
202+
203+
variable "image_os_type" {
204+
type = string
205+
default = "Windows"
206+
}
207+
202208
source "azure-arm" "image" {
203209
allowed_inbound_ip_addresses = "${var.allowed_inbound_ip_addresses}"
204210
build_resource_group_name = "${var.build_resource_group_name}"
@@ -211,12 +217,12 @@ source "azure-arm" "image" {
211217
image_publisher = "${var.image_publisher}"
212218
image_sku = "${var.image_sku}"
213219
location = "${var.location}"
214-
managed_image_name = "${local.managed_image_name}"
220+
managed_image_name = "${var.managed_image_name}"
215221
managed_image_resource_group_name = "${var.managed_image_resource_group_name}"
216222
managed_image_storage_account_type = "${var.managed_image_storage_account_type}"
217223
object_id = "${var.object_id}"
218-
os_disk_size_gb = "150"
219-
os_type = "Windows"
224+
os_disk_size_gb = var.os_disk_size_gb
225+
os_type = var.image_os_type
220226
private_virtual_network_with_public_ip = "${var.private_virtual_network_with_public_ip}"
221227
subscription_id = "${var.subscription_id}"
222228
temp_resource_group_name = "${var.temp_resource_group_name}"

0 commit comments

Comments
 (0)