Skip to content

Commit

Permalink
feat: improving support for marketplace images
Browse files Browse the repository at this point in the history
accept marketplace agreement and provide image plan by setting enable_plan to true
  • Loading branch information
QBY-MauriceBaerisch committed Sep 16, 2024
1 parent 92a6386 commit 91b94ed
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
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
19 changes: 18 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,20 @@ 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.source_image_reference.os_sku
}

resource "azurerm_linux_virtual_machine" "this" {
name = local.virtual_machine.name
computer_name = var.virtual_machine_config.hostname
location = var.virtual_machine_config.location
resource_group_name = var.resource_group_name
size = var.virtual_machine_config.size
plan = var.virtual_machine_config.os_plan
admin_username = var.admin_username
admin_password = var.admin_credential.admin_password
disable_password_authentication = var.admin_credential.admin_password == null
Expand Down Expand Up @@ -72,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.sku
product = var.virtual_machine_config.offer
publisher = var.virtual_machine_config.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
4 changes: 2 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ variable "virtual_machine_config" {
os_offer = string
os_version = string
os_publisher = string
os_plan = optional(string)
os_disk_caching = optional(string, "ReadWrite")
os_disk_size_gb = optional(number)
os_disk_storage_type = optional(string, "Premium_LRS")
Expand All @@ -100,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 @@ -133,7 +133,6 @@ variable "virtual_machine_config" {
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_plan: When using marketplace images passing this plan information is required. Otherwise optional.
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.
Expand All @@ -144,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

0 comments on commit 91b94ed

Please sign in to comment.