Skip to content

Commit 99d49a7

Browse files
authored
Updated the code in the common_columns.go file to use the subscription_id returned by the List Subscriptions API Closes #947 (#948)
1 parent ae39bb0 commit 99d49a7

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

azure/common_columns.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package azure
33
import (
44
"context"
55

6+
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions"
67
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
78
"github.com/turbot/steampipe-plugin-sdk/v5/memoize"
89
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
@@ -54,7 +55,24 @@ func getSubscriptionIDUncached(ctx context.Context, d *plugin.QueryData, h *plug
5455
if err != nil {
5556
return nil, err
5657
}
57-
return session.SubscriptionID, nil
58+
59+
client := subscriptions.NewClientWithBaseURI(session.ResourceManagerEndpoint)
60+
client.Authorizer = session.Authorizer
61+
subscriptionID := session.SubscriptionID
62+
63+
// Always fetch the subscription ID via an API call instead of relying on session.SubscriptionID.
64+
// The session value cannot be guaranteed to be consistent, particularly because `subscription_id`
65+
// is used as a connection-level key qualifier. Subscription ID may differ in letter casing,
66+
// which causes mismatches during query evaluation. To ensure consistency, we normalize the process
67+
// by retrieving the subscription ID through the API and reusing that value across connection-level
68+
// key quals and table-level columns.
69+
op, err := client.Get(ctx, subscriptionID)
70+
if err != nil {
71+
plugin.Logger(ctx).Error("getSubscriptionIDUncached", "error", err)
72+
return nil, err
73+
}
74+
75+
return *op.SubscriptionID, nil
5876
}
5977

6078
// if the caching is required other than per connection, build a cache key for the call and use it in Memoize.

azure/plugin.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
9292
// ~2,000 GET/10s per vault
9393
{
9494
Name: "azure_key_vault_secret",
95-
FillRate: 40,
95+
FillRate: 40,
9696
BucketSize: 400,
9797
Scope: []string{"connection", "subscription", "vault"},
9898
Where: "service = 'Microsoft.KeyVault' and action = 'vaults/secrets/read'",
@@ -300,5 +300,11 @@ func getSubscriptionIdForConnection(ctx context.Context, d *plugin.QueryData, h
300300
if err != nil {
301301
return nil, err
302302
}
303-
return subscriptionID, nil
303+
304+
// The value must be returned as a string because connection-level quals do not support transform functions.
305+
// If the value is not returned as a string, queries that filter on subscription_id in the WHERE clause
306+
// (e.g., "SELECT id, subscription_id FROM azure_resource WHERE subscription_id = 'd46d7416...'")
307+
// will produce empty results due to a type mismatch during query evaluation.
308+
subscriptionIDStr := subscriptionID.(string)
309+
return subscriptionIDStr, nil
304310
}

0 commit comments

Comments
 (0)