Skip to content

Commit b3b58ec

Browse files
authored
Deduplicate TerraformResourceName (#2995)
## Changes The `TerraformResourceName` field was added to the description struct in #1928. This PR removes the duplication between that field and the `TerraformResourceName` function on all resources. It also uses this value when interpolating Terraform resource references instead of keeping another hardcoded value around. The value for the model serving endpoint is updated to reflect the right value (it wasn't used before). ## Tests Existing tests pass.
1 parent 503f952 commit b3b58ec

File tree

17 files changed

+12
-86
lines changed

17 files changed

+12
-86
lines changed

bundle/config/resources.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ type ConfigResource interface {
3535
// ResourceDescription returns a struct containing strings describing a resource
3636
ResourceDescription() resources.ResourceDescription
3737

38-
// TerraformResourceName returns an equivalent name of the resource. For example "databricks_job"
39-
// for jobs and "databricks_pipeline" for pipelines.
40-
TerraformResourceName() string
41-
4238
// GetName returns the in-product name of the resource.
4339
GetName() string
4440

@@ -172,7 +168,7 @@ func (r *Resources) FindResourceByConfigKey(key string) (ConfigResource, error)
172168
if len(found) > 1 {
173169
keys := make([]string, 0, len(found))
174170
for _, r := range found {
175-
keys = append(keys, fmt.Sprintf("%s:%s", r.TerraformResourceName(), key))
171+
keys = append(keys, fmt.Sprintf("%s:%s", r.ResourceDescription().TerraformResourceName, key))
176172
}
177173
return nil, fmt.Errorf("ambiguous: %s (can resolve to all of %s)", key, keys)
178174
}

bundle/config/resources/apps.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ func (*App) ResourceDescription() ResourceDescription {
6767
}
6868
}
6969

70-
func (a *App) TerraformResourceName() string {
71-
return "databricks_app"
72-
}
73-
7470
func (a *App) InitializeURL(baseURL url.URL) {
7571
if a.ModifiedStatus == "" || a.ModifiedStatus == ModifiedStatusCreated {
7672
return

bundle/config/resources/clusters.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ func (*Cluster) ResourceDescription() ResourceDescription {
5858
}
5959
}
6060

61-
func (s *Cluster) TerraformResourceName() string {
62-
return "databricks_cluster"
63-
}
64-
6561
func (s *Cluster) InitializeURL(baseURL url.URL) {
6662
if s.ID == "" {
6763
return

bundle/config/resources/dashboard.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ func (*Dashboard) ResourceDescription() ResourceDescription {
8181
}
8282
}
8383

84-
func (*Dashboard) TerraformResourceName() string {
85-
return "databricks_dashboard"
86-
}
87-
8884
func (r *Dashboard) InitializeURL(baseURL url.URL) {
8985
if r.ID == "" {
9086
return

bundle/config/resources/job.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ func (j *Job) ResourceDescription() ResourceDescription {
6565
}
6666
}
6767

68-
func (j *Job) TerraformResourceName() string {
69-
return "databricks_job"
70-
}
71-
7268
func (j *Job) InitializeURL(baseURL url.URL) {
7369
if j.ID == "" {
7470
return

bundle/config/resources/mlflow_experiment.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ func (j *MlflowExperiment) ResourceDescription() ResourceDescription {
6060
}
6161
}
6262

63-
func (s *MlflowExperiment) TerraformResourceName() string {
64-
return "databricks_mlflow_experiment"
65-
}
66-
6763
func (s *MlflowExperiment) InitializeURL(baseURL url.URL) {
6864
if s.ID == "" {
6965
return

bundle/config/resources/mlflow_model.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ func (j *MlflowModel) ResourceDescription() ResourceDescription {
6060
}
6161
}
6262

63-
func (s *MlflowModel) TerraformResourceName() string {
64-
return "databricks_mlflow_model"
65-
}
66-
6763
func (s *MlflowModel) InitializeURL(baseURL url.URL) {
6864
if s.ID == "" {
6965
return

bundle/config/resources/model_serving_endpoint.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,10 @@ func (j *ModelServingEndpoint) ResourceDescription() ResourceDescription {
6464
PluralName: "model_serving_endpoints",
6565
SingularTitle: "Model Serving Endpoint",
6666
PluralTitle: "Model Serving Endpoints",
67-
TerraformResourceName: "databricks_model_serving_endpoint",
67+
TerraformResourceName: "databricks_model_serving",
6868
}
6969
}
7070

71-
func (s *ModelServingEndpoint) TerraformResourceName() string {
72-
return "databricks_model_serving"
73-
}
74-
7571
func (s *ModelServingEndpoint) InitializeURL(baseURL url.URL) {
7672
if s.ID == "" {
7773
return

bundle/config/resources/pipeline.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ func (j *Pipeline) ResourceDescription() ResourceDescription {
6060
}
6161
}
6262

63-
func (p *Pipeline) TerraformResourceName() string {
64-
return "databricks_pipeline"
65-
}
66-
6763
func (p *Pipeline) InitializeURL(baseURL url.URL) {
6864
if p.ID == "" {
6965
return

bundle/config/resources/quality_monitor.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ func (*QualityMonitor) ResourceDescription() ResourceDescription {
5252
}
5353
}
5454

55-
func (s *QualityMonitor) TerraformResourceName() string {
56-
return "databricks_quality_monitor"
57-
}
58-
5955
func (s *QualityMonitor) InitializeURL(baseURL url.URL) {
6056
if s.TableName == "" {
6157
return

0 commit comments

Comments
 (0)