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.6k stars 4.65k forks source link

Normalise servicebus_subscription lock_duration values before building diff #25481

Open EpicWink opened 7 months ago

EpicWink commented 7 months ago

Is there an existing issue for this?

Community Note

Terraform Version

1.7.5

AzureRM Provider Version

3.97.1

Affected Resource(s)/Data Source(s)

azurerm_servicebus_subscription

Terraform Configuration Files

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 3.0"
    }
  }

  required_version = "~> 1.0"
}

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = "example"
  location = "Australia East"
}

resource "azurerm_servicebus_namespace" "example" {
  name                = "example"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  sku                 = "Standard"
}

resource "azurerm_servicebus_topic" "example" {
  name         = "example"
  namespace_id = azurerm_servicebus_namespace.example.id
}

resource "azurerm_servicebus_subscription" "example" {
  name               = "example"
  topic_id           = azurerm_servicebus_topic.example.id
  lock_duration      = "P0DT0H3M0S"
  max_delivery_count = 1
}

Note: namespace name is globally unique: pick a random name

Debug Output/Panic Output

not important

Expected Behaviour

No changes. Your infrastructure matches the configuration.

Actual Behaviour

Terraform will perform the following actions:

  # azurerm_servicebus_subscription.example will be updated in-place
  ~ resource "azurerm_servicebus_subscription" "example" {
        id                                        = "/subscriptions/.../resourceGroups/example/providers/Microsoft.ServiceBus/namespaces/example/topics/example/subscriptions/example"
      ~ lock_duration                             = "PT3M" -> "P0DT0H3M0S"
        name                                      = "example"
        # (10 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

The before and after values of lock_duration are equivalent (see ISO 8601 durations on Wikipedia), and should not result in an attempt to modify.

Steps to Reproduce

  1. terraform apply
  2. terraform plan

Important Factoids

No response

References

No response

xiaxyi commented 7 months ago

Thanks @EpicWink for raising this issue, are you suggesting that the change P0DT0H3M0S is not being saved to state file, thus terraform detected a diff during the second plan?

tombuildsstuff commented 7 months ago

@xiaxyi these values are being written to state - however @EpicWink is suggesting that the values PT3M and P0DT0H3M0S are semantically the same value (e.g. 3 months) just written in a different manner - and thus the Provider shouldn't be detecting a difference between the two (e.g. adding a DiffSuppressFunc to detect this). From memory there's some normalization happening on the API side here, which is likely where this diff is occurring.

EpicWink commented 7 months ago

@xiaxyi what @tombuildsstuff said is correct. I'll update the issue description to make that more clear

xiaxyi commented 7 months ago

@tombuildsstuff Ah Thanks for the explanation, shall we add the suppressDiff func for that or would you like me to reach out to the api team for more information?

tombuildsstuff commented 7 months ago

@EpicWink 👍 thanks for confirming

@xiaxyi a DiffSuppressFunc seems reasonable on our side to handle this, since it'll be useful in a few places