Skip to content

Commit 31df20c

Browse files
authored
Exporter: optimize generation of databricks_group_member resource (#3559)
With this change we're generating resource data directly because we have all necessary information - this should decrease the number of REST API calls to SCIM API because the Read operation of `databricks_group_member` reads a group for each group member.
1 parent a285f58 commit 31df20c

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

exporter/importables.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -903,10 +903,12 @@ var resourcesMap map[string]importable = map[string]importable{
903903
ID: parent.Value,
904904
})
905905
if parent.Type == "direct" {
906+
id := fmt.Sprintf("%s|%s", parent.Value, g.ID)
906907
ic.Emit(&resource{
907908
Resource: "databricks_group_member",
908-
ID: fmt.Sprintf("%s|%s", parent.Value, g.ID),
909+
ID: id,
909910
Name: fmt.Sprintf("%s_%s_%s", parent.Display, parent.Value, g.DisplayName),
911+
Data: ic.makeGroupMemberData(id, parent.Value, g.ID),
910912
})
911913
}
912914
}
@@ -917,10 +919,12 @@ var resourcesMap map[string]importable = map[string]importable{
917919
ID: x.Value,
918920
})
919921
if !builtInUserGroup {
922+
id := fmt.Sprintf("%s|%s", g.ID, x.Value)
920923
ic.Emit(&resource{
921924
Resource: "databricks_group_member",
922-
ID: fmt.Sprintf("%s|%s", g.ID, x.Value),
925+
ID: id,
923926
Name: fmt.Sprintf("%s_%s_%s_%s", g.DisplayName, g.ID, x.Display, x.Value),
927+
Data: ic.makeGroupMemberData(id, g.ID, x.Value),
924928
})
925929
}
926930
}
@@ -930,10 +934,12 @@ var resourcesMap map[string]importable = map[string]importable{
930934
ID: x.Value,
931935
})
932936
if !builtInUserGroup {
937+
id := fmt.Sprintf("%s|%s", g.ID, x.Value)
933938
ic.Emit(&resource{
934939
Resource: "databricks_group_member",
935-
ID: fmt.Sprintf("%s|%s", g.ID, x.Value),
940+
ID: id,
936941
Name: fmt.Sprintf("%s_%s_%s_%s", g.DisplayName, g.ID, x.Display, x.Value),
942+
Data: ic.makeGroupMemberData(id, g.ID, x.Value),
937943
})
938944
}
939945
}
@@ -943,10 +949,12 @@ var resourcesMap map[string]importable = map[string]importable{
943949
ID: x.Value,
944950
})
945951
if !builtInUserGroup {
952+
id := fmt.Sprintf("%s|%s", g.ID, x.Value)
946953
ic.Emit(&resource{
947954
Resource: "databricks_group_member",
948-
ID: fmt.Sprintf("%s|%s", g.ID, x.Value),
955+
ID: id,
949956
Name: fmt.Sprintf("%s_%s_%s_%s", g.DisplayName, g.ID, x.Display, x.Value),
957+
Data: ic.makeGroupMemberData(id, g.ID, x.Value),
950958
})
951959
}
952960
}

exporter/util.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,12 @@ func (ic *importContext) emitGroups(u scim.User) {
371371
Resource: "databricks_group",
372372
ID: g.Value,
373373
})
374+
id := fmt.Sprintf("%s|%s", g.Value, u.ID)
374375
ic.Emit(&resource{
375376
Resource: "databricks_group_member",
376-
ID: fmt.Sprintf("%s|%s", g.Value, u.ID),
377+
ID: id,
377378
Name: fmt.Sprintf("%s_%s_%s_%s", g.Display, g.Value, u.DisplayName, u.ID),
379+
Data: ic.makeGroupMemberData(id, g.Value, u.ID),
378380
})
379381
}
380382
}
@@ -1495,3 +1497,12 @@ func dltIsMatchingCatalogAndSchema(ic *importContext, res *resource, ra *resourc
14951497
result := ra_catalog_name.(string) == res_catalog_name && ra_schema_name.(string) == res_schema_name
14961498
return result
14971499
}
1500+
1501+
func (ic *importContext) makeGroupMemberData(id, groupId, memberId string) *schema.ResourceData {
1502+
data := scim.ResourceGroupMember().ToResource().TestResourceData()
1503+
data.MarkNewResource()
1504+
data.SetId(id)
1505+
data.Set("group_id", groupId)
1506+
data.Set("member_id", memberId)
1507+
return data
1508+
}

0 commit comments

Comments
 (0)