Skip to content

Commit 08024ee

Browse files
committed
Pass SYSTEM_TEAMFOUNDATIONCOLLECTIONURI to Terraform for Azure DevOps OIDC auth
1 parent c54498e commit 08024ee

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

bundle/deploy/terraform/init.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,19 @@ func inheritEnvVars(ctx context.Context, environ map[string]string) error {
167167
}
168168

169169
// 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.
170+
// This is necessary to ensure that Terraform can use the same access token as the CLI for Azure DevOps OIDC auth.
171171
systemAccessToken, ok := env.Lookup(ctx, "SYSTEM_ACCESSTOKEN")
172172
if ok {
173173
environ["SYSTEM_ACCESSTOKEN"] = systemAccessToken
174174
}
175175

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
181+
}
182+
176183
// Map $DATABRICKS_TF_CLI_CONFIG_FILE to $TF_CLI_CONFIG_FILE
177184
// VSCode extension provides a file with the "provider_installation.filesystem_mirror" configuration.
178185
// We only use it if the provider version matches the currently used version,

bundle/deploy/terraform/init_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,16 @@ func TestInheritSystemAccessToken(t *testing.T) {
291291
assert.Equal(t, "foobar", env["SYSTEM_ACCESSTOKEN"])
292292
}
293293

294+
func TestInheritSystemTeamFoundationCollectionUri(t *testing.T) {
295+
t.Setenv("SYSTEM_TEAMFOUNDATIONCOLLECTIONURI", "foobar")
296+
297+
ctx := context.Background()
298+
env := map[string]string{}
299+
err := inheritEnvVars(ctx, env)
300+
require.NoError(t, err)
301+
assert.Equal(t, "foobar", env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"])
302+
}
303+
294304
func TestSetUserProfileFromInheritEnvVars(t *testing.T) {
295305
t.Setenv("USERPROFILE", "c:\\foo\\c")
296306

0 commit comments

Comments
 (0)