Skip to content

Commit 7c60885

Browse files
authored
Pass SYSTEM_ACCESSTOKEN from env to the Terraform provider (#4135)
## Changes Pass SYSTEM_ACCESSTOKEN from env to the Terraform provider ## Why Fixes #4047 ## 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 9e3c449 commit 7c60885

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### CLI
88

99
### Bundles
10+
* Pass SYSTEM_ACCESSTOKEN from env to the Terraform provider ([#4135](https://github.com/databricks/cli/pull/4135))
1011

1112
### Dependency updates
1213

bundle/deploy/terraform/init.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,13 @@ 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.
171+
systemAccessToken, ok := env.Lookup(ctx, "SYSTEM_ACCESSTOKEN")
172+
if ok {
173+
environ["SYSTEM_ACCESSTOKEN"] = systemAccessToken
174+
}
175+
169176
// Map $DATABRICKS_TF_CLI_CONFIG_FILE to $TF_CLI_CONFIG_FILE
170177
// VSCode extension provides a file with the "provider_installation.filesystem_mirror" configuration.
171178
// 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
@@ -281,6 +281,16 @@ func TestInheritOIDCTokenEnv(t *testing.T) {
281281
assert.Equal(t, "", env["DATABRICKS_OIDC_TOKEN_ENV"])
282282
}
283283

284+
func TestInheritSystemAccessToken(t *testing.T) {
285+
t.Setenv("SYSTEM_ACCESSTOKEN", "foobar")
286+
287+
ctx := context.Background()
288+
env := map[string]string{}
289+
err := inheritEnvVars(ctx, env)
290+
require.NoError(t, err)
291+
assert.Equal(t, "foobar", env["SYSTEM_ACCESSTOKEN"])
292+
}
293+
284294
func TestSetUserProfileFromInheritEnvVars(t *testing.T) {
285295
t.Setenv("USERPROFILE", "c:\\foo\\c")
286296

0 commit comments

Comments
 (0)