You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
azurerm_management_group_subscription_association throws error '"subscription_id" expected to be valid subscription ID' when referencing an azurerm_subscription resource
#13422
Open
kensykora opened this issue
Sep 20, 2021
· 2 comments
│ Error: "subscription_id" expected to be valid subscription ID, got "e42c1859-1c46-4c0b-a52c-36d09f272ac2"
│
│ with azurerm_management_group_subscription_association.dev,
│ on subscriptions.tf line 19, in resource "azurerm_management_group_subscription_association" "dev":
│ 19: subscription_id = azurerm_subscription.dev.subscription_id
│
╵
Additionally, trying to use the .id property instead of .subscription_id gives a similar error:
Error: "subscription_id" expected to be valid subscription ID, got "/providers/Microsoft.Subscription/aliases/dev"
Description / Feedback
Scenario: Subscriptions existed pre-terraform, and the subscriptions were brought into terraform using the methodology described under Adding an alias to an existing subscription
The azurerm_management_group_subscription_association resource expects the subscription_id to be in the format /subscriptions/{subscriptionid} and there isn't a direct attribute output from the azurerm_subscription resource that matches this.
This is further confused by the terraform example in the documentation, which using the data provider for azurerm_subscription which shows this same approach, just using a data.azurerm_subscription block instead of a resource azurerm_subscription block.
I would expect the data block to behave similarly to the resource block. I would also expect that the azurerm_management_group_subscription_association resource would accept subscription_id in a simple uuid format (typical convention used in many other parts of this resource provider) so it can be directly referenced by a managed subscription in terraform.
Workaround
Format the subscription_id directly like the provider expects:
However, when the pipeline failed for other resources, a different error is raised for the azurerm_management_group resource itself when the job is retried: Error: unable to create Management Group "test_mg": managementgroups.Client#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: Code="BadRequest" Message="Circular dependency detected"
Community Note
Terraform (and AzureRM Provider) Version
Terraform Configuration Files
Trying to apply the above produces the error:
Additionally, trying to use the
.id
property instead of.subscription_id
gives a similar error:Description / Feedback
Scenario: Subscriptions existed pre-terraform, and the subscriptions were brought into terraform using the methodology described under Adding an alias to an existing subscription
The
azurerm_management_group_subscription_association
resource expects thesubscription_id
to be in the format/subscriptions/{subscriptionid}
and there isn't a direct attribute output from theazurerm_subscription
resource that matches this.This is further confused by the terraform example in the documentation, which using the data provider for
azurerm_subscription
which shows this same approach, just using adata.azurerm_subscription
block instead of a resourceazurerm_subscription
block.I would expect the data block to behave similarly to the resource block. I would also expect that the
azurerm_management_group_subscription_association
resource would acceptsubscription_id
in a simple uuid format (typical convention used in many other parts of this resource provider) so it can be directly referenced by a managed subscription in terraform.Workaround
Format the
subscription_id
directly like the provider expects:The text was updated successfully, but these errors were encountered: