Skip to content

[AVM Module Issue]: serverFarmId casing mismatch causes perpetual diff on every terraform plan #281

@davidroler

Description

@davidroler

Check for previous/existing GitHub issues

  • I have checked for previous/existing GitHub issues

Issue Type?

Bug

(Optional) Module Version

0.21.8

(Optional) Correlation Id

No response

Description

Since the module was rewritten to use azapi in v0.21.0, every terraform plan shows a spurious in-place update for azapi_resource.this due to a serverFarmId casing mismatch — even when no changes
have been made.

Steps to Reproduce

  1. Use this module with an azurerm_service_plan resource as the service_plan_resource_id input.
  2. Run terraform apply successfully.
  3. Run terraform plan again — it immediately shows a diff.

Plan Output

~ resource "azapi_resource" "this" {
~ body = {
~ properties = {
~ serverFarmId = "/subscriptions/.../providers/Microsoft.Web/serverfarms/my-plan" -> "/subscriptions/.../providers/Microsoft.Web/serverFarms/my-plan"

The only difference is the capitalization of serverFarms (F vs f).

Root Cause

In locals.body.tf, serverFarmId is set directly from the input variable:

serverFarmId = var.service_plan_resource_id

The azurerm_service_plan resource returns an ID with serverFarms (capital F), which gets passed into the azapi_resource body. However, the Azure ARM API returns the serverFarmId property with
serverfarms (lowercase) in subsequent GET responses. The azapi provider performs a case-sensitive comparison between the desired body and the API response, resulting in a perpetual diff.

Suggested Fix

Normalize the casing in locals.body.tf:

serverFarmId = replace(var.service_plan_resource_id, "/serverFarms/", "/serverfarms/")

Or more robustly using a regex to handle any casing:

serverFarmId = replace(var.service_plan_resource_id, "/(?i)serverfarms/", "/serverfarms/")

Environment

  • Module version: v0.21.8 (also confirmed present in v0.22.0)
  • Provider: Azure/azapi
  • Introduced in: v0.21.0 (PR feat: convert to azapi #258, migration from azurerm to azapi)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions