Skip to content

Commit

Permalink
Upgrade TF provider to 1.61.0 (#2011)
Browse files Browse the repository at this point in the history
## Changes
Upgraded to TF provider 1.61.0

### New Features and Improvements
- Added databricks_app resource and data source
(databricks/terraform-provider-databricks#4099).
- Added databricks_credentials resource and data source
  • Loading branch information
andrewnester authored Dec 13, 2024
1 parent 4e95cb2 commit 58dfa70
Show file tree
Hide file tree
Showing 20 changed files with 440 additions and 44 deletions.
56 changes: 36 additions & 20 deletions bundle/internal/tf/codegen/generator/walker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package generator

import (
"fmt"
"strings"

"slices"
"strings"

tfjson "github.com/hashicorp/terraform-json"
"github.com/iancoleman/strcase"
Expand Down Expand Up @@ -70,6 +69,25 @@ func nestedBlockKeys(block *tfjson.SchemaBlock) []string {
return keys
}

func nestedField(name []string, k string, isRef bool) field {
// Collect field properties.
fieldName := strcase.ToCamel(k)
fieldTypePrefix := ""
if isRef {
fieldTypePrefix = "*"
} else {
fieldTypePrefix = "[]"
}
fieldType := fmt.Sprintf("%s%s", fieldTypePrefix, strings.Join(append(name, strcase.ToCamel(k)), ""))
fieldTag := fmt.Sprintf("%s,omitempty", k)

return field{
Name: fieldName,
Type: fieldType,
Tag: fieldTag,
}
}

func (w *walker) walk(block *tfjson.SchemaBlock, name []string) error {
// Produce nested types before this block itself.
// This ensures types are defined before they are referenced.
Expand All @@ -91,10 +109,24 @@ func (w *walker) walk(block *tfjson.SchemaBlock, name []string) error {
v := block.Attributes[k]

// Assert the attribute type is always set.
if v.AttributeType == cty.NilType {
if v.AttributeType == cty.NilType && v.AttributeNestedType == nil {
return fmt.Errorf("unexpected nil type for attribute %s", k)
}

// If there is a nested type, walk it and continue to next attribute.
if v.AttributeNestedType != nil {
nestedBlock := &tfjson.SchemaBlock{
Attributes: v.AttributeNestedType.Attributes,
}
err := w.walk(nestedBlock, append(name, strcase.ToCamel(k)))
if err != nil {
return err
}
// Append to list of fields for type.
typ.Fields = append(typ.Fields, nestedField(name, k, v.AttributeNestedType.NestingMode == tfjson.SchemaNestingModeSingle))
continue
}

// Collect field properties.
fieldName := strcase.ToCamel(k)
fieldType := processAttributeType(v.AttributeType)
Expand All @@ -117,24 +149,8 @@ func (w *walker) walk(block *tfjson.SchemaBlock, name []string) error {
// Declare nested blocks.
for _, k := range nestedBlockKeys(block) {
v := block.NestedBlocks[k]

// Collect field properties.
fieldName := strcase.ToCamel(k)
fieldTypePrefix := ""
if v.MaxItems == 1 {
fieldTypePrefix = "*"
} else {
fieldTypePrefix = "[]"
}
fieldType := fmt.Sprintf("%s%s", fieldTypePrefix, strings.Join(append(name, strcase.ToCamel(k)), ""))
fieldTag := fmt.Sprintf("%s,omitempty", k)

// Append to list of fields for type.
typ.Fields = append(typ.Fields, field{
Name: fieldName,
Type: fieldType,
Tag: fieldTag,
})
typ.Fields = append(typ.Fields, nestedField(name, k, v.MaxItems == 1))
}

// Append type to list of structs.
Expand Down
2 changes: 1 addition & 1 deletion bundle/internal/tf/codegen/schema/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package schema

const ProviderVersion = "1.59.0"
const ProviderVersion = "1.61.0"
6 changes: 3 additions & 3 deletions bundle/internal/tf/codegen/templates/root.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const ProviderVersion = "{{ .ProviderVersion }}"

func NewRoot() *Root {
return &Root{
Terraform: map[string]interface{}{
"required_providers": map[string]interface{}{
"databricks": map[string]interface{}{
Terraform: map[string]any{
"required_providers": map[string]any{
"databricks": map[string]any{
"source": ProviderSource,
"version": ProviderVersion,
},
Expand Down
107 changes: 107 additions & 0 deletions bundle/internal/tf/schema/data_source_app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Generated from Databricks Terraform provider schema. DO NOT EDIT.

package schema

type DataSourceAppAppActiveDeploymentDeploymentArtifacts struct {
SourceCodePath string `json:"source_code_path,omitempty"`
}

type DataSourceAppAppActiveDeploymentStatus struct {
Message string `json:"message,omitempty"`
State string `json:"state,omitempty"`
}

type DataSourceAppAppActiveDeployment struct {
CreateTime string `json:"create_time,omitempty"`
Creator string `json:"creator,omitempty"`
DeploymentArtifacts *DataSourceAppAppActiveDeploymentDeploymentArtifacts `json:"deployment_artifacts,omitempty"`
DeploymentId string `json:"deployment_id,omitempty"`
Mode string `json:"mode,omitempty"`
SourceCodePath string `json:"source_code_path,omitempty"`
Status *DataSourceAppAppActiveDeploymentStatus `json:"status,omitempty"`
UpdateTime string `json:"update_time,omitempty"`
}

type DataSourceAppAppAppStatus struct {
Message string `json:"message,omitempty"`
State string `json:"state,omitempty"`
}

type DataSourceAppAppComputeStatus struct {
Message string `json:"message,omitempty"`
State string `json:"state,omitempty"`
}

type DataSourceAppAppPendingDeploymentDeploymentArtifacts struct {
SourceCodePath string `json:"source_code_path,omitempty"`
}

type DataSourceAppAppPendingDeploymentStatus struct {
Message string `json:"message,omitempty"`
State string `json:"state,omitempty"`
}

type DataSourceAppAppPendingDeployment struct {
CreateTime string `json:"create_time,omitempty"`
Creator string `json:"creator,omitempty"`
DeploymentArtifacts *DataSourceAppAppPendingDeploymentDeploymentArtifacts `json:"deployment_artifacts,omitempty"`
DeploymentId string `json:"deployment_id,omitempty"`
Mode string `json:"mode,omitempty"`
SourceCodePath string `json:"source_code_path,omitempty"`
Status *DataSourceAppAppPendingDeploymentStatus `json:"status,omitempty"`
UpdateTime string `json:"update_time,omitempty"`
}

type DataSourceAppAppResourcesJob struct {
Id string `json:"id"`
Permission string `json:"permission"`
}

type DataSourceAppAppResourcesSecret struct {
Key string `json:"key"`
Permission string `json:"permission"`
Scope string `json:"scope"`
}

type DataSourceAppAppResourcesServingEndpoint struct {
Name string `json:"name"`
Permission string `json:"permission"`
}

type DataSourceAppAppResourcesSqlWarehouse struct {
Id string `json:"id"`
Permission string `json:"permission"`
}

type DataSourceAppAppResources struct {
Description string `json:"description,omitempty"`
Job *DataSourceAppAppResourcesJob `json:"job,omitempty"`
Name string `json:"name"`
Secret *DataSourceAppAppResourcesSecret `json:"secret,omitempty"`
ServingEndpoint *DataSourceAppAppResourcesServingEndpoint `json:"serving_endpoint,omitempty"`
SqlWarehouse *DataSourceAppAppResourcesSqlWarehouse `json:"sql_warehouse,omitempty"`
}

type DataSourceAppApp struct {
ActiveDeployment *DataSourceAppAppActiveDeployment `json:"active_deployment,omitempty"`
AppStatus *DataSourceAppAppAppStatus `json:"app_status,omitempty"`
ComputeStatus *DataSourceAppAppComputeStatus `json:"compute_status,omitempty"`
CreateTime string `json:"create_time,omitempty"`
Creator string `json:"creator,omitempty"`
DefaultSourceCodePath string `json:"default_source_code_path,omitempty"`
Description string `json:"description,omitempty"`
Name string `json:"name"`
PendingDeployment *DataSourceAppAppPendingDeployment `json:"pending_deployment,omitempty"`
Resources []DataSourceAppAppResources `json:"resources,omitempty"`
ServicePrincipalClientId string `json:"service_principal_client_id,omitempty"`
ServicePrincipalId int `json:"service_principal_id,omitempty"`
ServicePrincipalName string `json:"service_principal_name,omitempty"`
UpdateTime string `json:"update_time,omitempty"`
Updater string `json:"updater,omitempty"`
Url string `json:"url,omitempty"`
}

type DataSourceApp struct {
App *DataSourceAppApp `json:"app,omitempty"`
Name string `json:"name"`
}
106 changes: 106 additions & 0 deletions bundle/internal/tf/schema/data_source_apps.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Generated from Databricks Terraform provider schema. DO NOT EDIT.

package schema

type DataSourceAppsAppActiveDeploymentDeploymentArtifacts struct {
SourceCodePath string `json:"source_code_path,omitempty"`
}

type DataSourceAppsAppActiveDeploymentStatus struct {
Message string `json:"message,omitempty"`
State string `json:"state,omitempty"`
}

type DataSourceAppsAppActiveDeployment struct {
CreateTime string `json:"create_time,omitempty"`
Creator string `json:"creator,omitempty"`
DeploymentArtifacts *DataSourceAppsAppActiveDeploymentDeploymentArtifacts `json:"deployment_artifacts,omitempty"`
DeploymentId string `json:"deployment_id,omitempty"`
Mode string `json:"mode,omitempty"`
SourceCodePath string `json:"source_code_path,omitempty"`
Status *DataSourceAppsAppActiveDeploymentStatus `json:"status,omitempty"`
UpdateTime string `json:"update_time,omitempty"`
}

type DataSourceAppsAppAppStatus struct {
Message string `json:"message,omitempty"`
State string `json:"state,omitempty"`
}

type DataSourceAppsAppComputeStatus struct {
Message string `json:"message,omitempty"`
State string `json:"state,omitempty"`
}

type DataSourceAppsAppPendingDeploymentDeploymentArtifacts struct {
SourceCodePath string `json:"source_code_path,omitempty"`
}

type DataSourceAppsAppPendingDeploymentStatus struct {
Message string `json:"message,omitempty"`
State string `json:"state,omitempty"`
}

type DataSourceAppsAppPendingDeployment struct {
CreateTime string `json:"create_time,omitempty"`
Creator string `json:"creator,omitempty"`
DeploymentArtifacts *DataSourceAppsAppPendingDeploymentDeploymentArtifacts `json:"deployment_artifacts,omitempty"`
DeploymentId string `json:"deployment_id,omitempty"`
Mode string `json:"mode,omitempty"`
SourceCodePath string `json:"source_code_path,omitempty"`
Status *DataSourceAppsAppPendingDeploymentStatus `json:"status,omitempty"`
UpdateTime string `json:"update_time,omitempty"`
}

type DataSourceAppsAppResourcesJob struct {
Id string `json:"id"`
Permission string `json:"permission"`
}

type DataSourceAppsAppResourcesSecret struct {
Key string `json:"key"`
Permission string `json:"permission"`
Scope string `json:"scope"`
}

type DataSourceAppsAppResourcesServingEndpoint struct {
Name string `json:"name"`
Permission string `json:"permission"`
}

type DataSourceAppsAppResourcesSqlWarehouse struct {
Id string `json:"id"`
Permission string `json:"permission"`
}

type DataSourceAppsAppResources struct {
Description string `json:"description,omitempty"`
Job *DataSourceAppsAppResourcesJob `json:"job,omitempty"`
Name string `json:"name"`
Secret *DataSourceAppsAppResourcesSecret `json:"secret,omitempty"`
ServingEndpoint *DataSourceAppsAppResourcesServingEndpoint `json:"serving_endpoint,omitempty"`
SqlWarehouse *DataSourceAppsAppResourcesSqlWarehouse `json:"sql_warehouse,omitempty"`
}

type DataSourceAppsApp struct {
ActiveDeployment *DataSourceAppsAppActiveDeployment `json:"active_deployment,omitempty"`
AppStatus *DataSourceAppsAppAppStatus `json:"app_status,omitempty"`
ComputeStatus *DataSourceAppsAppComputeStatus `json:"compute_status,omitempty"`
CreateTime string `json:"create_time,omitempty"`
Creator string `json:"creator,omitempty"`
DefaultSourceCodePath string `json:"default_source_code_path,omitempty"`
Description string `json:"description,omitempty"`
Name string `json:"name"`
PendingDeployment *DataSourceAppsAppPendingDeployment `json:"pending_deployment,omitempty"`
Resources []DataSourceAppsAppResources `json:"resources,omitempty"`
ServicePrincipalClientId string `json:"service_principal_client_id,omitempty"`
ServicePrincipalId int `json:"service_principal_id,omitempty"`
ServicePrincipalName string `json:"service_principal_name,omitempty"`
UpdateTime string `json:"update_time,omitempty"`
Updater string `json:"updater,omitempty"`
Url string `json:"url,omitempty"`
}

type DataSourceApps struct {
App []DataSourceAppsApp `json:"app,omitempty"`
}
8 changes: 4 additions & 4 deletions bundle/internal/tf/schema/data_source_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,30 @@ type DataSourceFunctionsFunctions struct {
FullDataType string `json:"full_data_type,omitempty"`
FullName string `json:"full_name,omitempty"`
FunctionId string `json:"function_id,omitempty"`
InputParams []DataSourceFunctionsFunctionsInputParams `json:"input_params,omitempty"`
IsDeterministic bool `json:"is_deterministic,omitempty"`
IsNullCall bool `json:"is_null_call,omitempty"`
MetastoreId string `json:"metastore_id,omitempty"`
Name string `json:"name,omitempty"`
Owner string `json:"owner,omitempty"`
ParameterStyle string `json:"parameter_style,omitempty"`
Properties string `json:"properties,omitempty"`
ReturnParams []DataSourceFunctionsFunctionsReturnParams `json:"return_params,omitempty"`
RoutineBody string `json:"routine_body,omitempty"`
RoutineDefinition string `json:"routine_definition,omitempty"`
RoutineDependencies []DataSourceFunctionsFunctionsRoutineDependencies `json:"routine_dependencies,omitempty"`
SchemaName string `json:"schema_name,omitempty"`
SecurityType string `json:"security_type,omitempty"`
SpecificName string `json:"specific_name,omitempty"`
SqlDataAccess string `json:"sql_data_access,omitempty"`
SqlPath string `json:"sql_path,omitempty"`
UpdatedAt int `json:"updated_at,omitempty"`
UpdatedBy string `json:"updated_by,omitempty"`
InputParams []DataSourceFunctionsFunctionsInputParams `json:"input_params,omitempty"`
ReturnParams []DataSourceFunctionsFunctionsReturnParams `json:"return_params,omitempty"`
RoutineDependencies []DataSourceFunctionsFunctionsRoutineDependencies `json:"routine_dependencies,omitempty"`
}

type DataSourceFunctions struct {
CatalogName string `json:"catalog_name"`
Functions []DataSourceFunctionsFunctions `json:"functions,omitempty"`
IncludeBrowse bool `json:"include_browse,omitempty"`
SchemaName string `json:"schema_name"`
Functions []DataSourceFunctionsFunctions `json:"functions,omitempty"`
}
5 changes: 3 additions & 2 deletions bundle/internal/tf/schema/data_source_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package schema

type DataSourceJobs struct {
Id string `json:"id,omitempty"`
Ids map[string]string `json:"ids,omitempty"`
Id string `json:"id,omitempty"`
Ids map[string]string `json:"ids,omitempty"`
JobNameContains string `json:"job_name_contains,omitempty"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ type DataSourceNotificationDestinationsNotificationDestinations struct {

type DataSourceNotificationDestinations struct {
DisplayNameContains string `json:"display_name_contains,omitempty"`
Type string `json:"type,omitempty"`
NotificationDestinations []DataSourceNotificationDestinationsNotificationDestinations `json:"notification_destinations,omitempty"`
Type string `json:"type,omitempty"`
}
2 changes: 1 addition & 1 deletion bundle/internal/tf/schema/data_source_registered_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type DataSourceRegisteredModelModelInfoAliases struct {
}

type DataSourceRegisteredModelModelInfo struct {
Aliases []DataSourceRegisteredModelModelInfoAliases `json:"aliases,omitempty"`
BrowseOnly bool `json:"browse_only,omitempty"`
CatalogName string `json:"catalog_name,omitempty"`
Comment string `json:"comment,omitempty"`
Expand All @@ -21,7 +22,6 @@ type DataSourceRegisteredModelModelInfo struct {
StorageLocation string `json:"storage_location,omitempty"`
UpdatedAt int `json:"updated_at,omitempty"`
UpdatedBy string `json:"updated_by,omitempty"`
Aliases []DataSourceRegisteredModelModelInfoAliases `json:"aliases,omitempty"`
}

type DataSourceRegisteredModel struct {
Expand Down
Loading

0 comments on commit 58dfa70

Please sign in to comment.