Skip to content

Commit 5d589f0

Browse files
authored
data.azurerm_api_management_subscription : fixed a failure that occurred when reading the built-in subscription (hashicorp#30610)
[BUG] * Data Source: `azurerm_api_management_subscription` - fix an issue that prevented referencing the built-in API Management Service's subscription
1 parent bc2ca51 commit 5d589f0

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

internal/services/apimanagement/api_management_subscription_data_source.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,15 @@ func (ApiManagementSubscriptionDataSource) Read() sdk.ResourceFunc {
135135

136136
if model := resp.Model; model != nil {
137137
if props := model.Properties; props != nil {
138-
// check if the subscription is for all apis or a specific product/ api
138+
// Check if the subscription is for all apis or a specific product/ api, excluding the built-in master subscription.
139+
// The scope of the built-in subscription is the API Management service itself (service ID).
139140
if props.Scope != "" && !strings.HasSuffix(props.Scope, "/apis") {
140-
// the scope is either a product or api id
141-
parseId, err := product.ParseProductIDInsensitively(props.Scope)
142-
if err == nil {
143-
state.ProductId = parseId.ID()
144-
} else {
145-
parsedApiId, err := api.ParseApiIDInsensitively(props.Scope)
146-
if err != nil {
147-
return fmt.Errorf("parsing scope into product/api id %q: %+v", props.Scope, err)
148-
}
149-
state.ApiId = parsedApiId.ID()
141+
// the scope is either a product, api id or service id
142+
if productId, err := product.ParseProductIDInsensitively(props.Scope); err == nil {
143+
state.ProductId = productId.ID()
144+
}
145+
if apiId, err := api.ParseApiIDInsensitively(props.Scope); err == nil {
146+
state.ApiId = apiId.ID()
150147
}
151148
}
152149
state.AllowTracing = pointer.From(props.AllowTracing)

0 commit comments

Comments
 (0)