-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathvariables.tf
More file actions
1693 lines (1524 loc) · 105 KB
/
variables.tf
File metadata and controls
1693 lines (1524 loc) · 105 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# The `run_commands` variable defines the configuration for Virtual Machine Run Commands in Azure.
#
# The following arguments are supported:
########## optional variables
########## Required variables
variable "location" {
type = string
description = "The Azure region where this and supporting resources should be deployed."
nullable = false
}
variable "name" {
type = string
description = "The name to use when creating the virtual machine."
nullable = false
validation {
condition = can(regex("^.{1,64}$", var.name))
error_message = "virtual machine names for linux must be between 1 and 64 characters in length. Virtual machine name for windows must be between 1 and 20 characters in length."
}
}
variable "resource_group_name" {
type = string
description = "The resource group name of the resource group where the vm resources will be deployed."
nullable = false
}
variable "zone" {
type = string
description = "The Availability Zone which the Virtual Machine should be allocated in, only one zone would be accepted. If set then this module won't create `azurerm_availability_set` resource. Changing this forces a new resource to be created. This has been moved to a required value to comply with WAF guidance to intentionally select zones for resources as part of resource architectures. If deploying to a region without zones, set this value to null."
}
########## optional variables
variable "account_credentials" {
type = object({
admin_credentials = optional(object({
username = optional(string, "azureuser")
password = optional(string, null)
ssh_keys = optional(list(string), [])
generate_admin_password_or_ssh_key = optional(bool, true) # Use of flag is required to avoid known after apply issues
}), {})
key_vault_configuration = optional(object({
resource_id = string
secret_configuration = optional(object({
name = optional(string, null)
expiration_date_length_in_days = optional(number, 45)
content_type = optional(string, "text/plain")
not_before_date = optional(string, null)
tags = optional(map(string), {})
}), {})
}), null)
password_authentication_disabled = optional(bool, true)
#future addditional user credentials map?
})
default = {}
description = <<ACCOUNT_CREDENTIALS
This is the primary object for defining admin credentials for the VM. It supports both windows and linux configurations with the following logic:
- For Both Windows and Linux:
- If a username is provided, it will be used as the admin username, otherwise azureadmin will be the default.
- If password or ssh public keys are not provided and the `var.account_credentials.admin_credentials.generate_admin_password_or_ssh_key` flag is true (default), a password or ssh private key will be generated and can be accessed via outputs.
- If a key vault configuration is set, the provided or generated credential objects will be stored in the key vault using the provided details.
- For Windows:
- Password authentication is always enabled.
- For Linux:
- Password authentication is disabled by default. If you want to use password authentication, set password_authentication_disabled to false.
- If password authentication is disabled, ssh public keys are required. If not provided, a new private key will be generated and can be accessed via outputs when the `var.account_credentials.admin_credentials.generate_admin_password_or_ssh_key` flag is true (default).
- If password authentication is enabled, any provided ssh public keys will cause a validation error. This is a limitation of the azurerm_linux_virtual_machine resource which requires either password or ssh key authentication, not both.
Schema:
- admin_credentials
- `username`: string (optional, default: azureuser) = (optional) The username for the admin account. If not provided, `azureuser` will be used for the default administrative account.
- `password`: string (optional, default: null) = (optional) The password for the admin account. If not provided, a password will be generated. Only valid for Linux when password_authentication_disabled = false.
- `ssh_keys`: list(string) (optional, default: []) = (optional) The SSH public keys for the admin account. If not provided, a new private key will be generated. Only valid when password_authentication_disabled = true and only valid for Linux virtual machines.
- `generate_admin_password_or_ssh_key`: bool (optional, default: true) = (optional) A flag to indicate whether to generate a password or SSH key for the admin account. If set to true, a password or SSH key will be auto-generated. If set to false, the provided password or SSH keys will be used.
- `key_vault_configuration` = Object (optional, default: null) = (optional) The configuration for storing credentials in an Azure Key Vault. If not provided, credentials will not be stored in Key Vault as part of this module.
- `resource_id`: string (required) = (required) The resource ID of the Key Vault where the credentials will be stored.
- `secret_configuration` = Object (optional, default: null) = (optional) The secret configuration that is used when storing credentials in the Key Vault.
- `name`: string (optional, default: null) = (optional) The name of the secret in the Key Vault. If not provided, a name will be generated using the pattern <vm name>-<admin username>-<password | ssh-private-key>.
- `expiration_date_length_in_days`: number (optional, default: 45) = (optional) The number of days until the secret expires. If not provided, the default is 45 days.
- `content_type`: string (optional, default: text/plain) = (optional) The content type of the secret. If not provided, the default is `text/plain`.
- `not_before_date`: string (optional, default: null) = (optional) The date before which the secret is not valid. If not provided, the default is null.
- `tags`: map(string) (optional, default: {}) = (optional) The tags to apply to the secret in the Key Vault. If not provided, the default is an empty map.
- `password_authentication_disabled`: bool (optional, default: true) = (optional) A flag to indicate whether password authentication is disabled. This is only valid for Linux virtual machines. If set to true, password authentication will be disabled and SSH key authentication will be used. If set to false, password authentication will be enabled and SSH key authentication will be ignored.
Input Examples:
#no configuration = default username, generated password, password available via output
# Linux, password auth allowed, generated password stored in vault using a custom secret name
account_credentials = {
key_vault_configuration = {
resource_id = module.avm_res_keyvault_vault.resource_id
secret_configuration = {
name = "vault-pub-key-test"
}
}
password_authentication_disabled = false
}
# Windows custom username and password, no vaulting
account_credentials = {
admin_credentials = {
username = "testuser"
password = "testValue123!"
}
}
ACCOUNT_CREDENTIALS
nullable = false
validation {
condition = !(
lower(var.os_type) == "linux" &&
var.account_credentials.admin_credentials.password != null &&
var.account_credentials.password_authentication_disabled == true)
error_message = "var.account_credentials.admin_credentials.password values will be ignored when var.admin_credentials.password_authentication_disabled == true. Please set var.admin_credentials.password_authentication_disabled to false if you want to use password authentication for linux systems."
}
validation {
condition = !(
length(var.account_credentials.admin_credentials.ssh_keys) != 0 &&
var.account_credentials.admin_credentials.password != null
)
error_message = "Only one of password or ssh_keys should be set due to limitations imposed by the use of azurerm_linux_virtual_machine resource. Please set either password or ssh_keys, not both."
}
validation {
condition = !can(regex("^(administrator|admin|user|user1|test|user2|test2|user3|admin1|1|123|a|actuser|adm|admin2|aspnet|backup|console|david|guest|john|owner|root|server|sql|support|support_388945a0|sys|test2|test3|user4|user5)$", lower(var.account_credentials.admin_credentials.username)))
error_message = "Admin username may not contain any of the following reserved values. ( administrator, admin, user, user1, test, user2, test1, user3, admin1, 1, 123, a, actuser, adm, admin2, aspnet, backup, console, david, guest, john, owner, root, server, sql, support, support_388945a0, sys, test2, test3, user4, user5 )"
}
validation {
condition = can(regex("^.{1,64}$", var.account_credentials.admin_credentials.username))
error_message = "Admin username for linux must be between 1 and 64 characters in length. Admin name for windows must be between 1 and 20 characters in length."
}
validation {
condition = !(
var.account_credentials.password_authentication_disabled == false &&
lower(var.os_type) == "windows")
error_message = "Use of password_authentication_disabled == false is limited to Linux operating systems. Please set to true when using os_type of Windows."
}
validation {
condition = !(
var.account_credentials.admin_credentials.password == null &&
length(var.account_credentials.admin_credentials.ssh_keys) == 0 &&
var.account_credentials.admin_credentials.generate_admin_password_or_ssh_key == false)
error_message = "Either password or ssh_keys must be provided if generate_admin_password_or_ssh_key is false. Please set the generate_admin_password_or_ssh_key flag to true or provide a password or ssh_key input."
}
validation {
condition = !(
var.account_credentials.admin_credentials.password != null &&
var.account_credentials.admin_credentials.generate_admin_password_or_ssh_key == true)
error_message = "The generate_admin_password_or_ssh_key is set to true, but a password value has also been set. If use of a custom password is desired, then set the generate_admin_password_or_ssh_key to false. Otherwise, please remove the custom password value."
}
validation {
condition = !(
length(var.account_credentials.admin_credentials.ssh_keys) > 0 &&
var.account_credentials.admin_credentials.generate_admin_password_or_ssh_key == true)
error_message = "The generate_admin_password_or_ssh_key is set to true, but a ssh_keys value has also been set. If use of custom ssh_keys is desired, then set the generate_admin_password_or_ssh_key to false. Otherwise, please remove the custom ssh_keys values."
}
validation {
condition = !(
length(var.account_credentials.admin_credentials.ssh_keys) > 0 &&
var.account_credentials.password_authentication_disabled == false)
error_message = "The password_authentication_disabled flag is set to false, but a ssh_keys value has also been set. If use of custom ssh_keys is desired, then set the password_authentication_disabled to true. Otherwise, please remove the custom ssh_keys values."
}
validation {
condition = !(
var.account_credentials.key_vault_configuration != null &&
length(var.account_credentials.admin_credentials.ssh_keys) > 0
)
error_message = "When adding ssh public keys using the ssh_keys input, the key vault configuration has no effect. The ssh public keys will be added to the VM and not stored in the key vault. Please remove the key vault configuration if you want to use ssh public keys."
}
}
variable "additional_unattend_contents" {
type = list(object({
content = string
setting = string
}))
default = []
description = <<ADDITIONAL_UNATTEND_CONTENTS
List of objects representing unattend content settings
- `content` (Required) - The XML formatted content that is added to the unattend.xml file for the specified path and component. Changing this forces a new resource to be created.
- `setting` (Required) - The name of the setting to which the content applies. Possible values are `AutoLogon` and `FirstLogonCommands`. Changing this forces a new resource to be created.
Example Inputs:
```hcl
#Example Reboot
additional_unattend_contents = [
{
content = "<FirstLogonCommands><SynchronousCommand><CommandLine>shutdown /r /t 0 /c \"initial reboot\"</CommandLine><Description>reboot</Description><Order>1</Order></SynchronousCommand></FirstLogonCommands>"
setting = "FirstLogonCommands"
}
]
```
ADDITIONAL_UNATTEND_CONTENTS
nullable = false
}
variable "allow_extension_operations" {
type = bool
default = true
description = "(Optional) Should Extension Operations be allowed on this Virtual Machine? Defaults to `true`."
}
variable "availability_set_resource_id" {
type = string
default = null
description = "(Optional) Specifies the Azure Resource ID of the Availability Set in which the Virtual Machine should exist. Cannot be used along with `new_availability_set`, `new_capacity_reservation_group`, `capacity_reservation_group_id`, `virtual_machine_scale_set_id`, `zone`. Changing this forces a new resource to be created."
}
variable "azure_backup_configurations" {
type = map(object({
resource_group_name = optional(string, null)
recovery_vault_name = optional(string, null)
recovery_vault_resource_id = string
backup_policy_resource_id = optional(string, null)
exclude_disk_luns = optional(list(number), null)
include_disk_luns = optional(list(number), null)
}))
default = {}
description = <<DESCRIPTION
This object describes the backup configuration to use for this VM instance. Provide the backup details for configuring the backup. It defaults to null.
- `<map_key>` - An arbitrary map key to avoid terraform issues with know before apply challenges
- `recovery_vault_resource_id - (Required) - The Azure Resource ID of the recovery services vault where the backup will be stored.
- `resource_group_name` - (Optional) - This value is deprecated and will be removed in future versions as the VM resource group name will be used.
- `recovery_vault_name` - (Optional) - This value is deprecated and will be removed in future versions as the RSV information will be pulled from the RSV resource id. The name of the recovery services vault where the backup will be stored.
- `backup_policy_resource_id` - (Optional) - Required during creation, but can be optional when the protection state is not `ProtectionStopped`.
- `exclude_disk_luns` - (Optional) - A list of Disk Logical Unit Numbers (LUN) to be excluded from VM Protection. Only one of `exclude_disk_luns` or `include_disk_luns` can be set. If both are set then only the `exclude_disk_luns` value will be used.
- `include_disk_luns` - (Optional) - A list of Disk Logical Unit Numbers (LUN) to be included for VM Protection. Only one of `exclude_disk_luns` or `include_disk_luns` can be set. If both are set then only the `exclude_disk_luns` value will be used.
Example Input:
azure_backup_configurations = {
arbitrary_key = {
recovery_vault_resource_id = azurerm_recovery_services_vault.test_vault.id
backup_policy_resource_id = azurerm_backup_policy_vm.test_policy.id
exclude_disk_luns = [0,1]
}
}
DESCRIPTION
}
variable "boot_diagnostics" {
type = bool
default = false
description = "(Optional) Enable or Disable boot diagnostics."
nullable = false
}
variable "boot_diagnostics_storage_account_uri" {
type = string
default = null
description = "(Optional) The Primary/Secondary Endpoint for the Azure Storage Account which should be used to store Boot Diagnostics, including Console Output and Screenshots from the Hypervisor. Passing a null value will Utilize a managed storage account for diags."
}
variable "bypass_platform_safety_checks_on_user_schedule_enabled" {
type = bool
default = false
description = "(Optional) Specifies whether to skip platform scheduled patching when a user schedule is associated with the VM. This value can only be set to true when patch_mode is set to AutomaticByPlatform"
}
variable "capacity_reservation_group_resource_id" {
type = string
default = null
description = "(Optional) Specifies the Azure Resource ID of the Capacity Reservation Group with the Virtual Machine should be allocated to. Cannot be used with availability_set_id or proximity_placement_group_id"
}
variable "computer_name" {
type = string
default = null
description = "(Optional) Specifies the Hostname which should be used for this Virtual Machine. If unspecified this defaults to the value for the `vm_name` field. If the value of the `vm_name` field is not a valid `computer_name`, then you must specify `computer_name`. Changing this forces a new resource to be created."
}
variable "custom_data" {
type = string
default = null
description = "(Optional) The Base64 encoded Custom Data for building this virtual machine. Changing this forces a new resource to be created"
validation {
# Gzipped payloads (e.g. from cloudinit_config with gzip=true) are valid
# base64 but base64decode() rejects them because the decoded bytes are not
# valid UTF-8. Gzip streams always start with magic bytes 0x1f 0x8b 0x08,
# which base64-encode to the prefix "H4sI". We check for that prefix as a
# fallback to accept gzipped cloud-init data.
condition = var.custom_data == null ? true : (
can(base64decode(var.custom_data)) ||
startswith(var.custom_data, "H4sI")
)
error_message = "The `custom_data` must be either `null` or a valid Base64-Encoded string."
}
}
variable "data_disk_existing_disks" {
type = map(object({
caching = string
managed_disk_resource_id = string
lun = number
disk_attachment_create_option = optional(string, "Attach")
write_accelerator_enabled = optional(bool, false)
}))
default = {}
description = <<DATA_DISK_EXISTING_DISKS
A map of objects used to define one or more existing data disks for attachment to the virtual machine. This will not create the disks but will instead attach previously created disks to the virtual machine using their resource Ids. Lun numbers need to be unique across all disks include disks created as part of the module.
- `<map key>` - Use a custom map key to define each data disk
- `caching` (Required) - Specifies the caching requirements for this Data Disk. Possible values include None, ReadOnly and ReadWrite
- `lun` (Required) - The Logical Unit Number of the Data Disk, which needs to be unique within the Virtual Machine. Changing this forces a new resource to be created.
- `managed_disk_resource_id` (Required) - The Azure Resource ID of the existing Managed Disk to attach to the Virtual Machine. Changing this forces a new resource to be created.
- `disk_attachment_create_option` (Optional) - The disk attachment create Option of the Data Disk, such as Empty or Attach. Defaults to Attach. Changing this forces a new resource to be created.
- `write_accelerator_enabled` (Optional) - Should Write Accelerator be enabled for this Data Disk? Defaults to false. Changing this forces a new resource to be created.
DATA_DISK_EXISTING_DISKS
}
variable "data_disk_managed_disks" {
type = map(object({
caching = string
lun = number
name = string
storage_account_type = string
create_option = optional(string, "Empty")
disk_access_resource_id = optional(string)
disk_attachment_create_option = optional(string)
disk_encryption_set_resource_id = optional(string) #this is currently a preview feature in the provider
disk_iops_read_only = optional(number, null)
disk_iops_read_write = optional(number, null)
disk_mbps_read_only = optional(number, null)
disk_mbps_read_write = optional(number, null)
disk_size_gb = optional(number, 128)
gallery_image_reference_resource_id = optional(string)
hyper_v_generation = optional(string)
image_reference_resource_id = optional(string)
inherit_tags = optional(bool, true)
lock_level = optional(string, null)
lock_name = optional(string, null)
logical_sector_size = optional(number, null)
max_shares = optional(number)
network_access_policy = optional(string)
on_demand_bursting_enabled = optional(bool)
optimized_frequent_attach_enabled = optional(bool, false)
os_type = optional(string)
performance_plus_enabled = optional(bool, false)
public_network_access_enabled = optional(bool)
resource_group_name = optional(string)
secure_vm_disk_encryption_set_resource_id = optional(string)
security_type = optional(string)
source_resource_id = optional(string)
source_uri = optional(string)
storage_account_resource_id = optional(string)
tags = optional(map(string), null)
tier = optional(string)
trusted_launch_enabled = optional(bool)
upload_size_bytes = optional(number, null)
write_accelerator_enabled = optional(bool)
encryption_settings = optional(list(object({
disk_encryption_key_vault_secret_url = optional(string)
disk_encryption_key_vault_resource_id = optional(string)
key_encryption_key_vault_secret_url = optional(string)
key_encryption_key_vault_resource_id = optional(string)
})), [])
role_assignments = optional(map(object({
role_definition_id_or_name = string
principal_id = string
description = optional(string, null)
skip_service_principal_aad_check = optional(bool, false)
condition = optional(string, null)
condition_version = optional(string, null)
delegated_managed_identity_resource_id = optional(string, null)
principal_type = optional(string, null)
})), {})
}))
default = {}
description = <<DATA_DISK_MANAGED_DISKS
This variable is a map of objects used to define one or more data disks for creation and attachment to the virtual machine.
- `<map key>` - Use a custom map key to define each data disk
- `caching` (Required) - Specifies the caching requirements for this Data Disk. Possible values include None, ReadOnly and ReadWrite
- `lun` (Required) - The Logical Unit Number of the Data Disk, which needs to be unique within the Virtual Machine. Changing this forces a new resource to be created.
- `name` (Required) - Specifies the name of the Managed Disk. Changing this forces a new resource to be created.
- `storage_account_type` (Required) - The type of storage to use for the managed disk. Possible values are Standard_LRS, StandardSSD_ZRS, Premium_LRS, PremiumV2_LRS, Premium_ZRS, StandardSSD_LRS or UltraSSD_LRS
- `create_option` (Optional) - The method to use when creating the managed disk. Changing this forces a new resource to be created. Possible values include: 1. Import - Import a VHD file in to the managed disk (VHD specified with source_uri). 2.ImportSecure - Securely import a VHD file in to the managed disk (VHD specified with source_uri). 3. Empty - Create an empty managed disk. 4. Copy - Copy an existing managed disk or snapshot (specified with source_resource_id). 5. FromImage - Copy a Platform Image (specified with image_reference_id) 6. Restore - Set by Azure Backup or Site Recovery on a restored disk (specified with source_resource_id). 7. Upload - Upload a VHD disk with the help of SAS URL (to be used with upload_size_bytes).
- `disk_access_resource_id` (Optional) - The ID of the disk access resource for using private endpoints on disks. disk_access_resource_id is only supported when network_access_policy is set to AllowPrivate.
- `disk_attachment_create_option` (Optional) - The disk attachment create Option of the Data Disk, such as Empty or Attach. Defaults to Attach. Changing this forces a new resource to be created.
- `disk_encryption_set_resource_id` (Optional) - The resource ID of the Disk Encryption Set which should be used to Encrypt this OS Disk.
- `disk_iops_read_only` (Optional) - The number of IOPS allowed across all VMs mounting the shared disk as read-only; only settable for UltraSSD disks and PremiumV2 disks with shared disk enabled. One operation can transfer between 4k and 256k bytes.
- `disk_iops_read_write` (Optional) - The number of IOPS allowed for this disk; only settable for UltraSSD disks and PremiumV2 disks. One operation can transfer between 4k and 256k bytes.
- `disk_mbps_read_only` (Optional) - The bandwidth allowed across all VMs mounting the shared disk as read-only; only settable for UltraSSD disks and PremiumV2 disks with shared disk enabled. MBps means millions of bytes per second.
- `disk_mbps_read_write` (Optional) - The bandwidth allowed for this disk; only settable for UltraSSD disks and PremiumV2 disks. MBps means millions of bytes per second.
- `disk_size_gb` (Optional) - (Required for a new managed disk) - Specifies the size of the managed disk to create in gigabytes. If create_option is Copy or FromImage, then the value must be equal to or greater than the source's size. The size can only be increased.If No Downtime Resizing is not available, be aware that changing this value is disruptive if the disk is attached to a Virtual Machine. The VM will be shut down and de-allocated as required by Azure to action the change. Terraform will attempt to start the machine again after the update if it was in a running state when the apply was started. When upgrading disk_size_gb from value less than 4095 to a value greater than 4095, the disk will be detached from its associated Virtual Machine as required by Azure to action the change. Terraform will attempt to reattach the disk again after the update.
- `gallery_image_reference_resource_id` (Optional) - ID of a Gallery Image Version to copy when create_option is FromImage. This field cannot be specified if image_reference_id is specified. Changing this forces a new resource to be created.
- `hyper_v_generation` (Optional) - The HyperV Generation of the Disk when the source of an Import or Copy operation targets a source that contains an operating system. Possible values are V1 and V2. For ImportSecure it must be set to V2. Changing this forces a new resource to be created.
- `image_reference_resource_id` (Optional) - ID of an existing platform/marketplace disk image to copy when create_option is FromImage. This field cannot be specified if gallery_image_reference_resource_id is specified. Changing this forces a new resource to be created.
- `inherit_tags` (Optional) - Defaults to true. Set this to false if only the tags defined on this resource should be applied.
- `lock_level` (Optional) - Set this value to override the resource level lock value. Possible values are `CanNotDelete`, and `ReadOnly`.
- `lock_name` (Optional) - The name for the lock on this disk
- `logical_sector_size` (Optional) - Logical Sector Size. Possible values are: 512 and 4096. Defaults to 4096. Changing this forces a new resource to be created. Setting logical sector size is supported only with UltraSSD_LRS disks and PremiumV2_LRS disks.
- `max_shares` (Optional) - The maximum number of VMs that can attach to the disk at the same time. Value greater than one indicates a disk that can be mounted on multiple VMs at the same time. Premium SSD maxShares limit: P15 and P20 disks: 2. P30,P40,P50 disks: 5. P60,P70,P80 disks: 10. For ultra disks the max_shares minimum value is 1 and the maximum is 5.
- `network_access_policy` (Optional) - Policy for accessing the disk via network. Allowed values are AllowAll, AllowPrivate, and DenyAll.
- `on_demand_bursting_enabled` (Optional) - Specifies if On-Demand Bursting is enabled for the Managed Disk.
- `optimized_frequent_attach_enabled` (Optional) - Specifies whether this Managed Disk should be optimized for frequent disk attachments (where a disk is attached/detached more than 5 times in a day). Defaults to false. Setting optimized_frequent_attach_enabled to true causes the disks to not align with the fault domain of the Virtual Machine, which can have operational implications.
- `os_type` (Optional) - Specify a value when the source of an Import, ImportSecure or Copy operation targets a source that contains an operating system. Valid values are Linux or Windows.
- `performance_plus_enabled` (Optional) - Specifies whether Performance Plus is enabled for this Managed Disk. Defaults to false. Changing this forces a new resource to be created. performance_plus_enabled can only be set to true when using a Managed Disk with an Ultra SSD.
- `public_network_access_enabled` (Optional) - Whether it is allowed to access the disk via public network. Defaults to true.
- `resource_group_name` (Optional) - Specify a resource group name if the data disk should be created in a separate resource group from the virtual machine
- `secure_vm_disk_encryption_set_resource_id` (Optional) - The ID of the Disk Encryption Set which should be used to Encrypt this OS Disk when the Virtual Machine is a Confidential VM. Conflicts with disk_encryption_set_id. Changing this forces a new resource to be created. secure_vm_disk_encryption_set_resource_id can only be specified when security_type is set to ConfidentialVM_DiskEncryptedWithCustomerKey.
- `security_type` (Optional) - Security Type of the Managed Disk when it is used for a Confidential VM. Possible values are ConfidentialVM_VMGuestStateOnlyEncryptedWithPlatformKey, ConfidentialVM_DiskEncryptedWithPlatformKey and ConfidentialVM_DiskEncryptedWithCustomerKey. Changing this forces a new resource to be created. When security_type is set to ConfidentialVM_DiskEncryptedWithCustomerKey the value of create_option must be one of FromImage or ImportSecure. security_type cannot be specified when trusted_launch_enabled is set to true. secure_vm_disk_encryption_set_id must be specified when security_type is set to ConfidentialVM_DiskEncryptedWithCustomerKey.
- `source_resource_id` (Optional) - The ID of an existing Managed Disk or Snapshot to copy when create_option is Copy or the recovery point to restore when create_option is Restore. Changing this forces a new resource to be created.
- `source_uri` (Optional) - URI to a valid VHD file to be used when create_option is Import or ImportSecure. Changing this forces a new resource to be created.
- `storage_account_resource_id` (Optional) - The ID of the Storage Account where the source_uri is located. Required when create_option is set to Import or ImportSecure. Changing this forces a new resource to be created.
- `tags` (Optional) - A mapping of tags to assign to the resource.
- `tier` (Optional) - The disk performance tier to use. Possible values are documented at https://docs.microsoft.com/azure/virtual-machines/disks-change-performance. This feature is currently supported only for premium SSDs.Changing this value is disruptive if the disk is attached to a Virtual Machine. The VM will be shut down and de-allocated as required by Azure to action the change. Terraform will attempt to start the machine again after the update if it was in a running state when the apply was started.
- `trusted_launch_enabled` (Optional) - Specifies if Trusted Launch is enabled for the Managed Disk. Changing this forces a new resource to be created. Trusted Launch can only be enabled when create_option is FromImage or Import
- `upload_size_bytes` (Optional) - Specifies the size of the managed disk to create in bytes. Required when create_option is Upload. The value must be equal to the source disk to be copied in bytes. Source disk size could be calculated with ls -l or wc -c. More information can be found at Copy a managed disk. Changing this forces a new resource to be created.
- `write_accelerator_enabled` (Optional) - Specifies if Write Accelerator is enabled on the disk. This can only be enabled on Premium_LRS managed disks with no caching and M-Series VMs. Defaults to false.
- `encryption_settings` = (Optional) List of encryption objects with the following attributes:
- `disk_encryption_key_vault_secret_url` (Required) - The URL to the Key Vault Secret used as the Disk Encryption Key. This can be found as the id on the azurerm_key_vault_secret resource.
- `disk_encryption_key_vault_resource_id` (Required) - The ID of the source Key Vault. This can be found as the id on the azurerm_key_vault resource.
- `key_encryption_key_vault_secret_url` (Required) - The URL to the Key Vault Key used as the Key Encryption Key. This can be found as the id on the azurerm_key_vault_key resource.
- `key_encryption_key_vault_resource_id` (Required) - The ID of the source Key Vault. This can be found as the id on the azurerm_key_vault resource.
- `role_assignments` = (Optional) - Map of role assignments to assign to this disk
- `<map key>` - Use a custom map key to define each role assignment configuration assigned to the system managed identity of this virtual machine
- `role_definition_id_or_name` = (Required) - The Scoped-ID of the Role Definition or the built-in role name. Changing this forces a new resource to be created. Conflicts with role_definition_name
- `scope_resource_id` = (Required) - The scope at which the System Managed Identity Role Assignment applies to, such as /subscriptions/0b1f6471-1bf0-4dda-aec3-111122223333, /subscriptions/0b1f6471-1bf0-4dda-aec3-111122223333/resourceGroups/myGroup, or /subscriptions/0b1f6471-1bf0-4dda-aec3-111122223333/resourceGroups/myGroup/providers/Microsoft.Compute/virtualMachines/myVM, or /providers/Microsoft.Management/managementGroups/myMG. Changing this forces a new resource to be created.
- `condition` = (Optional) - The condition that limits the resources that the role can be assigned to. Changing this forces a new resource to be created.
- `condition_version` = (Optional) - The version of the condition. Possible values are 1.0 or 2.0. Changing this forces a new resource to be created.
- `description` = (Optional) - The description for this Role Assignment. Changing this forces a new resource to be created.
- `skip_service_principal_aad_check` = (Optional) - If the principal_id is a newly provisioned Service Principal set this value to true to skip the Azure Active Directory check which may fail due to replication lag. This argument is only valid if the principal_id is a Service Principal identity. Defaults to true.
- `delegated_managed_identity_resource_id` = (Optional) - The delegated Azure Resource Id which contains a Managed Identity. Changing this forces a new resource to be created.
- `principal_type` = (Optional) - The type of the `principal_id`. Possible values are `User`, `Group` and `ServicePrincipal`. It is necessary to explicitly set this attribute when creating role assignments if the principal creating the assignment is constrained by ABAC rules that filters on the PrincipalType attribute.
Example Inputs:
```hcl
#Create a new empty disk and attach it as lun 0
data_disk_managed_disks = {
disk1 = {
name = "testdisk1-win-lun0"
storage_account_type = "Premium_LRS"
lun = 0
caching = "ReadWrite"
disk_size_gb = 32
}
}
```
DATA_DISK_MANAGED_DISKS
nullable = false
}
variable "dedicated_host_group_resource_id" {
type = string
default = null
description = "(Optional) The Azure Resource ID of the dedicated host group where this virtual machine should run. Conflicts with dedicated_host_resource_id (dedicated_host_group_id on the azurerm provider)"
}
variable "dedicated_host_resource_id" {
type = string
default = null
description = "(Optional) The Azure Resource ID of the dedicated host where this virtual machine should run. Conflicts with dedicated_host_group_resource_id (dedicated_host_group_id on the azurerm provider)"
}
variable "diagnostic_settings" {
type = map(object({
name = optional(string, null)
log_categories = optional(set(string), [])
log_groups = optional(set(string), [])
metric_categories = optional(set(string), ["AllMetrics"])
log_analytics_destination_type = optional(string, "Dedicated")
workspace_resource_id = optional(string, null)
storage_account_resource_id = optional(string, null)
event_hub_authorization_rule_resource_id = optional(string, null)
event_hub_name = optional(string, null)
marketplace_partner_resource_id = optional(string, null)
}))
default = {}
description = <<DIAGNOSTIC_SETTINGS
This map object is used to define the diagnostic settings on the virtual machine. This functionality does not implement the diagnostic settings extension, but instead can be used to configure sending the vm metrics to one of the standard targets.
- `<map_key>` - unique key to define the map element
- `name` = (required) - Name to use for the Diagnostic setting configuration. Changing this creates a new resource
- `log_categories_and_groups` = (Optional) - List of strings used to define log categories and groups. Currently not valid for the VM resource
- `metric_categories` = (Optional) - List of strings used to define metric categories. Currently only AllMetrics is valid
- `log_analytics_destination_type` = (Optional) - Valid values are null, AzureDiagnostics, and Dedicated. Defaults to null
- `workspace_resource_id` = (Optional) - The Log Analytics Workspace Azure Resource ID when sending logs or metrics to a Log Analytics Workspace
- `storage_account_resource_id` = (Optional) - The Storage Account Azure Resource ID when sending logs or metrics to a Storage Account
- `event_hub_authorization_rule_resource_id` = (Optional) - The Event Hub Namespace Authorization Rule Resource ID when sending logs or metrics to an Event Hub Namespace
- `event_hub_name` = (Optional) - The Event Hub name when sending logs or metrics to an Event Hub
- `marketplace_partner_resource_id` = (Optional) - The marketplace partner solution Azure Resource ID when sending logs or metrics to a partner integration
Example Input:
diagnostic_settings = {
vm_diags = {
name = module.naming.monitor_diagnostic_setting.name_unique
workspace_resource_id = azurerm_log_analytics_workspace.this_workspace.id
metric_categories = ["AllMetrics"]
}
}
DIAGNOSTIC_SETTINGS
nullable = false
}
variable "disk_controller_type" {
type = string
default = null
description = "(Optional) - Specifies the Disk Controller Type used for this Virtual Machine. Possible values are `SCSI` and `NVME`."
}
variable "edge_zone" {
type = string
default = null
description = "(Optional) Specifies the Edge Zone within the Azure Region where this Virtual Machine should exist. Changing this forces a new Virtual Machine to be created."
}
variable "enable_automatic_updates" {
type = bool
default = true
description = "(Optional) Specifies if Automatic Updates are Enabled for the Windows Virtual Machine. Changing this forces a new resource to be created. Defaults to `true`."
}
variable "enable_telemetry" {
type = bool
default = true
description = <<DESCRIPTION
This variable controls whether or not telemetry is enabled for the module.
For more information see <https://aka.ms/avm/telemetryinfo>.
If it is set to false, then no telemetry will be collected.
DESCRIPTION
nullable = false
}
variable "encryption_at_host_enabled" {
type = bool
default = true
description = "(Optional) Should all of the disks (including the temp disk) attached to this Virtual Machine be encrypted by enabling Encryption at Host?"
}
variable "eviction_policy" {
type = string
default = null
description = "(Optional) Specifies what should happen when the Virtual Machine is evicted for price reasons when using a Spot instance. Possible values are Deallocate and Delete. Changing this forces a new resource to be created. This value can only be set when priority is set to Spot"
}
variable "extensions" {
type = map(object({
name = string
publisher = string
type = string
type_handler_version = string
auto_upgrade_minor_version = optional(bool)
automatic_upgrade_enabled = optional(bool)
deploy_sequence = optional(number, 5)
failure_suppression_enabled = optional(bool, false)
settings = optional(string)
protected_settings = optional(string)
provision_after_extensions = optional(list(string), [])
tags = optional(map(string), null)
protected_settings_from_key_vault = optional(object({
secret_url = string
source_vault_id = string
}))
timeouts = optional(object({
create = optional(string)
delete = optional(string)
update = optional(string)
read = optional(string)
})
)
}))
# tflint-ignore: terraform_sensitive_variable_no_default
default = {}
description = <<EXTENSIONS
This map of objects is used to create additional `azurerm_virtual_machine_extension` resources, the argument descriptions could be found at [the document](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine_extension).
- `<map key>` - Provide a custom key value to define each extension object
- `name` (Required) - Set a custom name on this value if you want the guest configuration extension to have a custom name
- `publisher` (Required) - Configure the publisher for the extension to be deployed. The Publisher and Type of Virtual Machine Extensions can be found using the Azure CLI, via: az vm extension image list --location westus -o table
- `type` (Required) - Configure the type value for the extension to be deployed.
- `type_handler_version` (Required) - The type handler version for the extension. A common value is 1.0.
- `auto_upgrade_minor_version` (Optional) - Set this to false to avoid automatic upgrades for minor versions on the extension. Defaults to true
- `automatic_upgrade_enabled` (Optional) - Set this to false to avoid automatic upgrades for major versions on the extension. Defaults to true
- `deploy_sequence` (Optional) - The sequence number in which the extension should be provisioned. This value allows for serialization of two extensions. Sequence numbers of 3 and higher are deployed in parallel after the first two serialized extensions. Defaults to 3 to be non-breaking for previous versions of the module.
- `failure_suppression_enabled` (Optional) - Should failures from the extension be suppressed? Possible values are true or false. Defaults to false. Operational failures such as not connecting to the VM will not be suppressed regardless of the failure_suppression_enabled value.
- `settings` (Optional) - The settings passed to the extension, these are specified as a JSON object in a string. Certain VM Extensions require that the keys in the settings block are case sensitive. If you're seeing unhelpful errors, please ensure the keys are consistent with how Azure is expecting them (for instance, for the JsonADDomainExtension extension, the keys are expected to be in TitleCase.)
- `protected_settings` (Optional) - The protected_settings passed to the extension, like settings, these are specified as a JSON object in a string. Certain VM Extensions require that the keys in the protected_settings block are case sensitive. If you're seeing unhelpful errors, please ensure the keys are consistent with how Azure is expecting them (for instance, for the JsonADDomainExtension extension, the keys are expected to be in TitleCase.)
- `provision_after_extensions` (Optional) - list of strings that specifies the collection of extension names after which this extension needs to be provisioned.
- `protected_settings_from_key_vault` (Optional) object for protected settings. Cannot be used with `protected_settings`
- `secret_url` (Required) - The Secret URL of a Key Vault Certificate. This can be sourced from the `secret_id` field within the `azurerm_key_vault_certificate` Resource.
- `source_vault_id` (Required) - the Azure resource ID of the key vault holding the secret
- `tags` (Optional) - A mapping of tags to assign to the extension resource.
- `timeouts` (Optional): Timeouts for the extension resource.
Example Inputs:
```hcl
#custom script extension example - linux
extensions = {
custom_script_extension_linux = {
name = "CustomScriptExtension"
publisher = "Microsoft.Azure.Extensions"
type = "CustomScript"
type_handler_version = "2.0"
settings = <<SETTINGS
{
"script": "<base 64 encoded script file>"
}
SETTINGS
}
}
#custom script extension example - windows
extensions = {
custom_script_extension_windows = {
name = "CustomScriptExtension"
publisher = "Microsoft.Compute"
type = "CustomScriptExtension"
type_handler_version = "1.10"
settings = <<SETTINGS
{
"timestamp":123456789
}
SETTINGS
protected_settings = <<PROTECTED_SETTINGS
{
"commandToExecute": "myExecutionCommand",
"storageAccountName": "myStorageAccountName",
"storageAccountKey": "myStorageAccountKey",
"managedIdentity" : {},
"fileUris": [
"script location"
]
}
PROTECTED_SETTINGS
}
}
```
EXTENSIONS
nullable = false
sensitive = true # Because `protected_settings` is sensitive
validation {
condition = length(var.extensions) == length(distinct([
for e in var.extensions : e.type
]))
error_message = "`type` in `vm_extensions` must be unique."
}
}
variable "extensions_time_budget" {
type = string
default = "PT1H30M"
description = "(Optional) Specifies the duration allocated for all extensions to start. The time duration should be between 15 minutes and 120 minutes (inclusive) and should be specified in ISO 8601 format. Defaults to 90 minutes (`PT1H30M`)."
}
variable "gallery_applications" {
type = map(object({
version_id = string
configuration_blob_uri = optional(string)
order = optional(number, 0)
tag = optional(string)
}))
default = {}
description = <<GALLERY_APPLICATIONS
A list of gallery application objects with the following elements:
- `<map key>` - Used to designate a unique instance for a gallery application.
- `version_id` (Required) Specifies the Gallery Application Version resource ID.
- `configuration_blob_uri` (Optional) Specifies the URI to an Azure Blob that will replace the default configuration for the package if provided.
- `order` (Optional) Specifies the order in which the packages have to be installed. Possible values are between `0` and `2,147,483,647`.
- `tag` (Optional) Specifies a passthrough value for more generic context. This field can be any valid `string` value.
Example Inputs:
```hcl
gallery_applications = {
application_1 = {
version_id = "/subscriptions/{subscriptionId}/resourceGroups/<resource group>/providers/Microsoft.Compute/galleries/{gallery name}/applications/{application name}/versions/{version}"
order = 1
}
}
```
GALLERY_APPLICATIONS
nullable = false
}
variable "hotpatching_enabled" {
type = bool
default = false
description = "(Optional) Should the VM be patched without requiring a reboot? Possible values are `true` or `false`. Defaults to `false`. For more information about hot patching please see the [product documentation](https://docs.microsoft.com/azure/automanage/automanage-hotpatch). Hotpatching can only be enabled if the `patch_mode` is set to `AutomaticByPlatform`, the `provision_vm_agent` is set to `true`, your `source_image_reference` references a hotpatching enabled image, and the VM's `size` is set to a [Azure generation 2](https://docs.microsoft.com/azure/virtual-machines/generation-2#generation-2-vm-sizes) VM. An example of how to correctly configure a Windows Virtual Machine to use the `hotpatching_enabled` field can be found in the [`./examples/virtual-machines/windows/hotpatching-enabled`](https://github.com/hashicorp/terraform-provider-azurerm/tree/main/examples/virtual-machines/windows/hotpatching-enabled) directory within the GitHub Repository."
}
variable "license_type" {
type = string
default = null
description = "(Optional) For Linux virtual machine specifies the BYOL Type for this Virtual Machine, possible values are `RHEL_BYOS` and `SLES_BYOS`. For Windows virtual machine specifies the type of on-premise license (also known as [Azure Hybrid Use Benefit](https://docs.microsoft.com/windows-server/get-started/azure-hybrid-benefit)) which should be used for this Virtual Machine, possible values are `None`, `Windows_Client` and `Windows_Server`."
}
variable "lock" {
type = object({
name = optional(string, null)
kind = string
})
default = null
description = <<LOCK
"The lock configuration to apply to this virtual machine and all of it's child resources. The following properties are specified.
- `kind` - (Required) - The type of the lock. Possible values are `CanNotDelete` and `ReadOnly`.
- `name` - (Optional) - The name of the lock. If not specified, a name will be generated based on the `kind` value. Changing this forces the creation of a new resource.
Example Inputs:
```hcl
lock = {
name = "lock-{resourcename}" # optional
type = "CanNotDelete"
}
```
LOCK
validation {
condition = var.lock != null ? contains(["CanNotDelete", "ReadOnly"], var.lock.kind) : true
error_message = "Lock kind must be either `\"CanNotDelete\"` or `\"ReadOnly\"`."
}
}
variable "maintenance_configuration_resource_ids" {
type = map(string)
default = {}
description = <<DESCRIPTION
A map of maintenance configuration Id(s) to apply to this virtual machine. Using a map to avoid any issues with known before apply. The key value is arbitrary as it is only used as the index for terraform.
Example Input:
```hcl
{
config_1 = "<maintenance configuration Azure resource id>"
}
```
DESCRIPTION
}
variable "managed_identities" {
type = object({
system_assigned = optional(bool, false)
user_assigned_resource_ids = optional(set(string), [])
})
default = {}
description = <<IDENTITY
An object that sets the managed identity configuration for the virtual machine being deployed. Be aware that capabilities such as the Azure Monitor Agent and Role Assignments require that a managed identity has been configured.
- `system_assigned` = (Optional) Specifies whether the System Assigned Managed Identity should be enabled. Defaults to false.
- `user_assigned_resource_ids` = (Optional) Specifies a set of User Assigned Managed Identity IDs to be assigned to this Virtual Machine.
Example Inputs:
```hcl
#default system managed identity
managed_identities = {
system_assigned = true
}
#user assigned managed identity only
managed_identities = {
user_assigned_resource_ids = ["<azure resource ID of a user assigned managed identity>"]
}
#user assigned and system assigned managed identities
managed_identities = {
system_assigned = true
user_assigned_resource_ids = ["<azure resource ID of a user assigned managed identity>"]
}
```
IDENTITY
nullable = false
}
variable "max_bid_price" {
type = number
default = -1
description = "(Optional) The maximum price you're willing to pay for this Virtual Machine, in US Dollars; which must be greater than the current spot price. If this bid price falls below the current spot price the Virtual Machine will be evicted using the `eviction_policy`. Defaults to `-1`, which means that the Virtual Machine should not be evicted for price reasons. This can only be configured when `priority` is set to `Spot`."
}
variable "network_interfaces" {
type = map(object({
name = string
ip_configurations = map(object({
name = string
app_gateway_backend_pools = optional(map(object({
app_gateway_backend_pool_resource_id = string
})), {})
create_public_ip_address = optional(bool, false)
gateway_load_balancer_frontend_ip_configuration_resource_id = optional(string)
is_primary_ipconfiguration = optional(bool, true)
load_balancer_backend_pools = optional(map(object({
load_balancer_backend_pool_resource_id = string
})), {})
load_balancer_nat_rules = optional(map(object({
load_balancer_nat_rule_resource_id = string
})), {})
private_ip_address = optional(string)
private_ip_address_allocation = optional(string, "Dynamic")
private_ip_address_version = optional(string, "IPv4")
private_ip_subnet_resource_id = optional(string)
public_ip_address_lock_name = optional(string)
public_ip_address_name = optional(string)
public_ip_address_resource_id = optional(string)
}))
accelerated_networking_enabled = optional(bool, false)
application_security_groups = optional(map(object({
application_security_group_resource_id = string
})), {})
diagnostic_settings = optional(map(object({
name = optional(string, null)
log_categories = optional(set(string), [])
log_groups = optional(set(string), [])
metric_categories = optional(set(string), ["AllMetrics"])
log_analytics_destination_type = optional(string, null)
workspace_resource_id = optional(string, null)
storage_account_resource_id = optional(string, null)
event_hub_authorization_rule_resource_id = optional(string, null)
event_hub_name = optional(string, null)
marketplace_partner_resource_id = optional(string, null)
})), {})
dns_servers = optional(list(string))
inherit_tags = optional(bool, true)
internal_dns_name_label = optional(string)
ip_forwarding_enabled = optional(bool, false)
is_primary = optional(bool, false)
lock_level = optional(string)
lock_name = optional(string)
network_security_groups = optional(map(object({
network_security_group_resource_id = string
})), {})
resource_group_name = optional(string)
role_assignments = optional(map(object({
principal_id = string
role_definition_id_or_name = string
assign_to_child_public_ip_addresses = optional(bool, true)
condition = optional(string, null)
condition_version = optional(string, null)
delegated_managed_identity_resource_id = optional(string, null)
description = optional(string, null)
skip_service_principal_aad_check = optional(bool, false)
principal_type = optional(string, null)
})), {})
tags = optional(map(string), null)
}))
default = {
ipconfig_1 = {
name = "default-ipv4-ipconfig"
ip_configurations = {
ip_config_1 = {
name = "ipv4-ipconfig"
private_ip_address = null
private_ip_address_version = "IPv4"
private_ip_address_allocation = "Dynamic"
private_ip_subnet_resource_id = null
public_ip_address_resource_id = null
is_primary_ipconfiguration = true
gateway_load_balancer_frontend_ip_configuration_resource_id = null
}
}
dns_servers = null
accelerated_networking_enabled = true
ip_forwarding_enabled = false
internal_dns_name_label = null
tags = null
} }
description = <<NETWORK_INTERFACES
A map of objects representing each network virtual machine network interface
- `<map key>` - Use a custom map key to define each network interface
- `name` = (Required) The name of the Network Interface. Changing this forces a new resource to be created.
- `ip_configurations` - A required map of objects defining each interfaces IP configurations
- `<map key>` - Use a custom map key to define each ip configuration
- `name` = (Required) - A name used for this IP Configuration.
- `app_gateway_backend_pools` = (Optional) - A map defining app gateway backend pool(s) this IP configuration should be associated to.
- `<map key>` - Use a custom map key to define each app gateway backend pool association. This is done to handle issues with certain details not being known until after apply.
- `app_gateway_backend_pool_resource_id` = (Required) - An application gateway backend pool Azure Resource ID can be entered to join this ip configuration to the backend pool of an Application Gateway.
- `create_public_ip_address` = (Optional) - Select true here to have the module create the public IP address for this IP Configuration
- `gateway_load_balancer_frontend_ip_configuration_resource_id` = (Optional) - The Frontend IP Configuration Azure Resource ID of a Gateway SKU Load Balancer.)
- `is_primary_ipconfiguration` = (Optional) - Is this the Primary IP Configuration? Must be true for the first ip_configuration when multiple are specified.
- `load_balancer_backend_pools` = (Optional) - A map defining load balancer backend pool(s) this IP configuration should be associated to.
- `<map key>` - Use a custom map key to define each load balancer backend pool association. This is done to handle issues with certain details not being known until after apply.
- `load_balancer_backend_pool_resource_id` = (Required) - A Load Balancer backend pool Azure Resource ID can be entered to join this ip configuration to a load balancer backend pool.
- `load_balancer_nat_rules` = (Optional) - A map defining load balancer NAT rule(s) that this IP Configuration should be associated to.
- `<map key>` - Use a custom map key to define each load balancer NAT Rule association. This is done to handle issues with certain details not being known until after apply.
- `load_balancer_nat_rule_resource_id` = (Optional) - A Load Balancer Nat Rule Azure Resource ID can be entered to associate this ip configuration to a load balancer NAT rule.
- `private_ip_address` = (Optional) - The Static IP Address which should be used. Configured when private_ip_address_allocation is set to Static
- `private_ip_address_allocation` = (Optional) - The allocation method used for the Private IP Address. Possible values are Dynamic and Static. Dynamic means "An IP is automatically assigned during creation of this Network Interface" and is the default; Static means "User supplied IP address will be used"
- `private_ip_address_version` = (Optional) - The IP Version to use. Possible values are IPv4 or IPv6. Defaults to IPv4.
- `private_ip_subnet_resource_id` = (Optional) - The Azure Resource ID of the Subnet where this Network Interface should be located in.
- `public_ip_address_resource_id` = (Optional) - Reference to a Public IP Address resource ID to associate with this NIC
- `accelerated_networking_enabled` = (Optional) - Should Accelerated Networking be enabled? Defaults to false. Only certain Virtual Machine sizes are supported for Accelerated Networking. To use Accelerated Networking in an Availability Set, the Availability Set must be deployed onto an Accelerated Networking enabled cluster.
- `application_security_groups` = (Optional) - A map defining the Application Security Group(s) that this network interface should be a part of.
- `<map key>` - Use a custom map key to define each Application Security Group association. This is done to handle issues with certain details not being known until after apply.
- `application_security_group_resource_id` = (Required) - The Application Security Group (ASG) Azure Resource ID for this Network Interface to be associated to.
- `diagnostic_settings` = (Optional) - A map of objects defining the network interface resource diagnostic settings
- `<map key>` - Use a custom map key to define each diagnostic setting configuration
- `name` = (required) - Name to use for the Diagnostic setting configuration. Changing this creates a new resource
- `event_hub_authorization_rule_resource_id` = (Optional) - The Event Hub Namespace Authorization Rule Resource ID when sending logs or metrics to an Event Hub Namespace
- `event_hub_name` = (Optional) - The Event Hub name when sending logs or metrics to an Event Hub
- `log_analytics_destination_type` = (Optional) - Valid values are null, AzureDiagnostics, and Dedicated. Defaults to null
- `log_categories_and_groups` = (Optional) - List of strings used to define log categories and groups. Currently not valid for the VM resource
- `marketplace_partner_resource_id` = (Optional) - The marketplace partner solution Azure Resource ID when sending logs or metrics to a partner integration
- `metric_categories` = (Optional) - List of strings used to define metric categories. Currently only AllMetrics is valid
- `storage_account_resource_id` = (Optional) - The Storage Account Azure Resource ID when sending logs or metrics to a Storage Account
- `workspace_resource_id` = (Optional) - The Log Analytics Workspace Azure Resource ID when sending logs or metrics to a Log Analytics Workspace
- `dns_servers` = (Optional) - A list of IP Addresses defining the DNS Servers which should be used for this Network Interface.
- `inherit_tags` = (Optional) - Defaults to true. Set this to false if only the tags defined on this resource should be applied. This is potential future functionality and is currently ignored.
- `internal_dns_name_label` = (Optional) - The (relative) DNS Name used for internal communications between Virtual Machines in the same Virtual Network.
- `ip_forwarding_enabled` = (Optional) - Should IP Forwarding be enabled? Defaults to false
- `lock_level` = (Optional) - Set this value to override the resource level lock value. Possible values are `None`, `CanNotDelete`, and `ReadOnly`.
- `lock_name` = (Optional) - The name for the lock on this nic
- `network_security_groups` = (Optional) - A map describing Network Security Group(s) that this Network Interface should be associated to.
- `<map key>` - Use a custom map key to define each network security group association. This is done to handle issues with certain details not being known until after apply.
- `network_security_group_resource_id` = (Optional) - The Network Security Group (NSG) Azure Resource ID used to associate this Network Interface to the NSG.
- `resource_group_name` (Optional) - Specify a resource group name if the network interface should be created in a separate resource group from the virtual machine
- `role_assignments` = An optional map of objects defining role assignments on the individual network configuration resource
- `<map key>` - Use a custom map key to define each role assignment configuration
- `assign_to_child_public_ip_addresses` = (Optional) - Set this to true if the assignment should also apply to any children public IP addresses.
- `condition` = (Optional) - The condition that limits the resources that the role can be assigned to. Changing this forces a new resource to be created.
- `condition_version` = (Optional) - The version of the condition. Possible values are 1.0 or 2.0. Changing this forces a new resource to be created.
- `delegated_managed_identity_resource_id` = (Optional) - The delegated Azure Resource Id which contains a Managed Identity. Changing this forces a new resource to be created.
- `description` = (Optional) - The description for this Role Assignment. Changing this forces a new resource to be created.
- `principal_id` = (optional) - The ID of the Principal (User, Group or Service Principal) to assign the Role Definition to. Changing this forces a new resource to be created.
- `role_definition_id_or_name` = (Optional) - The Scoped-ID of the Role Definition or the built-in role name. Changing this forces a new resource to be created. Conflicts with role_definition_name
- `skip_service_principal_aad_check` = (Optional) - If the principal_id is a newly provisioned Service Principal set this value to true to skip the Azure Active Directory check which may fail due to replication lag. This argument is only valid if the principal_id is a Service Principal identity. Defaults to true.
- `principal_type` = (Optional) - The type of the `principal_id`. Possible values are `User`, `Group` and `ServicePrincipal`. It is necessary to explicitly set this attribute when creating role assignments if the principal creating the assignment is constrained by ABAC rules that filters on the PrincipalType attribute.
- `tags` = (Optional) - A mapping of tags to assign to the resource.
Example Inputs:
```hcl
#Simple private IP single NIC with IPV4 private address
network_interfaces = {
network_interface_1 = {
name = "testnic1"
ip_configurations = {
ip_configuration_1 = {
name = "testnic1-ipconfig1"
private_ip_subnet_resource_id = azurerm_subnet.this_subnet_1.id
}
}
}
}
#Simple NIC with private and public IP address
network_interfaces = {
network_interface_1 = {
name = "testnic1"
ip_configurations = {
ip_configuration_1 = {
name = "testnic1-ipconfig1"
private_ip_subnet_resource_id = azurerm_subnet.this_subnet_1.id
create_public_ip_address = true
public_ip_address_name = "vm1-testnic1-publicip1"
}
}
}
}
```
NETWORK_INTERFACES
nullable = false
}
variable "os_disk" {
type = object({
caching = string
storage_account_type = string
disk_encryption_set_id = optional(string)
disk_size_gb = optional(number)
name = optional(string)
secure_vm_disk_encryption_set_id = optional(string)
security_encryption_type = optional(string)
write_accelerator_enabled = optional(bool, false)
diff_disk_settings = optional(object({
option = string
placement = optional(string, "CacheDisk")
}), null)
})
default = {
caching = "ReadWrite"
storage_account_type = "Premium_LRS"
}
description = <<OS_DISK
Required configuration values for the OS disk on the virtual machine.
- `caching` = (Required) - The type of caching which should be used for the internal OS disk. Possible values are `None`, `ReadOnly`, and `ReadWrite`.
- `storage_account_type` = (Required) - The Type of Storage Account which should back this the Internal OS Disk. Possible values are `Standard_LRS`, `Premium_LRS`, `Premium_LRS`, `StandardSSD_ZRS` and `Premium_ZRS`. Changing this forces a new resource to be created
- `disk_encryption_set_id` = (Optional) - The Azure Resource ID of the Disk Encryption Set which should be used to Encrypt this OS Disk. Conflicts with secure_vm_disk_encryption_set_id. The Disk Encryption Set must have the Reader Role Assignment scoped on the Key Vault - in addition to an Access Policy to the Key Vault
- `disk_size_gb` = (Optional) - The Size of the Internal OS Disk in GB, if you wish to vary from the size used in the image this Virtual Machine is sourced from.
- `name` = (Optional) - The name which should be used for the Internal OS Disk. Changing this forces a new resource to be created.
- `secure_vm_disk_encryption_set_id` = (Optional) - The Azure Resource ID of the Disk Encryption Set which should be used to Encrypt this OS Disk when the Virtual Machine is a Confidential VM. Conflicts with disk_encryption_set_id. Changing this forces a new resource to be created.
- `security_encryption_type` = (Optional) - Encryption Type when the Virtual Machine is a Confidential VM. Possible values are `VMGuestStateOnly` and `DiskWithVMGuestState`. Changing this forces a new resource to be created. `vtpm_enabled` must be set to true when security_encryption_type is specified. encryption_at_host_enabled cannot be set to `true` when security_encryption_type is set to `DiskWithVMGuestState`
- `write_accelerator_enabled` = (Optional) - Should Write Accelerator be Enabled for this OS Disk? Defaults to `false`. This requires that the storage_account_type is set to `Premium_LRS` and that caching is set to `None`
- `diff_disk_settings` - An optional object defining the diff disk settings
- `option` = (Required) - Specifies the Ephemeral Disk Settings for the OS Disk. At this time the only possible value is `Local`. Changing this forces a new resource to be created.
- `placement` = (Optional) - Specifies where to store the Ephemeral Disk. Possible values are CacheDisk and ResourceDisk. Defaults to CacheDisk. Changing this forces a new resource to be created.
Example Inputs:
```hcl
#basic example: