databricks / terraform-provider-databricks

Databricks Terraform Provider
https://registry.terraform.io/providers/databricks/databricks/latest
Other
456 stars 393 forks source link

[ISSUE] Gracefully handle incorrect aliases in `CustomizableSchema` #4129

Open alexott opened 1 month ago

alexott commented 1 month ago

I had a code that needs an alias and at some point I was need to change struct name from queryStruct to QueryStruct, but I forgot to update Aliases, so after renaming it stay the same

func (QueryStruct) Aliases() map[string]map[string]string {
    return map[string]map[string]string{
        "sql.queryStruct": queryAliasMap,
    }
}

And it leads to the crash in StructToSchema, like this:

github.com/databricks/terraform-provider-databricks/common.MustSchemaPath(...)
    /Users/.../terraform-provider-databricks/common/reflect_resource.go:232
github.com/databricks/terraform-provider-databricks/common.(*CustomizableSchema).SchemaPath(0x14000310600, {0x14000113ea0, 0x2, 0x2})
    /Users/.../terraform-provider-databricks/common/customizable_schema.go:62 +0x10c
github.com/databricks/terraform-provider-databricks/sql.QueryStruct.CustomizeSchema({{0x0, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, ...}, ...}}, ...)
    /Users/.../terraform-provider-databricks/sql/resource_query.go:45 +0x460
github.com/databricks/terraform-provider-databricks/common.resourceProviderStructToSchemaInternal({0x1046fbe98, 0x140005ab040}, {{0x103ef1d20, 0x0, 0x0}, {0x103ef1d20, 0x0, 0x0}})
    /Users/.../terraform-provider-databricks/common/reflect_resource.go:155 +0x560
github.com/databricks/terraform-provider-databricks/common.resourceProviderStructToSchema({0x1046fbe98, 0x140005ab040}, {{0x103ef1d20, 0x0, 0x0}, {0x103ef1d20, 0x0, 0x0}})
    /Users/.../terraform-provider-databricks/common/reflect_resource.go:132 +0x48
github.com/databricks/terraform-provider-databricks/common.StructToSchema({0x103328040?, 0x140005ab040?}, 0x0)
    /Users/.../terraform-provider-databricks/common/reflect_resource.go:252 +0x94
github.com/databricks/terraform-provider-databricks/sql.ResourceQuery()
    /Users/.../terraform-provider-databricks/sql/resource_query.go:95 +0x74
github.com/databricks/terraform-provider-databricks/internal/providers/sdkv2.DatabricksProvider()
    /Users/.../terraform-provider-databricks/internal/providers/sdkv2/sdkv2.go:192 +0x788c
github.com/databricks/terraform-provider-databricks/internal/providers.GetProviderServer({0x1034caf40, 0x103ef1d20}, {0x0, 0x0, 0x140003afed8?})
    /Users/.../terraform-provider-databricks/internal/providers/providers.go:63 +0x9c
main.main()
    /Users/.../terraform-provider-databricks/main.go:41 +0x268

We need to gracefully handle such cases: