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

empty string passed to location root level property #476

Closed
4c74356b41 opened this issue Apr 25, 2024 · 3 comments
Closed

empty string passed to location root level property #476

4c74356b41 opened this issue Apr 25, 2024 · 3 comments
Labels

Comments

@4c74356b41
Copy link

4c74356b41 commented Apr 25, 2024

AzApi 1.13.0, terraform 1.5.3

resource config:

resource "azapi_resource" "maint_link" {
  for_each  = local.vms
  type      = "Microsoft.Maintenance/configurationAssignments@2021-09-01-preview"
  name      = "${each.key}maintlink"
  location  = each.value.location
  parent_id = azurerm_linux_virtual_machine.bastion_vm[each.key].id
  body      = jsonencode({
    properties = {
      maintenanceConfigurationId = lower(data.azurerm_maintenance_configuration.existing[each.key].id)
      resourceId                 = lower(azurerm_linux_virtual_machine.bastion_vm[each.key].id)
    }
  })
  lifecycle {
    ignore_changes = [
      location
    ]
  }

the body passed to the api:

{
    "location": "",
    "properties": {
        "maintenanceConfigurationId": "/subscriptions/zzz/resourcegroups/yyy/providers/microsoft.maintenance/maintenanceconfigurations/xxx",
        "resourceId": "/subscriptions/zzz/resourcegroups/yyy/providers/microsoft.compute/virtualmachines/xxx"
    },
    "tags": {}
}

which fails. I moved my maintenance config to "native" azurerm resource to fix the issue. the same was working for over a year

@ms-henglu
Copy link
Collaborator

Hi @4c74356b41 ,

Thank you for taking time to report this issue!

There's an issue in the upstream Microsoft.Maintenance/configurationAssignments API, the location field is not returned in GET response:

GET /subscriptions/000/resourceGroups/henglu425main/providers/Microsoft.Compute/virtualMachines/henglu425main/providers/Microsoft.Maintenance/configurationAssign
ments/henglu425main

{
    "id": "/subscriptions/000/resourceGroups/henglu425main/providers/Microsoft.Compute/virtualMachines/henglu425main/providers/Microsoft.Maintenance/configurationAssign
ments/henglu425main",
    "name": "henglu425main",
    "properties": {
        "maintenanceConfigurationId": "/subscriptions/000/resourcegroups/henglu425main/providers/microsoft.maintenance/maintenanceconfigurations/henglu425main",
        "resourceId": "/subscriptions/000/resourcegroups/henglu425main/providers/microsoft.compute/virtualmachines/henglu425main"
    },
    "type": "Microsoft.Maintenance/configurationAssignments"
}

So if lifecycle.ignore_changes = ["location"] is applied, the config will be overwritten to "".

Here's an example of how to bypass this API issue:

resource "azapi_resource" "configurationAssignment" {
  type      = "Microsoft.Maintenance/configurationAssignments@2022-07-01-preview"
  parent_id = azapi_resource.virtualMachine.id
  name      = var.resource_name
  body = jsonencode({
    location = "westeurope" // we set location in the body
    properties = {
      maintenanceConfigurationId = azapi_resource.maintenanceConfiguration.id
      resourceId                 = azapi_resource.virtualMachine.id
    }
  })
  ignore_casing             = true // to ignore the casing differences for maintenanceConfigurationId and resourceId
  ignore_missing_property = true// to ignore the difference caused by "location" not returned
}

More details please check this complete config: https://github.com/Azure/terraform-provider-azapi/blob/v1.12.1/examples/Microsoft.Maintenance_configurationAssignments%402022-07-01-preview/main.tf

@ms-henglu ms-henglu added upstream-api example Example request labels Apr 25, 2024
@4c74356b41
Copy link
Author

okay, thanks, not sure if you want to close this or keep it, but we moved this resource to azurerm, so its your call.

@ms-henglu
Copy link
Collaborator

I've created this issue to track the API bug: Azure/azure-rest-api-specs#28880

I'll close this issue but feel free to reopen it if there's any question. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants