diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f2b7a5..2deb9f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0. ## [Unreleased] +## [1.3.0] - 2024-08-20 + +### Added + - To support Copy/Restore disk on managed disk. + +### Changed + - Upgrade accelerated networking variable in network interfaces. + ## [1.2.0] - 2024-08-02 ### Added @@ -20,6 +28,7 @@ and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0. ### Added - Initial code that creates a VM + ### Changed ### Removed diff --git a/README.md b/README.md index f94ff95..4baf811 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ resource "azurerm_subnet" "this" { | [virtual\_machine\_config](#input\_virtual\_machine\_config) |
hostname: Name of system hostname.
size: The size of the vm. Possible values can be seen here: https://learn.microsoft.com/en-us/azure/virtual-machines/sizes
location: The location of the virtual machine.
os_sku: (Required) The os that will be running on the vm.
os_offer: (Required) Specifies the offer of the image used to create the virtual machines. Changing this forces a new resource to be created.
os_version: (Required) Optionally specify an os version for the chosen sku.
os_publisher: (Required) Specifies the Publisher of the Marketplace Image this Virtual Machine should be created from. Changing this forces a new resource to be created.
os_disk_caching: Optionally change the caching option of the os disk. Defaults to ReadWrite.
os_disk_size_gb: Optionally change the size of the os disk. Defaults to be specified by image.
os_disk_storage_type: Optionally change the os_disk_storage_type. Defaults to StandardSSD_LRS.
zone: Optionally specify an availibility zone for the vm. Values 1, 2 or 3.
availability_set_id: Optionally specify an availibility set for the vm. Not compatible with zone.
os_disk_write_accelerator_enabled: Optionally activate write accelaration for the os disk. Can only
be activated on Premium disks and caching deactivated. Defaults to false.
proximity_placement_group_id: (Optional) The ID of the Proximity Placement Group which the Virtual Machine should be assigned to.
severity_group: (Required) Sets tag 'Severity Group Monthly' to a specific time and date when an update will be done automatically.
update_allowed: Sets tag 'Update allowed' to yes or no to specify if this VM should currently receive updates.
|
object({
hostname = string
size = string
location = string
os_sku = string
os_offer = string
os_version = string
os_publisher = string
os_disk_caching = optional(string, "ReadWrite")
os_disk_size_gb = optional(number)
os_disk_storage_type = optional(string, "Premium_LRS")
os_disk_write_accelerator_enabled = optional(bool, false)
zone = optional(number)
availability_set_id = optional(string)
proximity_placement_group_id = optional(string)
severity_group = string
update_allowed = optional(bool, true)
})
| n/a | yes | | [additional\_network\_interface\_ids](#input\_additional\_network\_interface\_ids) | List of ids for additional azurerm\_network\_interface. | `list(string)` | `[]` | no | | [admin\_username](#input\_admin\_username) | Optionally choose the admin\_username of the vm. Defaults to loc\_sysadmin. | `string` | `"loc_sysadmin"` | no | -| [data\_disks](#input\_data\_disks) |
 = {
lun: Number of the lun.
disk_size_gb: The size of the data disk.
storage_account_type: Optionally change the storage_account_type. Defaults to StandardSSD_LRS.
caching: Optionally activate disk caching. Defaults to None.
create_option: Optionally change the create option. Defaults to Empty disk.
write_accelerator_enabled: Optionally activate write accelaration for the data disk. Can only
be activated on Premium disks and caching deactivated. Defaults to false.
on_demand_bursting_enabled: Optionally activate disk bursting. Only for Premium disk. Default false.
}
|
map(object({
lun = number
disk_size_gb = number
caching = optional(string, "ReadWrite")
create_option = optional(string, "Empty")
storage_account_type = optional(string, "Premium_LRS")
write_accelerator_enabled = optional(bool, false)
on_demand_bursting_enabled = optional(bool, false)
}))
| `{}` | no | +| [data\_disks](#input\_data\_disks) |
 = {
lun: Number of the lun.
disk_size_gb: The size of the data disk.
storage_account_type: Optionally change the storage_account_type. Defaults to StandardSSD_LRS.
caching: Optionally activate disk caching. Defaults to None.
create_option: Optionally change the create option. Defaults to Empty disk.
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.
write_accelerator_enabled: Optionally activate write accelaration for the data disk. Can only
be activated on Premium disks and caching deactivated. Defaults to false.
on_demand_bursting_enabled: Optionally activate disk bursting. Only for Premium disk. Default false.
}
|
map(object({
lun = number
disk_size_gb = number
caching = optional(string, "ReadWrite")
create_option = optional(string, "Empty")
source_resource_id = optional(string)
storage_account_type = optional(string, "Premium_LRS")
write_accelerator_enabled = optional(bool, false)
on_demand_bursting_enabled = optional(bool, false)
}))
| `{}` | no | | [name\_overrides](#input\_name\_overrides) | Possibility to override names that will be generated according to q.beyond naming convention. |
object({
nic = optional(string)
nic_ip_config = optional(string)
public_ip = optional(string)
virtual_machine = optional(string)
os_disk = optional(string)
data_disks = optional(map(string), {})
})
| `{}` | no | | [nic\_config](#input\_nic\_config) |
private_ip: Optioanlly specify a private ip to use. Otherwise it will  be allocated dynamically.
dns_servers: Optionally specify a list of dns servers for the nic.
enable_accelerated_networking: Enabled Accelerated networking (SR-IOV) on the NIC. The machine SKU must support this feature.
nsg: Although it is discouraged you can optionally assign an NSG to the NIC. Optionally specify a NSG object.
|
object({
private_ip = optional(string)
dns_servers = optional(list(string))
enable_accelerated_networking = optional(bool, false)
nsg = optional(object({
id = string
}))
})
| `{}` | no | | [public\_ip\_config](#input\_public\_ip\_config) |
allocation_method: The allocation method of the public ip that will be created. Defaults to static.
stage: The stage of this PIP. Ex: prd, dev, tst, ...
|
object({
allocation_method = optional(string, "Static")
stage = string
})
| `null` | no | diff --git a/data_disk.tf b/data_disk.tf index 9a976ac..4cea198 100644 --- a/data_disk.tf +++ b/data_disk.tf @@ -6,6 +6,7 @@ resource "azurerm_managed_disk" "data_disk" { zone = var.virtual_machine_config.zone storage_account_type = each.value["storage_account_type"] create_option = each.value["create_option"] + source_resource_id = each.value["source_resource_id"] disk_size_gb = each.value["disk_size_gb"] on_demand_bursting_enabled = each.value["on_demand_bursting_enabled"] tags = var.tags diff --git a/main.tf b/main.tf index bdda7b9..36f5e0e 100644 --- a/main.tf +++ b/main.tf @@ -8,12 +8,12 @@ resource "azurerm_public_ip" "this" { } resource "azurerm_network_interface" "this" { - name = local.nic.name - location = var.virtual_machine_config.location - resource_group_name = var.resource_group_name - dns_servers = var.nic_config.dns_servers - enable_accelerated_networking = var.nic_config.enable_accelerated_networking - tags = var.tags + name = local.nic.name + location = var.virtual_machine_config.location + resource_group_name = var.resource_group_name + dns_servers = var.nic_config.dns_servers + accelerated_networking_enabled = var.nic_config.enable_accelerated_networking + tags = var.tags ip_configuration { name = local.nic.ip_config_name diff --git a/variables.tf b/variables.tf index 536fd2c..9f2f58c 100644 --- a/variables.tf +++ b/variables.tf @@ -152,6 +152,7 @@ variable "data_disks" { disk_size_gb = number caching = optional(string, "ReadWrite") create_option = optional(string, "Empty") + source_resource_id = optional(string) storage_account_type = optional(string, "Premium_LRS") write_accelerator_enabled = optional(bool, false) on_demand_bursting_enabled = optional(bool, false) @@ -182,6 +183,12 @@ variable "data_disks" { condition = alltrue([for k, v in var.data_disks : !strcontains(k, "-")]) error_message = "Logical Name can't contain a '-'" } + validation { + condition = alltrue([for o in var.data_disks : ( + (o.source_resource_id != null && contains(["Copy", "Restore"], o.create_option) || (o.create_option == "Empty" && o.source_resource_id == null)) + )]) + error_message = "When a data disk source resource ID is specified then create option must be either 'Copy' or 'Restore'." + } default = {} nullable = false @@ -193,6 +200,8 @@ variable "data_disks" { storage_account_type: Optionally change the storage_account_type. Defaults to StandardSSD_LRS. caching: Optionally activate disk caching. Defaults to None. create_option: Optionally change the create option. Defaults to Empty disk. + 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. write_accelerator_enabled: Optionally activate write accelaration for the data disk. Can only be activated on Premium disks and caching deactivated. Defaults to false. on_demand_bursting_enabled: Optionally activate disk bursting. Only for Premium disk. Default false.