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_storage_sync_group - SyncGroup ID parsed into 0 segments #25151

Open johnjjimenez opened 8 months ago

johnjjimenez commented 8 months ago

Is there an existing issue for this?

Community Note

Terraform Version

1.7.3

AzureRM Provider Version

3.94.0

Affected Resource(s)/Data Source(s)

azurerm_storage_sync_group

Terraform Configuration Files

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

resource "azurerm_storage_sync" "this" {
  name                = var.name
  location            = var.location
  resource_group_name = var.resource_group_name

  incoming_traffic_policy = var.incoming_traffic_policy

  timeouts {
    create = "30m"
  }
}

resource "azurerm_storage_sync_group" "this" {
  for_each = { for n in var.storage_sync_group_names : n => n }

  name            = each.value
  storage_sync_id = azurerm_storage_sync.this.id
}

variable "name" {
  description = "(Required) The name which should be used for this Storage Sync."
  type        = string
}

variable "location" {
  description = "(Required) The Azure Region where the Storage Sync should exist."
  type        = string
}

variable "resource_group_name" {
  description = " (Required) The name of the Resource Group where the Storage Sync should exist."
  type        = string
}

variable "tags" {
  description = "(Optional) Tags assigned to all Storage Sync related resources"
  type        = map(string)
  default     = {}
}

variable "incoming_traffic_policy" {
  description = "(Optional) Incoming traffic policy. Possible values are AllowAllTraffic and AllowVirtualNetworksOnly."
  type        = string
  default     = null
}

variable "storage_sync_group_names" {
  description = "A list of storage sync group names."
  type        = list(string)
  default     = []
}

Debug Output/Panic Output

Error: parsing "/subscriptions/XXXX/resourceGroups/XXXX/providers%2FMicrosoft.StorageSync/storageSyncServices/XXXX/syncGroups/XXXX": parsing the SyncGroup ID: the number of segments didn't match
│
│ Expected a SyncGroup ID that matched (containing 10 segments):
│
│ > /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StorageSync/storageSyncServices/storageSyncServiceValue/syncGroups/syncGroupValue
│
│ However this value was provided (which was parsed into 0 segments):
│
│ > /subscriptions/XXXX/resourceGroups/XXXX/providers%2FMicrosoft.StorageSync/storageSyncServices/XXXX/syncGroups/XXXX

Expected Behaviour

%2F should be decoded to a forward slash between segments 4 and 5.

Actual Behaviour

%2F is not decoded to a forward slash between segments 4 and 5.

I was initially using AzureRM Provider v3.55.0 and the SyncGroup ID has the encoded forward slash between segments 4 and 5 but does not throw an error.

image

I upgraded to 3.94.0 and started receiving this error message.

image

Steps to Reproduce

terraform plan terraform apply

Important Factoids

Azure Government

References

No response

neil-yechenwei commented 8 months ago

Thanks for raising this issue. Seems I can't repro it on my local. Could you double confirm if the steps are correct? Thanks.

Repro steps:

  1. Run tf apply to create the Storage Sync and the Storage Sync group using v3.55.0
  2. Upgrade TF azurerm provider to v3.94.0
  3. Run tf plan/tf apply against these two resources

tf config:

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "test" {
  name     = "acctestRG-ss-test01"
  location = "westeurope"
}

resource "azurerm_storage_sync" "test" {
  name                    = "acctest-SS-test01"
  resource_group_name     = azurerm_resource_group.test.name
  location                = azurerm_resource_group.test.location
  incoming_traffic_policy = "AllowVirtualNetworksOnly"
}

resource "azurerm_storage_sync_group" "test" {
  name            = "acctest-StorageSyncGroup-test01"
  storage_sync_id = azurerm_storage_sync.test.id
}
johnjjimenez commented 3 months ago

Sorry. I forgot to provide the module block.

module "storage_sync" {
  source = "../../common-modules/az-storage-sync/"

  count = var.storage_sync_name != "" && var.storage_sync_name != null ? 1 : 0

  location                = var.location
  resource_group_name     = azurerm_resource_group.rg.name
  name                    = var.storage_sync_name
  incoming_traffic_policy = var.storage_sync_incoming_traffic_policy

  storage_sync_group_names = var.storage_sync_group_names

  private_endpoint_enabled           = var.storage_sync_private_endpoint_enabled
  private_endpoint_name              = var.storage_sync_private_endpoint_name
  private_endpoint_subresource_names = var.storage_sync_private_endpoint_subresource_names
  subnet_id                          = data.azurerm_subnet.this.id

  tags = merge(var.storage_sync_tags, var.tags)
}
johnjjimenez commented 3 weeks ago

This issue can be closed. I corrected the IDs in my state file to fix the issue.