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

subscription_id "expected 2 segments within the Resource ID but got 1" #21628

Open pinlast opened 1 year ago

pinlast commented 1 year ago

Is there an existing issue for this?

Community Note

Terraform Version

1.4.6

AzureRM Provider Version

3.54.0

Affected Resource(s)/Data Source(s)

azurerm_subscription_cost_management_export

Terraform Configuration Files

resource "azurerm_subscription_cost_management_export" "cost-cur" {
  name                         = "cost-cur"
  subscription_id              = var.subscription_id
  recurrence_type              = "Daily"
  recurrence_period_start_date = "2020-08-18T00:00:00Z"
  recurrence_period_end_date   = "2030-08-18T00:00:00Z"

  export_data_storage_location {
    container_id     = azurerm_storage_container.cost_container.resource_manager_id
    root_folder_path = "/cost"
  }

  export_data_options {
    type       = "AmortizedCost"
    time_frame = "WeekToDate"
  }
}

Debug Output/Panic Output

╷
│ Error: parsing "18f9f461-76ca-4d0d-997c-7300f94998e4": expected 2 segments within the Resource ID but got 1 for "18f9f461-76ca-4d0d-997c-7300f94998e4"
│ 
│   with azurerm_subscription_cost_management_export.cost-cur,
│   on main.tf line 22, in resource "azurerm_subscription_cost_management_export" "cost-cur":
│   22:   subscription_id              = var.subscription_id
│

Expected Behaviour

resource azurerm_subscription_cost_management_export should be created

Actual Behaviour

azurerm_subscription_cost_management_export resource can't be created because subscription id is expected to have 2 segments

Steps to Reproduce

No response

Important Factoids

No response

References

There is same issue, but fix doesn't work for me https://github.com/hashicorp/terraform-provider-azurerm/issues/21241

ms-zhenhua commented 1 year ago

Hi @pinlast, thank you for reaching out.
Could you kindly check the value of subscription_id in azurerm_subscription_cost_management_export? The valid format of subscription_id should be /subscriptions/00000000-0000-0000-0000-000000000000.

L1ghtman2k commented 1 year ago

@ms-zhenhua

│ Error: parsing "3003b46d-a543-438d-9bd8-fc8f3ad03bd2": parsing the Subscription ID: the number of segments didn't match
│ 
│ Expected a Subscription ID that matched (containing 2 segments):
│ 
│ > /subscriptions/12345678-1234-9876-4563-123456789012
│ 
│ However this value was provided (which was parsed into 0 segments):
│ 
│ > 3003b46d-a543-438d-9bd8-fc8f3ad03bd2
resource "azurerm_subscription" "sub" {
  subscription_name = var.subscription_name
  billing_scope_id  = var.billing_scope_id
}

resource "azurerm_subscription_policy_assignment" "namespace_tag" {
  name                 = "namespace_tag"
  subscription_id      = azurerm_subscription.sub.subscription_id
  policy_definition_id = data.azurerm_policy_definition.add_or_replace_tag_on_subscription.id

  parameters = jsonencode({
    "tagName" : {
      "value" : "NameSpace",
    }
    "tagValue" : {
      "value" : var.finops_tags.NameSpace,
    }
  })

  description = "Set NameSpace tag for subscription"
}
L1ghtman2k commented 1 year ago

related to this bug: https://github.com/hashicorp/terraform-provider-azurerm/issues/13422