Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make subscription_id configurable in cli #465

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion builder/azure/common/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,10 @@ func (c *Config) FillParameters() error {
}

c.TenantID = tenantID
c.SubscriptionID = subscriptionID
// we need to honor the subscription_id if specified in the config instead using the default CLI subscription_id
if c.SubscriptionID == "" {
c.SubscriptionID = subscriptionID
}
}

// Get Tenant ID from Access token
Expand Down
29 changes: 29 additions & 0 deletions builder/azure/common/client/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,35 @@ func Test_ClientConfig_AzureCli(t *testing.T) {
if cfg.AuthType() != AuthTypeAzureCLI {
t.Fatalf("Expected authType to be %q, but got: %q", AuthTypeAzureCLI, cfg.AuthType())
}

if cfg.SubscriptionID == "" {
t.Fatalf("Expected SubscriptionId to not be empty, but got %s", cfg.SubscriptionID)
}
}

func Test_ClientConfig_AzureCli_with_subscription_id_set(t *testing.T) {
// Azure CLI tests skipped unless env 'AZURE_CLI_AUTH' is set, and an active `az login` session has been established
getEnvOrSkip(t, "AZURE_CLI_AUTH")
subId := "non-default-subscription_id"
cfg := Config{
UseAzureCLIAuth: true,
cloudEnvironment: environments.AzurePublic(),
SubscriptionID: subId,
}
assertValid(t, cfg)

err := cfg.FillParameters()
if err != nil {
t.Fatalf("Expected nil err, but got: %v", err)
}

if cfg.AuthType() != AuthTypeAzureCLI {
t.Fatalf("Expected authType to be %q, but got: %q", AuthTypeAzureCLI, cfg.AuthType())
}

if cfg.SubscriptionID != subId {
t.Fatalf("Expected SubscriptionId to be %s, but got: %s", subId, cfg.SubscriptionID)
}
}

func Test_ClientConfig_GitHubOIDC(t *testing.T) {
Expand Down
Loading