Skip to content
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
22 changes: 22 additions & 0 deletions bundle/deploy/terraform/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,23 @@ func setProxyEnvVars(ctx context.Context, environ map[string]string, b *bundle.B
return nil
}

func setUserAgentExtraEnvVar(environ map[string]string, b *bundle.Bundle) error {
var products []string

if experimental := b.Config.Experimental; experimental != nil {
if experimental.PyDABs.Enabled {
products = append(products, "databricks-pydabs/0.0.0")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the user agent in the client that the CLI uses itself?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean "bundle run" command or any other command as well? I can fix for "bundle run" as a follow-up

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good for parity.

}
}

userAgentExtra := strings.Join(products, " ")
if userAgentExtra != "" {
environ["DATABRICKS_USER_AGENT_EXTRA"] = userAgentExtra
}

return nil
}

func (m *initialize) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
tfConfig := b.Config.Bundle.Terraform
if tfConfig == nil {
Expand Down Expand Up @@ -262,6 +279,11 @@ func (m *initialize) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnosti
return diag.FromErr(err)
}

err = setUserAgentExtraEnvVar(environ, b)
if err != nil {
return diag.FromErr(err)
}

// Configure environment variables for auth for Terraform to use.
log.Debugf(ctx, "Environment variables for Terraform: %s", strings.Join(maps.Keys(environ), ", "))
err = tf.SetEnv(environ)
Expand Down
21 changes: 21 additions & 0 deletions bundle/deploy/terraform/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,27 @@ func TestSetProxyEnvVars(t *testing.T) {
assert.ElementsMatch(t, []string{"HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY"}, maps.Keys(env))
}

func TestSetUserAgentExtraEnvVar(t *testing.T) {
b := &bundle.Bundle{
RootPath: t.TempDir(),
Config: config.Root{
Experimental: &config.Experimental{
PyDABs: config.PyDABs{
Enabled: true,
},
},
},
}

env := make(map[string]string, 0)
err := setUserAgentExtraEnvVar(env, b)

require.NoError(t, err)
assert.Equal(t, map[string]string{
"DATABRICKS_USER_AGENT_EXTRA": "databricks-pydabs/0.0.0",
}, env)
}

func TestInheritEnvVars(t *testing.T) {
env := map[string]string{}

Expand Down