Skip to content

Commit 439c36c

Browse files
authored
Pass additional Azure DevOps system variables (#4236)
## Changes Pass additional Azure DevOps system variables required for OIDC authentication. * SYSTEM_PLANID * SYSTEM_COLLECTIONID * SYSTEM_TEAMPROJECTID * SYSTEM_OIDCREQUESTURI ## Why These variables are used by the Databricks Go SDK to authenticate with Azure DevOps OIDC. Fixes #4226 ## Tests Added unit test <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent ede447a commit 439c36c

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ To disable this, set the environment variable DATABRICKS_CACHE_ENABLED to false.
1010

1111
### Bundles
1212
* Enable caching user identity by default ([#4202](https://github.com/databricks/cli/pull/4202))
13+
* Pass additional Azure DevOps system variables ([#4236](https://github.com/databricks/cli/pull/4236))
1314

1415
### Dependency updates
1516

bundle/deploy/terraform/init.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,20 @@ func inheritEnvVars(ctx context.Context, environ map[string]string) error {
166166
environ[oidcTokenEnv] = oidcToken
167167
}
168168

169-
// If there's SYSTEM_ACCESSTOKEN set, we need to pass the value of the environment variable to Terraform.
170-
// This is necessary to ensure that Terraform can use the same access token as the CLI for Azure DevOps OIDC auth.
171-
systemAccessToken, ok := env.Lookup(ctx, "SYSTEM_ACCESSTOKEN")
172-
if ok {
173-
environ["SYSTEM_ACCESSTOKEN"] = systemAccessToken
174-
}
175-
176-
// If there's SYSTEM_TEAMFOUNDATIONCOLLECTIONURI set, we need to pass the value of the environment variable to Terraform.
177-
// This is necessary for Azure DevOps OIDC auth to work properly.
178-
systemCollectionUri, ok := env.Lookup(ctx, "SYSTEM_TEAMFOUNDATIONCOLLECTIONURI")
179-
if ok {
180-
environ["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"] = systemCollectionUri
169+
// Pass additional Azure DevOps system variables required for OIDC authentication.
170+
// These variables are used by the Databricks Go SDK to authenticate with Azure DevOps OIDC.
171+
azureDevOpsVars := []string{
172+
"SYSTEM_ACCESSTOKEN",
173+
"SYSTEM_TEAMFOUNDATIONCOLLECTIONURI",
174+
"SYSTEM_PLANID",
175+
"SYSTEM_COLLECTIONID",
176+
"SYSTEM_TEAMPROJECTID",
177+
"SYSTEM_OIDCREQUESTURI",
178+
}
179+
for _, varName := range azureDevOpsVars {
180+
if val, ok := env.Lookup(ctx, varName); ok {
181+
environ[varName] = val
182+
}
181183
}
182184

183185
// Map $DATABRICKS_TF_CLI_CONFIG_FILE to $TF_CLI_CONFIG_FILE

bundle/deploy/terraform/init_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,23 @@ func TestInheritSystemTeamFoundationCollectionUri(t *testing.T) {
301301
assert.Equal(t, "foobar", env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"])
302302
}
303303

304+
func TestInheritAzureDevOpsSystemVariables(t *testing.T) {
305+
// Set Azure DevOps system variables
306+
t.Setenv("SYSTEM_PLANID", "plan-id-123")
307+
t.Setenv("SYSTEM_COLLECTIONID", "collection-id-456")
308+
t.Setenv("SYSTEM_TEAMPROJECTID", "project-id-789")
309+
t.Setenv("SYSTEM_OIDCREQUESTURI", "https://oidc.example.com")
310+
311+
ctx := context.Background()
312+
env := map[string]string{}
313+
err := inheritEnvVars(ctx, env)
314+
require.NoError(t, err)
315+
assert.Equal(t, "plan-id-123", env["SYSTEM_PLANID"])
316+
assert.Equal(t, "collection-id-456", env["SYSTEM_COLLECTIONID"])
317+
assert.Equal(t, "project-id-789", env["SYSTEM_TEAMPROJECTID"])
318+
assert.Equal(t, "https://oidc.example.com", env["SYSTEM_OIDCREQUESTURI"])
319+
}
320+
304321
func TestSetUserProfileFromInheritEnvVars(t *testing.T) {
305322
t.Setenv("USERPROFILE", "c:\\foo\\c")
306323

0 commit comments

Comments
 (0)