Azure / terraform-azurerm-avm-res-compute-virtualmachinescaleset

MIT License
2 stars 6 forks source link

[AVM Module Issue]: os_profile fails validation checks if left to default (null) #70

Open MikeDembek opened 1 month ago

MikeDembek commented 1 month ago

Check for previous/existing GitHub issues

Issue Type?

Bug

(Optional) Module Version

0.2.0

(Optional) Correlation Id

No response

Description

Hello, I'm seeing validation errors if I don't specify an os_profile, which is listed as an optional parameter in both the AVM and the underlying provider documentation. Here's an example error:

Error: Attempt to get attribute from null value

  on .terraform/modules/vmss_example/variables.tf line 600, in variable "os_profile":
 600:     condition     = var.os_profile.linux_configuration == null ? true : var.os_profile.linux_configuration.patch_mode == null ? true : contains(["ImageDefault", "AutomaticByPlatform"], var.os_profile.linux_configuration.patch_mode)
    ├────────────────
    │ var.os_profile is null

This value is null, so it does not have any attributes.

Error: Attempt to get attribute from null value

  on .terraform/modules/vmss_example/variables.tf line 604, in variable "os_profile":
 604:     condition     = var.os_profile.linux_configuration == null ? true : var.os_profile.linux_configuration.patch_assessment_mode == null ? true : contains(["AutomaticByPlatform", "ImageDefault"], var.os_profile.linux_configuration.patch_assessment_mode)
    ├────────────────
    │ var.os_profile is null

This value is null, so it does not have any attributes.

Error: Attempt to get attribute from null value

  on .terraform/modules/vmss_example/variables.tf line 608, in variable "os_profile":
 608:     condition     = var.os_profile.windows_configuration == null ? true : var.os_profile.windows_configuration.patch_mode == null ? true : contains(["Manual", "AutomaticByOS", "AutomaticByPlatform"], var.os_profile.windows_configuration.patch_mode)
    ├────────────────
    │ var.os_profile is null

This value is null, so it does not have any attributes.

Error: Attempt to get attribute from null value

  on .terraform/modules/vmss_example/variables.tf line 612, in variable "os_profile":
 612:     condition     = var.os_profile.windows_configuration == null ? true : var.os_profile.windows_configuration.patch_assessment_mode == null ? true : contains(["AutomaticByPlatform", "ImageDefault"], var.os_profile.windows_configuration.patch_assessment_mode)
    ├────────────────
    │ var.os_profile is null

This value is null, so it does not have any attributes.

Error: Attempt to get attribute from null value

  on .terraform/modules/vmss_example/variables.tf line 616, in variable "os_profile":
 616:     condition = var.os_profile.windows_configuration == null ? true : var.os_profile.windows_configuration.winrm_listener == null ? true : alltrue([
    ├────────────────
    │ var.os_profile is null

This value is null, so it does not have any attributes.

Here's a basic example of what I'm using to reproduce this:

module "vmss_example" {
  source  = "Azure/avm-res-compute-virtualmachinescaleset/azurerm"
  version = "0.2.0"

  location = "somelocation"
  resource_group_name = "somerg"
  admin_password = "somepass"
  name = "somevmssname"
  platform_fault_domain_count = 1

  extension = []

  network_interface = [{
    name = "VMSS-NIC"
    ip_configuration = [{
      name      = "VMSS-IPConfig"
      subnet_id = module.vnet[0].subnets.resource_id
    }]
  }]

  admin_ssh_keys = []

  extension_protected_setting = {}
  user_data_base64 = ""
}

In the AVM's variables.tf we see os_profile defaults to null, but that appears to fail the validations starting at line 599. Could this be updated to either result in a pass on a default/null entry?

Thanks!

terrymandin commented 4 weeks ago

Thanks @MikeDembek I will fix this.

terrymandin commented 1 week ago

@Kanik09, interested in your thoughts on this issue. Should we be able to create VMSS Flex instances without a source image or os profile? These are optional parameters in the azurerm_orchestrated_virtual_machine_scale_set provider and also appear to be optional in the ARM API and also the CLI.

If I remove these sections, I get the following error message from the underlying Terraform provider:

Error: creating Orchestrated Virtual Machine Scale Set (Subscription: "1f16fd54-0921-4c3d-81b1-edde291f16df"
│ Resource Group Name: "rg-zcul"
│ Virtual Machine Scale Set Name: "vmss-zcul"): performing CreateOrUpdate: unexpected status 400 (400 Bad Request) with error: InvalidParameter: Required parameter 'osProfile' is missing (null).
│
│   with module.terraform_azurerm_avm_res_compute_virtualmachinescaleset.azurerm_orchestrated_virtual_machine_scale_set.virtual_machine_scale_set,
│   on ..\..\main.tf line 1, in resource "azurerm_orchestrated_virtual_machine_scale_set" "virtual_machine_scale_set":
│    1: resource "azurerm_orchestrated_virtual_machine_scale_set" "virtual_machine_scale_set" {

@marcelkmfst