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.64k forks source link

azurerm_resource_group tag is empty even though it's populated. #26340

Closed ghost closed 1 month ago

ghost commented 4 months ago

Is there an existing issue for this?

Community Note

Terraform Version

1.8.5

AzureRM Provider Version

3.107.0

Affected Resource(s)/Data Source(s)

azurerm_resource_group

Terraform Configuration Files

Within this module.

  ....
  tags = var.storage_account_tags == {} ? data.azurerm_resource_group.resource_group.tags : var.storage_account_tags
}

# THIS IS NEWLY CREATED, it won't work without the depends on clause.
data "azurerm_resource_group" "resource_group" {
  name = var.resource_group.name
}

data.azurerm_resource_group.resource_group.tags shows up as empty map even though it's populated in the console.


### Debug Output/Panic Output

```shell
~ resource "azurerm_storage_account" "storage_account" {
        id                                = "/subscriptions/d5ad7b6a-8387-4840-a977-19a461568dee/resourceGroups/ctfr-poc-ultimate-gar/providers/Microsoft.Storage/storageAccounts/splk3blihzcx5mu237edqaxa"
        name                              = "splk3blihzcx5mu237edqaxa"
      ~ tags                              = {
          - "Area"             = "core-services" -> null
          - "Cluster"          = "cyclops-phx30-play-lovelace.splunk8s.io" -> null
          - "Customer_Type_V2" = "Dev" -> null
          - "Environment"      = "dev.splunk8s.io" -> null
          - "Environment_V2"   = "Dev" -> null
          - "Owner"            = "yuhsuanh@splunk.com sg-pfm-d4s" -> null
          - "Pop"              = "phx30" -> null
          - "Product_V2"       = "No Product" -> null
          - "Region"           = "phx30" -> null
          - "Scope"            = "cluster" -> null
          - "Service"          = "d4s-testing" -> null
          - "Service_V2"       = "d4s-testing" -> null
          - "Slack"            = "d4s" -> null
          - "TagStandard"      = "V2" -> null
          - "Team"             = "d4s" -> null
        }
        # (39 unchanged attributes hidden)
        # (4 unchanged blocks hidden)
    }


### Expected Behaviour

_No response_

### Actual Behaviour

_No response_

### Steps to Reproduce

terraform apply.

### Important Factoids

_No response_

### References

_No response_
AlexPykavy commented 4 months ago

Hi @mnavaltaequitydine ,

I was able to reproduce the issue. For some reason var.storage_account_tags == {} returns false even so var.storage_account_tags is empty 🤔

As a hotfix, you can use length(...) function instead, like:

tags = length(var.storage_account_tags) == 0 ? data.azurerm_resource_group.resource_group.tags : var.storage_account_tags
ghost commented 4 months ago

@AlexPykavy - sorry for the confusion, but we can actually treat it as is like:

Within this module.

  ....
  tags = data.azurerm_resource_group.resource_group.tags
}

Will yield either empty if the resource_group is being created at the same time within the apply, or actually not empty if the resource_group is created prior to this the current apply.

AlexPykavy commented 4 months ago

Could you please share the full definition of your azurerm_storage_account from the module?

magodo commented 4 months ago

@mnavaltaequitydine If the resource group is created along with the module that referencing the tags, then the plan will indicate the tags to be known after apply, e.g.:

      + tags       = (known after apply)
rcskosir commented 1 month ago

Thank you for taking the time to raise this! I am going to close this with @magodo‘s response as an answer. If you have future questions, I suggest using the Community Resources, such as the Azure Provider forum.

github-actions[bot] commented 2 days ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.