-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support account-level provider with workspace-level resources #3188
base: main
Are you sure you want to change the base?
Changes from 1 commit
1ad91bd
eb7097b
148ccaa
8cfbb7d
f6cd6d0
703109d
9f35f59
7752299
ab4c591
4d4edd2
ddf747a
468920b
782b210
4ef15d3
f50673e
20f35e2
f3a0e4a
affa5a5
106d8cc
74d65f2
9af9719
fe2a7cd
ebbc581
a4d3ca5
2e385e8
a5b2dda
5874ead
d373d3b
1267f35
6f95828
327d471
10e586f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,10 @@ func (r Resource) ToResource() *schema.Resource { | |
if r.Update != nil { | ||
update = func(ctx context.Context, d *schema.ResourceData, | ||
m any) diag.Diagnostics { | ||
c := m.(*DatabricksClient) | ||
c, err := m.(*DatabricksClient).InConfiguredWorkspace(ctx, d) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's not enough, you also need to prepend workspace_id to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This field is marked as |
||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
if err := recoverable(r.Update)(ctx, d, c); err != nil { | ||
err = nicerError(ctx, err, "update") | ||
return diag.FromErr(err) | ||
|
@@ -124,7 +127,11 @@ func (r Resource) ToResource() *schema.Resource { | |
m any) diag.Diagnostics { | ||
return func(ctx context.Context, d *schema.ResourceData, | ||
m any) diag.Diagnostics { | ||
err := recoverable(r.Read)(ctx, d, m.(*DatabricksClient)) | ||
c, err := m.(*DatabricksClient).InConfiguredWorkspace(ctx, d) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
err = recoverable(r.Read)(ctx, d, c) | ||
// TODO: https://github.com/databricks/terraform-provider-databricks/issues/2021 | ||
if ignoreMissing && apierr.IsMissing(err) { | ||
log.Printf("[INFO] %s[id=%s] is removed on backend", | ||
|
@@ -146,8 +153,11 @@ func (r Resource) ToResource() *schema.Resource { | |
CustomizeDiff: r.saferCustomizeDiff(), | ||
CreateContext: func(ctx context.Context, d *schema.ResourceData, | ||
m any) diag.Diagnostics { | ||
c := m.(*DatabricksClient) | ||
err := recoverable(r.Create)(ctx, d, c) | ||
c, err := m.(*DatabricksClient).InConfiguredWorkspace(ctx, d) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
err = recoverable(r.Create)(ctx, d, c) | ||
if err != nil { | ||
err = nicerError(ctx, err, "create") | ||
return diag.FromErr(err) | ||
|
@@ -162,7 +172,11 @@ func (r Resource) ToResource() *schema.Resource { | |
UpdateContext: update, | ||
DeleteContext: func(ctx context.Context, d *schema.ResourceData, | ||
m any) diag.Diagnostics { | ||
err := recoverable(r.Delete)(ctx, d, m.(*DatabricksClient)) | ||
c, err := m.(*DatabricksClient).InConfiguredWorkspace(ctx, d) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
err = recoverable(r.Delete)(ctx, d, c) | ||
if apierr.IsMissing(err) { | ||
// TODO: https://github.com/databricks/terraform-provider-databricks/issues/2021 | ||
log.Printf("[INFO] %s[id=%s] is removed on backend", | ||
|
@@ -447,3 +461,13 @@ func AddAccountIdField(s map[string]*schema.Schema) map[string]*schema.Schema { | |
} | ||
return s | ||
} | ||
|
||
func AddWorkspaceIdField(s map[string]*schema.Schema) map[string]*schema.Schema { | ||
s["workspace_id"] = &schema.Schema{ | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
ForceNew: true, | ||
Description: "The workspace id of the workspace, for example 1234567890. This can be retrieved from `databricks_mws_workspaces.<YOUR_WORKSPACE>.workspace_id`. This attribute is required when using an account-level provider.", | ||
} | ||
return s | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this won't scale, add it on the level of
common.Resource
andcommon.DataSource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about how to do this. We don't know which resources are workspace-only or also at the account level. We need some explicit mapping to make sure this isn't forgotten about. I will probably add this at the provider-level to make sure there is an explicit opt-in/out for each resource type.