Skip to content

Commit 26da4c1

Browse files
authored
Use "group" instead of "section" when talking about resources (#3121)
https://github.com/databricks/cli/pull/2926/files#r2154501729
1 parent 2d935b6 commit 26da4c1

File tree

8 files changed

+67
-68
lines changed

8 files changed

+67
-68
lines changed

acceptance/bin/read_id.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
"""
33
Print selected attributes from terraform state.
44
5-
Usage: <section> <name> [attr...]
5+
Usage: <group> <name> [attr...]
66
"""
77

88
import sys
99
import os
1010
import json
1111

1212

13-
def print_resource_terraform(section, name):
14-
resource_type = "databricks_" + section[:-1]
13+
def print_resource_terraform(group, name):
14+
resource_type = "databricks_" + group[:-1]
1515
filename = ".databricks/bundle/default/terraform/terraform.tfstate"
1616
raw = open(filename).read()
1717
data = json.loads(raw)
@@ -29,14 +29,14 @@ def print_resource_terraform(section, name):
2929
return
3030

3131

32-
def print_resource_terranova(section, name):
32+
def print_resource_terranova(group, name):
3333
filename = ".databricks/bundle/default/resources.json"
3434
raw = open(filename).read()
3535
data = json.loads(raw)
36-
resources = data["resources"].get(section, {})
36+
resources = data["resources"].get(group, {})
3737
result = resources.get(name)
3838
if result is None:
39-
print(f"Resource {section=} {name=} not found. Available: {raw}")
39+
print(f"Resource {group=} {name=} not found. Available: {raw}")
4040
return
4141
print(result.get("__id__"))
4242

acceptance/bin/read_state.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
"""
33
Print selected attributes from terraform state.
44
5-
Usage: <section> <name> [attr...]
5+
Usage: <group> <name> [attr...]
66
"""
77

88
import sys
99
import os
1010
import json
1111

1212

13-
def print_resource_terraform(section, name, *attrs):
14-
resource_type = "databricks_" + section[:-1]
13+
def print_resource_terraform(group, name, *attrs):
14+
resource_type = "databricks_" + group[:-1]
1515
filename = ".databricks/bundle/default/terraform/terraform.tfstate"
1616
raw = open(filename).read()
1717
data = json.loads(raw)
@@ -27,25 +27,25 @@ def print_resource_terraform(section, name, *attrs):
2727
attribute_values = inst.get("attributes")
2828
if attribute_values:
2929
values = [f"{x}={attribute_values.get(x)!r}" for x in attrs]
30-
print(section, name, " ".join(values))
30+
print(group, name, " ".join(values))
3131
found += 1
3232
if not found:
33-
print(f"State not found for {section}.{name}")
33+
print(f"State not found for {group}.{name}")
3434

3535

36-
def print_resource_terranova(section, name, *attrs):
36+
def print_resource_terranova(group, name, *attrs):
3737
filename = ".databricks/bundle/default/resources.json"
3838
raw = open(filename).read()
3939
data = json.loads(raw)
40-
resources = data["resources"].get(section, {})
40+
resources = data["resources"].get(group, {})
4141
result = resources.get(name)
4242
if result is None:
43-
print(f"State not found for {section}.{name}")
43+
print(f"State not found for {group}.{name}")
4444
return
4545
state = result["state"]
4646
state.setdefault("id", result.get("__id__"))
4747
values = [f"{x}={state.get(x)!r}" for x in attrs]
48-
print(section, name, " ".join(values))
48+
print(group, name, " ".join(values))
4949

5050

5151
if os.environ.get("DATABRICKS_CLI_DEPLOYMENT", "").startswith("direct"):

bundle/bundle.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,20 +285,20 @@ func (b *Bundle) AuthEnv() (map[string]string, error) {
285285
return auth.Env(cfg), nil
286286
}
287287

288-
// GetResourceConfig returns the configuration object for a given resource section/name pair.
288+
// GetResourceConfig returns the configuration object for a given resource group/name pair.
289289
// The returned value is a pointer to the concrete struct that represents that resource type.
290-
// When the section or name is not found the second return value is false.
291-
func (b *Bundle) GetResourceConfig(section, name string) (any, bool) {
292-
// Resolve the Go type that represents a single resource in this section.
293-
typ, ok := config.ResourcesTypes[section]
290+
// When the group or name is not found the second return value is false.
291+
func (b *Bundle) GetResourceConfig(group, name string) (any, bool) {
292+
// Resolve the Go type that represents a single resource in this group.
293+
typ, ok := config.ResourcesTypes[group]
294294
if !ok {
295295
return nil, false
296296
}
297297

298298
// Fetch the raw value from the dynamic representation of the bundle config.
299299
v, err := dyn.GetByPath(
300300
b.Config.Value(),
301-
dyn.NewPath(dyn.Key("resources"), dyn.Key(section), dyn.Key(name)),
301+
dyn.NewPath(dyn.Key("resources"), dyn.Key(group), dyn.Key(name)),
302302
)
303303
if err != nil {
304304
return nil, false

bundle/config/resources_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
"github.com/databricks/cli/libs/structdiff/structtag"
77
)
88

9-
// ResourcesTypes maps the configuration key of each Databricks resource section (for example
9+
// ResourcesTypes maps the configuration key of each Databricks resource group (for example
1010
// "jobs" or "pipelines") to the Go type that represents a single resource instance inside
11-
// that section (for example `resources.Job`).
11+
// that group (for example `resources.Job`).
1212
var ResourcesTypes = func() map[string]reflect.Type {
1313
var r Resources
1414
rt := reflect.TypeOf(r)

bundle/terranova/apply.go

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ func (m *terranovaApplyMutator) Apply(ctx context.Context, b *bundle.Bundle) dia
6464
}
6565

6666
d := Deployer{
67-
client: client,
68-
db: &b.ResourceDatabase,
69-
// TODO: rename section to Group
70-
section: node.Group,
67+
client: client,
68+
db: &b.ResourceDatabase,
69+
group: node.Group,
7170
resourceName: node.Name,
7271
}
7372

@@ -93,34 +92,34 @@ func (m *terranovaApplyMutator) Apply(ctx context.Context, b *bundle.Bundle) dia
9392
type Deployer struct {
9493
client *databricks.WorkspaceClient
9594
db *tnstate.TerranovaState
96-
section string
95+
group string
9796
resourceName string
9897
}
9998

10099
func (d *Deployer) Deploy(ctx context.Context, inputConfig any, actionType deployplan.ActionType) error {
101100
if actionType == deployplan.ActionTypeDelete {
102101
err := d.destroy(ctx, inputConfig)
103102
if err != nil {
104-
return fmt.Errorf("destroying %s.%s: %w", d.section, d.resourceName, err)
103+
return fmt.Errorf("destroying %s.%s: %w", d.group, d.resourceName, err)
105104
}
106105
return nil
107106
}
108107

109108
err := d.deploy(ctx, inputConfig, actionType)
110109
if err != nil {
111-
return fmt.Errorf("deploying %s.%s: %w", d.section, d.resourceName, err)
110+
return fmt.Errorf("deploying %s.%s: %w", d.group, d.resourceName, err)
112111
}
113112
return nil
114113
}
115114

116115
func (d *Deployer) destroy(ctx context.Context, inputConfig any) error {
117-
entry, hasEntry := d.db.GetResourceEntry(d.section, d.resourceName)
116+
entry, hasEntry := d.db.GetResourceEntry(d.group, d.resourceName)
118117
if !hasEntry {
119-
log.Infof(ctx, "%s.%s: Cannot delete, missing from state", d.section, d.resourceName)
118+
log.Infof(ctx, "%s.%s: Cannot delete, missing from state", d.group, d.resourceName)
120119
return nil
121120
}
122121

123-
resource, _, err := tnresources.New(d.client, d.section, d.resourceName, inputConfig)
122+
resource, _, err := tnresources.New(d.client, d.group, d.resourceName, inputConfig)
124123
if err != nil {
125124
return err
126125
}
@@ -138,9 +137,9 @@ func (d *Deployer) destroy(ctx context.Context, inputConfig any) error {
138137
}
139138

140139
func (d *Deployer) deploy(ctx context.Context, inputConfig any, actionType deployplan.ActionType) error {
141-
entry, hasEntry := d.db.GetResourceEntry(d.section, d.resourceName)
140+
entry, hasEntry := d.db.GetResourceEntry(d.group, d.resourceName)
142141

143-
resource, cfgType, err := tnresources.New(d.client, d.section, d.resourceName, inputConfig)
142+
resource, cfgType, err := tnresources.New(d.client, d.group, d.resourceName, inputConfig)
144143
if err != nil {
145144
return err
146145
}
@@ -182,7 +181,7 @@ func (d *Deployer) deploy(ctx context.Context, inputConfig any, actionType deplo
182181

183182
// localDiffType is either None or Partial: we should proceed to fetching remote state and calculate local+remote diff
184183

185-
log.Debugf(ctx, "Unchanged %s.%s id=%#v", d.section, d.resourceName, oldID)
184+
log.Debugf(ctx, "Unchanged %s.%s id=%#v", d.group, d.resourceName, oldID)
186185
return nil
187186
}
188187

@@ -192,9 +191,9 @@ func (d *Deployer) Create(ctx context.Context, resource tnresources.IResource, c
192191
return fmt.Errorf("creating: %w", err)
193192
}
194193

195-
log.Infof(ctx, "Created %s.%s id=%#v", d.section, d.resourceName, newID)
194+
log.Infof(ctx, "Created %s.%s id=%#v", d.group, d.resourceName, newID)
196195

197-
err = d.db.SaveState(d.section, d.resourceName, newID, config)
196+
err = d.db.SaveState(d.group, d.resourceName, newID, config)
198197
if err != nil {
199198
return fmt.Errorf("saving state after creating id=%s: %w", newID, err)
200199
}
@@ -213,12 +212,12 @@ func (d *Deployer) Recreate(ctx context.Context, oldResource tnresources.IResour
213212
return fmt.Errorf("deleting old id=%s: %w", oldID, err)
214213
}
215214

216-
err = d.db.SaveState(d.section, d.resourceName, "", nil)
215+
err = d.db.SaveState(d.group, d.resourceName, "", nil)
217216
if err != nil {
218217
return fmt.Errorf("deleting state: %w", err)
219218
}
220219

221-
newResource, _, err := tnresources.New(d.client, d.section, d.resourceName, config)
220+
newResource, _, err := tnresources.New(d.client, d.group, d.resourceName, config)
222221
if err != nil {
223222
return fmt.Errorf("initializing: %w", err)
224223
}
@@ -228,8 +227,8 @@ func (d *Deployer) Recreate(ctx context.Context, oldResource tnresources.IResour
228227
return fmt.Errorf("re-creating: %w", err)
229228
}
230229

231-
log.Warnf(ctx, "Re-created %s.%s id=%#v (previously %#v)", d.section, d.resourceName, newID, oldID)
232-
err = d.db.SaveState(d.section, d.resourceName, newID, config)
230+
log.Warnf(ctx, "Re-created %s.%s id=%#v (previously %#v)", d.group, d.resourceName, newID, oldID)
231+
err = d.db.SaveState(d.group, d.resourceName, newID, config)
233232
if err != nil {
234233
return fmt.Errorf("saving state for id=%s: %w", newID, err)
235234
}
@@ -249,12 +248,12 @@ func (d *Deployer) Update(ctx context.Context, resource tnresources.IResource, o
249248
}
250249

251250
if oldID != newID {
252-
log.Infof(ctx, "Updated %s.%s id=%#v (previously %#v)", d.section, d.resourceName, newID, oldID)
251+
log.Infof(ctx, "Updated %s.%s id=%#v (previously %#v)", d.group, d.resourceName, newID, oldID)
253252
} else {
254-
log.Infof(ctx, "Updated %s.%s id=%#v", d.section, d.resourceName, newID)
253+
log.Infof(ctx, "Updated %s.%s id=%#v", d.group, d.resourceName, newID)
255254
}
256255

257-
err = d.db.SaveState(d.section, d.resourceName, newID, config)
256+
err = d.db.SaveState(d.group, d.resourceName, newID, config)
258257
if err != nil {
259258
return fmt.Errorf("saving state id=%s: %w", oldID, err)
260259
}
@@ -273,7 +272,7 @@ func (d *Deployer) Delete(ctx context.Context, resource tnresources.IResource, o
273272
return fmt.Errorf("deleting id=%s: %w", oldID, err)
274273
}
275274

276-
err = d.db.DeleteState(d.section, d.resourceName)
275+
err = d.db.DeleteState(d.group, d.resourceName)
277276
if err != nil {
278277
return fmt.Errorf("deleting state id=%s: %w", oldID, err)
279278
}

bundle/terranova/plan.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ import (
1818
type Planner struct {
1919
client *databricks.WorkspaceClient
2020
db *tnstate.TerranovaState
21-
section string
21+
group string
2222
resourceName string
2323
}
2424

2525
func (d *Planner) Plan(ctx context.Context, inputConfig any) (deployplan.ActionType, error) {
26-
entry, hasEntry := d.db.GetResourceEntry(d.section, d.resourceName)
26+
entry, hasEntry := d.db.GetResourceEntry(d.group, d.resourceName)
2727

28-
resource, cfgType, err := tnresources.New(d.client, d.section, d.resourceName, inputConfig)
28+
resource, cfgType, err := tnresources.New(d.client, d.group, d.resourceName, inputConfig)
2929
if err != nil {
3030
return "", err
3131
}
@@ -85,7 +85,7 @@ func CalculateDeployActions(ctx context.Context, b *bundle.Bundle) ([]deployplan
8585
pl := Planner{
8686
client: client,
8787
db: &b.ResourceDatabase,
88-
section: group,
88+
group: group,
8989
resourceName: name,
9090
}
9191

bundle/terranova/tnresources/resource.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,20 @@ func invokeConstructor(ctor reflect.Value, client *databricks.WorkspaceClient, c
8383
return res, nil
8484
}
8585

86-
func New(client *databricks.WorkspaceClient, section, name string, config any) (IResource, reflect.Type, error) {
87-
ctor, ok := supportedResources[section]
86+
func New(client *databricks.WorkspaceClient, group, name string, config any) (IResource, reflect.Type, error) {
87+
ctor, ok := supportedResources[group]
8888
if !ok {
89-
return nil, nil, fmt.Errorf("unsupported resource type: %s", section)
89+
return nil, nil, fmt.Errorf("unsupported resource type: %s", group)
9090
}
9191

92-
cfgType, ok := supportedResourcesTypes[section]
92+
cfgType, ok := supportedResourcesTypes[group]
9393
if !ok {
94-
return nil, nil, fmt.Errorf("unsupported resource type: %s", section)
94+
return nil, nil, fmt.Errorf("unsupported resource type: %s", group)
9595
}
9696

9797
// Disallow nil configs (including typed nil pointers).
9898
if config == nil {
99-
return nil, nil, fmt.Errorf("unexpected nil in config: %s.%s", section, name)
99+
return nil, nil, fmt.Errorf("unexpected nil in config: %s.%s", group, name)
100100
}
101101

102102
// If the supplied config is a pointer value, dereference it so that we pass
@@ -105,7 +105,7 @@ func New(client *databricks.WorkspaceClient, section, name string, config any) (
105105
v := reflect.ValueOf(config)
106106
if v.Kind() == reflect.Ptr {
107107
if v.IsNil() {
108-
return nil, nil, fmt.Errorf("unexpected nil in config: %s.%s", section, name)
108+
return nil, nil, fmt.Errorf("unexpected nil in config: %s.%s", group, name)
109109
}
110110
}
111111

bundle/terranova/tnstate/state.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,51 +26,51 @@ type ResourceEntry struct {
2626
State any `json:"state"`
2727
}
2828

29-
func (db *TerranovaState) SaveState(section, resourceName, newID string, state any) error {
29+
func (db *TerranovaState) SaveState(group, resourceName, newID string, state any) error {
3030
db.AssertOpened()
3131
db.mu.Lock()
3232
defer db.mu.Unlock()
3333

34-
sectionData, ok := db.Data.Resources[section]
34+
groupData, ok := db.Data.Resources[group]
3535
if !ok {
36-
sectionData = make(map[string]ResourceEntry)
37-
db.Data.Resources[section] = sectionData
36+
groupData = make(map[string]ResourceEntry)
37+
db.Data.Resources[group] = groupData
3838
}
3939

40-
sectionData[resourceName] = ResourceEntry{
40+
groupData[resourceName] = ResourceEntry{
4141
ID: newID,
4242
State: state,
4343
}
4444

4545
return nil
4646
}
4747

48-
func (db *TerranovaState) DeleteState(section, resourceName string) error {
48+
func (db *TerranovaState) DeleteState(group, resourceName string) error {
4949
db.AssertOpened()
5050
db.mu.Lock()
5151
defer db.mu.Unlock()
5252

53-
sectionData, ok := db.Data.Resources[section]
53+
groupData, ok := db.Data.Resources[group]
5454
if !ok {
5555
return nil
5656
}
5757

58-
delete(sectionData, resourceName)
58+
delete(groupData, resourceName)
5959

6060
return nil
6161
}
6262

63-
func (db *TerranovaState) GetResourceEntry(section, resourceName string) (ResourceEntry, bool) {
63+
func (db *TerranovaState) GetResourceEntry(group, resourceName string) (ResourceEntry, bool) {
6464
db.AssertOpened()
6565
db.mu.Lock()
6666
defer db.mu.Unlock()
6767

68-
sectionData, ok := db.Data.Resources[section]
68+
groupData, ok := db.Data.Resources[group]
6969
if !ok {
7070
return ResourceEntry{}, false
7171
}
7272

73-
result, ok := sectionData[resourceName]
73+
result, ok := groupData[resourceName]
7474
return result, ok
7575
}
7676

0 commit comments

Comments
 (0)