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

MIT License
4 stars 10 forks source link

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

Closed MikeDembek closed 2 months ago

MikeDembek commented 4 months 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 3 months ago

Thanks @MikeDembek I will fix this.

terrymandin commented 2 months 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

terrymandin commented 2 months ago

Fixed validation in v0.3.0. The underlying provider still fails if an image and os provider is not provided. I am closing the issue as there is nothing more I can do in the AVM.

Please create a issue in the underlying VMSS Flex provider if required. I'd create the issue myself, but I don't know the business justification for creating VMSS without an image or os profile. It is probably best that you interact with them directly instead of me getting in the middle.

Note that you can create a VMSS with 0 instances, but you still need to provide an image and os profile.

MikeDembek commented 2 months ago

Thank you - for me this was about consistency between documentation and usage of the module in practice more than a specific business justification (I was doing a PoC with a minimum viable config, not something I'd do outside early-phase testing). I appreciate the follow-up.