@@ -7,17 +7,13 @@ This deploys the module as a Windows Function App using some of the interfaces.
77terraform {
88 required_version = "~> 1.6"
99 required_providers {
10- azapi = {
11- source = "Azure/azapi"
12- version = ">=1.9.0"
13- }
1410 azurerm = {
1511 source = "hashicorp/azurerm"
16- version = ">= 3.7.0, < 4.0.0 "
12+ version = "~> 3.108 "
1713 }
1814 random = {
1915 source = "hashicorp/random"
20- version = ">= 3.5.0, < 4.0.0 "
16+ version = "~> 3.6 "
2117 }
2218 }
2319}
@@ -88,13 +84,7 @@ resource "azurerm_log_analytics_workspace" "example" {
8884 sku = "PerGB2018"
8985}
9086
91- resource "azurerm_service_plan" "example" {
92- location = azurerm_resource_group.example.location
93- name = module.naming.app_service_plan.name_unique
94- os_type = "Windows"
95- resource_group_name = azurerm_resource_group.example.name
96- sku_name = "EP1"
97- }
87+
9888
9989resource "azurerm_virtual_network" "example" {
10090 address_space = ["192.168.0.0/24"]
@@ -128,6 +118,14 @@ resource "azurerm_user_assigned_identity" "user" {
128118 resource_group_name = azurerm_resource_group.example.name
129119}
130120
121+ resource "azurerm_service_plan" "example" {
122+ location = azurerm_resource_group.example.location
123+ name = module.naming.app_service_plan.name_unique
124+ os_type = "Windows"
125+ resource_group_name = azurerm_resource_group.example.name
126+ sku_name = "S1"
127+ }
128+
131129module "test" {
132130 source = "../../"
133131
@@ -164,30 +162,11 @@ module "test" {
164162 }
165163
166164 managed_identities = {
167- # Identities can only be used with the Standard SKU
168-
169- /*
170- system = {
171- identity_type = "SystemAssigned"
172- identity_ids = [ azurerm_user_assigned_identity.system.id ]
173- }
174- */
175-
176-
177- user = {
178- identity_type = "UserAssigned"
179- identity_ids = [azurerm_user_assigned_identity.user.id]
180- }
181-
182-
183- /*
184- system_and_user = {
185- identity_type = "SystemAssigned, UserAssigned"
186- identity_resource_ids = [
187- azurerm_user_assigned_identity.user.id
188- ]
189- }
190- */
165+ # Identities can only be used with the Standard SKU
166+ system_assigned = true
167+ user_assigned_resource_ids = [
168+ azurerm_user_assigned_identity.user.id
169+ ]
191170 }
192171
193172 # lock = {
@@ -270,56 +249,16 @@ check "dns" {
270249# VM to test private endpoint connectivity
271250
272251# This allows us to randomize the region for the resource group.
273- resource "random_integer" "region_index_vm" {
274- max = length(local.azure_regions) - 1
275- min = 0
276- }
252+ # resource "random_integer" "region_index_vm" {
253+ # max = length(local.azure_regions) - 1
254+ # min = 0
255+ # }
277256
278257resource "random_integer" "zone_index" {
279- max = length(module.regions.regions_by_name[local.azure_regions[random_integer.region_index_vm .result]].zones)
258+ max = length(module.regions.regions_by_name[local.azure_regions[random_integer.region_index .result]].zones)
280259 min = 1
281260}
282261
283- resource "random_integer" "deploy_sku" {
284- max = length(local.deploy_skus) - 1
285- min = 0
286- }
287-
288- ### this segment of code gets valid vm skus for deployment in the current subscription
289- data "azurerm_subscription" "current" {}
290-
291- #get the full sku list (azapi doesn't currently have a good way to filter the api call)
292- data "azapi_resource_list" "example" {
293- parent_id = data.azurerm_subscription.current.id
294- type = "Microsoft.Compute/skus@2021-07-01"
295- response_export_values = ["*"]
296- }
297-
298- locals {
299- #filter the region virtual machines by desired capabilities (v1/v2 support, 2 cpu, and encryption at host)
300- deploy_skus = [
301- for sku in local.location_valid_vms : sku
302- if length([
303- for capability in sku.capabilities : capability
304- if(capability.name == "HyperVGenerations" && capability.value == "V1,V2") ||
305- (capability.name == "vCPUs" && capability.value == "2") ||
306- (capability.name == "EncryptionAtHostSupported" && capability.value == "True") ||
307- (capability.name == "CpuArchitectureType" && capability.value == "x64")
308- ]) == 4
309- ]
310- #filter the location output for the current region, virtual machine resources, and filter out entries that don't include the capabilities list
311- location_valid_vms = [
312- for location in jsondecode(data.azapi_resource_list.example.output).value : location
313- if contains(location.locations, local.azure_regions[random_integer.region_index_vm.result]) && # if the sku location field matches the selected location
314- length(location.restrictions) < 1 && # and there are no restrictions on deploying the sku (i.e. allowed for deployment)
315- location.resourceType == "virtualMachines" && # and the sku is a virtual machine
316- !strcontains(location.name, "C") && # no confidential vm skus
317- !strcontains(location.name, "B") && # no B skus
318- length(try(location.capabilities, [])) > 1 # avoid skus where the capabilities list isn't defined
319- # try(location.capabilities, []) != [] # avoid skus where the capabilities list isn't defined
320- ]
321- }
322-
323262resource "azurerm_network_security_group" "example" {
324263 location = azurerm_resource_group.example.location
325264 name = module.naming.network_security_group.name_unique
@@ -340,19 +279,25 @@ resource "azurerm_network_security_rule" "example" {
340279 source_port_range = "*"
341280}
342281
343- #create the virtual machine
282+ module "avm_res_compute_virtualmachine_sku_selector" {
283+ source = "Azure/avm-res-compute-virtualmachine/azurerm//modules/sku_selector"
284+ version = "0.15.0"
285+
286+ deployment_region = azurerm_resource_group.example.location
287+ }
288+
289+ # Create the virtual machine
344290module "avm_res_compute_virtualmachine" {
345- # source = "../../"
346291 source = "Azure/avm-res-compute-virtualmachine/azurerm"
347- version = "0.4 .0"
292+ version = "0.15 .0"
348293
349- resource_group_name = azurerm_resource_group.example.name
350- location = azurerm_resource_group.example.location
351- name = "${module.naming.virtual_machine.name_unique}-tf"
352- virtualmachine_sku_size = local.deploy_skus[random_integer.deploy_sku.result].name
294+ resource_group_name = azurerm_resource_group.example.name
295+ location = azurerm_resource_group.example.location
296+ name = "${module.naming.virtual_machine.name_unique}-tf"
297+ sku_size = module.avm_res_compute_virtualmachine_sku_selector.sku
298+ os_type = "Windows"
353299
354- virtualmachine_os_type = "Windows"
355- zone = random_integer.zone_index.result
300+ zone = random_integer.zone_index.result
356301
357302 generate_admin_password_or_ssh_key = false
358303 admin_username = "TestAdmin"
@@ -394,21 +339,17 @@ The following requirements are needed by this module:
394339
395340- <a name =" requirement_terraform " ></a > [ terraform] ( #requirement\_ terraform ) (~ > 1.6)
396341
397- - <a name =" requirement_azapi " ></a > [ azapi] ( #requirement\_ azapi ) (>=1.9.0)
398-
399- - <a name =" requirement_azurerm " ></a > [ azurerm] ( #requirement\_ azurerm ) (>= 3.7.0, < 4.0.0)
342+ - <a name =" requirement_azurerm " ></a > [ azurerm] ( #requirement\_ azurerm ) (~ > 3.108)
400343
401- - <a name =" requirement_random " ></a > [ random] ( #requirement\_ random ) (>= 3.5.0, < 4.0.0 )
344+ - <a name =" requirement_random " ></a > [ random] ( #requirement\_ random ) (~ > 3.6 )
402345
403346## Providers
404347
405348The following providers are used by this module:
406349
407- - <a name =" provider_azapi " ></a > [ azapi ] ( #provider\_ azapi ) (>=1.9.0 )
350+ - <a name =" provider_azurerm " ></a > [ azurerm ] ( #provider\_ azurerm ) (~ > 3.108 )
408351
409- - <a name =" provider_azurerm " ></a > [ azurerm] ( #provider\_ azurerm ) (>= 3.7.0, < 4.0.0)
410-
411- - <a name =" provider_random " ></a > [ random] ( #provider\_ random ) (>= 3.5.0, < 4.0.0)
352+ - <a name =" provider_random " ></a > [ random] ( #provider\_ random ) (~ > 3.6)
412353
413354## Resources
414355
@@ -424,12 +365,8 @@ The following resources are used by this module:
424365- [ azurerm_subnet.example] ( https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet ) (resource)
425366- [ azurerm_user_assigned_identity.user] ( https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/user_assigned_identity ) (resource)
426367- [ azurerm_virtual_network.example] ( https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network ) (resource)
427- - [ random_integer.deploy_sku] ( https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer ) (resource)
428368- [ random_integer.region_index] ( https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer ) (resource)
429- - [ random_integer.region_index_vm] ( https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer ) (resource)
430369- [ random_integer.zone_index] ( https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer ) (resource)
431- - [ azapi_resource_list.example] ( https://registry.terraform.io/providers/Azure/azapi/latest/docs/data-sources/resource_list ) (data source)
432- - [ azurerm_subscription.current] ( https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/subscription ) (data source)
433370
434371<!-- markdownlint-disable MD013 -->
435372## Required Inputs
@@ -454,6 +391,10 @@ Default: `true`
454391
455392The following outputs are exported:
456393
394+ ### <a name =" output_identity_principal_id " ></a > [ identity\_ principal\_ id] ( #output\_ identity\_ principal\_ id )
395+
396+ Description: The principal ID for the identity.
397+
457398### <a name =" output_name " ></a > [ name] ( #output\_ name )
458399
459400Description: Name for the resource.
@@ -474,7 +415,13 @@ The following Modules are called:
474415
475416Source: Azure/avm-res-compute-virtualmachine/azurerm
476417
477- Version: 0.4.0
418+ Version: 0.15.0
419+
420+ ### <a name =" module_avm_res_compute_virtualmachine_sku_selector " ></a > [ avm\_ res\_ compute\_ virtualmachine\_ sku\_ selector] ( #module\_ avm\_ res\_ compute\_ virtualmachine\_ sku\_ selector )
421+
422+ Source: Azure/avm-res-compute-virtualmachine/azurerm//modules/sku_selector
423+
424+ Version: 0.15.0
478425
479426### <a name =" module_avm_res_storage_storageaccount " ></a > [ avm\_ res\_ storage\_ storageaccount] ( #module\_ avm\_ res\_ storage\_ storageaccount )
480427
0 commit comments