Skip to content

Commit df33c57

Browse files
committed
fixup! feat: fall back to env vars for clientID/tenantID with OIDCTokenFile
Signed-off-by: Jeff Davis <mr.jefedavis@gmail.com>
1 parent 0742f84 commit df33c57

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

internal/clients/azure.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,15 @@ func msiAuth(pcSpec *namespacedv1beta1.ProviderConfigSpec, ps *terraform.Setup)
204204
return nil
205205
}
206206

207+
// specOrEnv returns the spec value if non-nil and non-empty, otherwise the
208+
// value of the named environment variable.
209+
func specOrEnv(specVal *string, envVar string) string {
210+
if specVal != nil && len(*specVal) > 0 {
211+
return *specVal
212+
}
213+
return os.Getenv(envVar)
214+
}
215+
207216
func oidcAuth(pcSpec *namespacedv1beta1.ProviderConfigSpec, ps *terraform.Setup) error {
208217
if pcSpec.SubscriptionID == nil || len(*pcSpec.SubscriptionID) == 0 {
209218
return errors.New(errSubscriptionIDNotSet)
@@ -213,18 +222,12 @@ func oidcAuth(pcSpec *namespacedv1beta1.ProviderConfigSpec, ps *terraform.Setup)
213222
// Azure Workload Identity webhook is enabled on the provider pod, it injects
214223
// AZURE_TENANT_ID and AZURE_CLIENT_ID per pod, enabling per-provider managed
215224
// identities without a cluster-wide ClusterProviderConfig per identity.
216-
tenantID := os.Getenv(envAzureTenantID)
217-
if pcSpec.TenantID != nil && len(*pcSpec.TenantID) > 0 {
218-
tenantID = *pcSpec.TenantID
219-
}
225+
tenantID := specOrEnv(pcSpec.TenantID, envAzureTenantID)
220226
if tenantID == "" {
221227
return errors.New(errTenantIDNotSet)
222228
}
223229

224-
clientID := os.Getenv(envAzureClientID)
225-
if pcSpec.ClientID != nil && len(*pcSpec.ClientID) > 0 {
226-
clientID = *pcSpec.ClientID
227-
}
230+
clientID := specOrEnv(pcSpec.ClientID, envAzureClientID)
228231
if clientID == "" {
229232
return errors.New(errClientIDNotSet)
230233
}

0 commit comments

Comments
 (0)