hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.59k stars 4.63k forks source link

Cannot assign "maintenance configuration" to "Scaleset instance" #18418

Open Sanket-Kaware opened 2 years ago

Sanket-Kaware commented 2 years ago

Is there an existing issue for this?

Community Note

Description

I have nodes(scaleset instance) in one of my Kubernetes Services node pools and trying to assign the maintenance configuration to it.

I have created a maintenance configuration using resource "azurerm_maintenance_configuration" but didn't find a solution for assigning the configuration to the "Scaleset instance".

I am looking for an option to add "Scaleset instance" via "add machine" in "maintenance configuration". Does terraform/azure have this feature? Able to do this in the portal but looking for terraform resource to add it.

New or Affected Resource(s)/Data Source(s)

azurerm_maintenance_configuration, azurerm_maintenance_assignment_virtual_machine_scale_set

Potential Terraform Configuration

No response

References

No response

ljluestc commented 1 week ago

provider "azurerm" {
  features {}
}

# Define your resource group
resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "East US"
}

# Define the virtual machine scale set
resource "azurerm_virtual_machine_scale_set" "example" {
  name                = "example-vmss"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  sku {
    name     = "Standard_DS1_v2"
    tier     = "Standard"
    capacity = 2
  }
  upgrade_policy {
    mode = "Automatic"
  }

  # Define the VM scale set instances
  identity {
    type = "SystemAssigned"
  }

  network_profile {
    name    = "example-network-profile"
    primary = true

    ip_configuration {
      name      = "example-ip-config"
      primary   = true
      subnet_id = "<YOUR_SUBNET_ID>"  # Replace with your actual subnet ID
    }
  }

  os_profile {
    computer_name_prefix = "vmss-example"
    admin_username       = "adminuser"
    admin_password       = "P@ssword1234!"
  }

  storage_profile {
    image_reference {
      publisher = "MicrosoftWindowsServer"
      offer     = "WindowsServer"
      sku       = "2019-Datacenter"
      version   = "latest"
    }

    os_disk {
      caching              = "ReadWrite"
      managed_disk_type    = "StandardSSD_LRS"
    }
  }
}

# Create the maintenance configuration
resource "azurerm_maintenance_configuration" "example" {
  name                = "example-maintenance-config"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  description         = "Maintenance configuration for VMSS instances"

  # Define the maintenance window
  maintenance_window {
    start_time = "2023-10-01T00:00:00Z"  # Start time in UTC
    end_time   = "2023-10-01T02:00:00Z"  # End time in UTC
    frequency  = "Weekly"
    day_of_week = "Sunday"
  }

  # Maintenance configuration settings
  maintenance_mode = "On"
}

# Assign the maintenance configuration to the VM scale set
resource "azurerm_maintenance_assignment_virtual_machine_scale_set" "example" {
  name                           = "example-maintenance-assignment"
  resource_group_name            = azurerm_resource_group.example.name
  maintenance_configuration_id    = azurerm_maintenance_configuration.example.id
  virtual_machine_scale_set_id    = azurerm_virtual_machine_scale_set.example.id
}