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
57 changes: 57 additions & 0 deletions bundle/direct/dresources/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,60 @@ func TestGetResourceConfig(t *testing.T) {
assert.NotEmpty(t, GetResourceConfig("volumes").RecreateOnChanges)
assert.Empty(t, GetResourceConfig("nonexistent").RecreateOnChanges)
}

// categoryRules projects ResourceLifecycleConfig's five categories onto a
// uniform [name, []FieldRule] shape so the redundancy check can iterate them.
func categoryRules(c ResourceLifecycleConfig) []struct {
name string
rules []FieldRule
} {
backendAsFieldRules := make([]FieldRule, len(c.BackendDefaults))
for i, r := range c.BackendDefaults {
backendAsFieldRules[i] = FieldRule{Field: r.Field}
}
return []struct {
name string
rules []FieldRule
}{
{"ignore_remote_changes", c.IgnoreRemoteChanges},
{"ignore_local_changes", c.IgnoreLocalChanges},
{"recreate_on_changes", c.RecreateOnChanges},
{"update_id_on_changes", c.UpdateIDOnChanges},
{"backend_defaults", backendAsFieldRules},
}
}

// TestResourcesYMLNoRedundantRules guards against two redundancy classes in
// resources.yml: duplicate field entries within the same category of a
// resource, and entries that the autogenerated resources.generated.yml already
// produces from the OpenAPI schema.
func TestResourcesYMLNoRedundantRules(t *testing.T) {
handWritten := MustLoadConfig()
generated := MustLoadGeneratedConfig()

for resourceType, rc := range handWritten.Resources {
genCats := categoryRules(generated.Resources[resourceType])
genFields := make(map[string]map[string]bool, len(genCats))
for _, c := range genCats {
fields := make(map[string]bool, len(c.rules))
for _, r := range c.rules {
fields[r.Field.String()] = true
}
genFields[c.name] = fields
}

for _, c := range categoryRules(rc) {
seen := make(map[string]bool, len(c.rules))
for _, r := range c.rules {
field := r.Field.String()
if seen[field] {
t.Errorf("bundle/direct/dresources/resources.yml: %s.%s lists %q twice; remove the duplicate entry", resourceType, c.name, field)
}
seen[field] = true
if genFields[c.name][field] {
t.Errorf("bundle/direct/dresources/resources.yml: %s.%s entry %q is already produced by resources.generated.yml; remove it from resources.yml", resourceType, c.name, field)
}
}
}
}
}
12 changes: 0 additions & 12 deletions bundle/direct/dresources/resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,6 @@ resources:
# https://github.com/databricks/terraform-provider-databricks/blob/4eba541abe1a9f50993ea7b9dd83874207e224a1/pipelines/resource_pipeline.go#L209
- field: ingestion_definition.ingest_from_uc_foreign_catalog
reason: immutable
# https://github.com/databricks/terraform-provider-databricks/blob/4eba541abe1a9f50993ea7b9dd83874207e224a1/pipelines/resource_pipeline.go#L204
- field: gateway_definition.connection_id
reason: immutable
- field: gateway_definition.connection_name
reason: immutable
- field: gateway_definition.gateway_storage_catalog
reason: immutable
- field: gateway_definition.gateway_storage_schema
reason: immutable
# https://github.com/databricks/terraform-provider-databricks/blob/4eba541abe1a9f50993ea7b9dd83874207e224a1/pipelines/resource_pipeline.go#L209
- field: ingestion_definition.ingest_from_uc_foreign_catalog
reason: immutable

ignore_remote_changes:
# "id" is handled in a special way before any fields changed
Expand Down
Loading