Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added plan passthrough variable #5

Merged
merged 11 commits into from
Sep 16, 2024
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.

## [Unreleased]

## [1.4.0] - 2024-09-16
- Added enable_plan option for marketplace images.

## [1.3.0] - 2024-08-20

### Added
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ resource "azurerm_subnet" "this" {
| <a name="input_admin_credential"></a> [admin\_credential](#input\_admin\_credential) | <pre>Specify either admin_password or public_key:<br> admin_password: Password of the local administrator.<br> public_key: SSH public key file (e.g. file(id_rsa.pub))</pre> | <pre>object({<br> admin_password = optional(string)<br> public_key = optional(string)<br> })</pre> | n/a | yes |
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | Name of the resource group where the resources will be created. | `string` | n/a | yes |
| <a name="input_subnet"></a> [subnet](#input\_subnet) | The variable takes the subnet as input and takes the id and the address prefix for further configuration. | <pre>object({<br> id = string<br> address_prefixes = list(string)<br> })</pre> | n/a | yes |
| <a name="input_virtual_machine_config"></a> [virtual\_machine\_config](#input\_virtual\_machine\_config) | <pre>hostname: Name of system hostname.<br> size: The size of the vm. Possible values can be seen here: https://learn.microsoft.com/en-us/azure/virtual-machines/sizes<br> location: The location of the virtual machine.<br> os_sku: (Required) The os that will be running on the vm.<br> os_offer: (Required) Specifies the offer of the image used to create the virtual machines. Changing this forces a new resource to be created.<br> os_version: (Required) Optionally specify an os version for the chosen sku.<br> 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.<br> os_disk_caching: Optionally change the caching option of the os disk. Defaults to ReadWrite.<br> os_disk_size_gb: Optionally change the size of the os disk. Defaults to be specified by image.<br> os_disk_storage_type: Optionally change the os_disk_storage_type. Defaults to StandardSSD_LRS.<br> zone: Optionally specify an availibility zone for the vm. Values 1, 2 or 3.<br> availability_set_id: Optionally specify an availibility set for the vm. Not compatible with zone.<br> os_disk_write_accelerator_enabled: Optionally activate write accelaration for the os disk. Can only<br> be activated on Premium disks and caching deactivated. Defaults to false.<br> proximity_placement_group_id: (Optional) The ID of the Proximity Placement Group which the Virtual Machine should be assigned to.<br> severity_group: (Required) Sets tag 'Severity Group Monthly' to a specific time and date when an update will be done automatically.<br> update_allowed: Sets tag 'Update allowed' to yes or no to specify if this VM should currently receive updates.</pre> | <pre>object({<br> hostname = string<br> size = string<br> location = string<br> os_sku = string<br> os_offer = string<br> os_version = string<br> os_publisher = string<br> os_disk_caching = optional(string, "ReadWrite")<br> os_disk_size_gb = optional(number)<br> os_disk_storage_type = optional(string, "Premium_LRS")<br> os_disk_write_accelerator_enabled = optional(bool, false)<br> zone = optional(number)<br> availability_set_id = optional(string)<br> proximity_placement_group_id = optional(string)<br> severity_group = string<br> update_allowed = optional(bool, true)<br> })</pre> | n/a | yes |
| <a name="input_virtual_machine_config"></a> [virtual\_machine\_config](#input\_virtual\_machine\_config) | <pre>hostname: Name of system hostname.<br> size: The size of the vm. Possible values can be seen here: https://learn.microsoft.com/en-us/azure/virtual-machines/sizes<br> location: The location of the virtual machine.<br> os_sku: (Required) The os that will be running on the vm.<br> os_offer: (Required) Specifies the offer of the image used to create the virtual machines. Changing this forces a new resource to be created.<br> os_version: (Required) Optionally specify an os version for the chosen sku.<br> 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.<br> os_disk_caching: Optionally change the caching option of the os disk. Defaults to ReadWrite.<br> os_disk_size_gb: Optionally change the size of the os disk. Defaults to be specified by image.<br> os_disk_storage_type: Optionally change the os_disk_storage_type. Defaults to StandardSSD_LRS.<br> zone: Optionally specify an availibility zone for the vm. Values 1, 2 or 3.<br> availability_set_id: Optionally specify an availibility set for the vm. Not compatible with zone.<br> os_disk_write_accelerator_enabled: Optionally activate write accelaration for the os disk. Can only<br> be activated on Premium disks and caching deactivated. Defaults to false.<br> proximity_placement_group_id: (Optional) The ID of the Proximity Placement Group which the Virtual Machine should be assigned to.<br> severity_group: (Required) Sets tag 'Severity Group Monthly' to a specific time and date when an update will be done automatically.<br> update_allowed: Sets tag 'Update allowed' to yes or no to specify if this VM should currently receive updates.<br> enable_plan: When using marketplace images, sending plan information might be required. Also accepts the terms of the marketplace product.</pre> | <pre>object({<br> hostname = string<br> size = string<br> location = string<br> os_sku = string<br> os_offer = string<br> os_version = string<br> os_publisher = string<br> os_disk_caching = optional(string, "ReadWrite")<br> os_disk_size_gb = optional(number)<br> os_disk_storage_type = optional(string, "Premium_LRS")<br> os_disk_write_accelerator_enabled = optional(bool, false)<br> zone = optional(number)<br> availability_set_id = optional(string)<br> proximity_placement_group_id = optional(string)<br> severity_group = string<br> update_allowed = optional(bool, true)<br> enable_plan = optional(bool, false)<br> })</pre> | n/a | yes |
| <a name="input_additional_network_interface_ids"></a> [additional\_network\_interface\_ids](#input\_additional\_network\_interface\_ids) | List of ids for additional azurerm\_network\_interface. | `list(string)` | `[]` | no |
| <a name="input_admin_username"></a> [admin\_username](#input\_admin\_username) | Optionally choose the admin\_username of the vm. Defaults to loc\_sysadmin. | `string` | `"loc_sysadmin"` | no |
| <a name="input_data_disks"></a> [data\_disks](#input\_data\_disks) | <pre><logical name of the data disk> = {<br> lun: Number of the lun.<br> disk_size_gb: The size of the data disk.<br> storage_account_type: Optionally change the storage_account_type. Defaults to StandardSSD_LRS.<br> caching: Optionally activate disk caching. Defaults to None.<br> create_option: Optionally change the create option. Defaults to Empty disk.<br> source_resource_id: (Optional) The ID of an existing Managed Disk or Snapshot to copy when create_option is Copy or<br> the recovery point to restore when create_option is Restore. Changing this forces a new resource to be created.<br> write_accelerator_enabled: Optionally activate write accelaration for the data disk. Can only<br> be activated on Premium disks and caching deactivated. Defaults to false.<br> on_demand_bursting_enabled: Optionally activate disk bursting. Only for Premium disk. Default false.<br> }</pre> | <pre>map(object({<br> lun = number<br> disk_size_gb = number<br> caching = optional(string, "ReadWrite")<br> create_option = optional(string, "Empty")<br> source_resource_id = optional(string)<br> storage_account_type = optional(string, "Premium_LRS")<br> write_accelerator_enabled = optional(bool, false)<br> on_demand_bursting_enabled = optional(bool, false)<br> }))</pre> | `{}` | no |
Expand All @@ -93,6 +93,7 @@ resource "azurerm_subnet" "this" {
|------|-------|
| [azurerm_linux_virtual_machine](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine) | 1 |
| [azurerm_managed_disk](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/managed_disk) | 1 |
| [azurerm_marketplace_agreement](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/marketplace_agreement) | 1 |
| [azurerm_network_interface](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface) | 1 |
| [azurerm_network_interface_security_group_association](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface_security_group_association) | 1 |
| [azurerm_public_ip](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip) | 1 |
Expand All @@ -118,6 +119,7 @@ No modules.
| Name | Type |
|------|------|
| [azurerm_linux_virtual_machine.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine) | resource |
| [azurerm_marketplace_agreement.default](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/marketplace_agreement) | resource |
| [azurerm_network_interface.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface) | resource |
| [azurerm_network_interface_security_group_association.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface_security_group_association) | resource |
| [azurerm_public_ip.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip) | resource |
Expand Down
45 changes: 45 additions & 0 deletions examples/marketplace_image/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
provider "azurerm" {
features {}
}

module "virtual_machine" {
source = "../.."

virtual_machine_config = {
hostname = "CUSTAPP001"
location = azurerm_resource_group.this.location
size = "Standard_B1ms"
os_sku = "smvm12"
os_offer = "seppmailvirtualmachine"
os_version = "12.0.5"
os_publisher = "seppmailag"
severity_group = "01-second-monday-0300-XCSUFEDTG-reboot"
enable_plan = true
}
admin_username = "local_admin"
admin_credential = {
admin_password = "H3ll0W0rld!"
}

resource_group_name = azurerm_resource_group.this.name
subnet = azurerm_subnet.this
}

resource "azurerm_resource_group" "this" {
name = "rg-TestLinuxMarketplace-tst-01"
location = "westeurope"
}

resource "azurerm_virtual_network" "this" {
name = "vnet-10-0-0-0-24-${azurerm_resource_group.this.location}"
address_space = ["10.0.0.0/24"]
location = azurerm_resource_group.this.location
resource_group_name = azurerm_resource_group.this.name
}

resource "azurerm_subnet" "this" {
name = "snet-10-0-0-0-24-Test"
resource_group_name = azurerm_resource_group.this.name
virtual_network_name = azurerm_virtual_network.this.name
address_prefixes = ["10.0.0.0/24"]
}
18 changes: 18 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ check "no_nsg_on_nic" {
}
}

resource "azurerm_marketplace_agreement" "default" {
count = var.virtual_machine_config.enable_plan == true ? 1 : 0

publisher = var.virtual_machine_config.os_publisher
offer = var.virtual_machine_config.os_offer
plan = var.virtual_machine_config.os_sku
}

resource "azurerm_linux_virtual_machine" "this" {
name = local.virtual_machine.name
computer_name = var.virtual_machine_config.hostname
Expand Down Expand Up @@ -71,6 +79,16 @@ resource "azurerm_linux_virtual_machine" "this" {
version = var.virtual_machine_config.os_version
}

dynamic "plan" {
for_each = var.virtual_machine_config.enable_plan ? ["one"] : []

content {
name = var.virtual_machine_config.os_sku
product = var.virtual_machine_config.os_offer
publisher = var.virtual_machine_config.os_publisher
}
}

proximity_placement_group_id = var.virtual_machine_config.proximity_placement_group_id
network_interface_ids = concat([azurerm_network_interface.this.id], var.additional_network_interface_ids)
availability_set_id = var.virtual_machine_config.availability_set_id
Expand Down
2 changes: 2 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ variable "virtual_machine_config" {
proximity_placement_group_id = optional(string)
severity_group = string
update_allowed = optional(bool, true)
enable_plan = optional(bool, false)
})
validation {
condition = contains(["None", "ReadOnly", "ReadWrite"], var.virtual_machine_config.os_disk_caching)
Expand Down Expand Up @@ -142,6 +143,7 @@ variable "virtual_machine_config" {
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.
enable_plan: When using marketplace images, sending plan information might be required. Also accepts the terms of the marketplace product.
```
DOC
}
Expand Down
Loading