contract

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package contract turns an inventory into the datatf Terraform module contract: tfvars values, import blocks, and the export report.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Header(scope Scope, host string) []string

Header returns the generated-file banner for tfvars output.

func ImportsHeader

func ImportsHeader(host string) []string

ImportsHeader returns the banner for imports.tf.

func RenderImports

func RenderImports(imports []Import, rootModule string, header []string) []byte

RenderImports renders Terraform import blocks. rootModule is the name of the composition module instance in the target root ("workspace" yields module.workspace.module.catalog["x"]...); empty addresses the per-resource modules directly.

func RenderVariable

func RenderVariable(v Variable, header []string) ([]byte, error)

RenderVariable renders one tfvars block as formatted HCL. Values pass through JSON so the same shape feeds export.json, which keeps the two outputs in lockstep.

func RenderVariables

func RenderVariables(variables []Variable, header []string) ([]byte, error)

RenderVariables renders populated variables into one formatted tfvars file.

Types

type Access

type Access map[string][]string

Access is principal -> privileges.

type AzureManagedIdentity

type AzureManagedIdentity struct {
	AccessConnectorID string `json:"access_connector_id"`
	ManagedIdentityID string `json:"managed_identity_id,omitempty"`
}

type CatalogSettings

type CatalogSettings struct {
	IsolationMode string            `json:"isolation_mode"`
	Owner         string            `json:"owner"`
	Comment       string            `json:"comment,omitempty"`
	StorageRoot   string            `json:"storage_root,omitempty"`
	Properties    map[string]string `json:"properties,omitempty"`
}

type ClusterPolicySettings

type ClusterPolicySettings struct {
	Description                     string       `json:"description,omitempty"`
	Definition                      any          `json:"definition,omitempty"`
	PolicyFamilyID                  string       `json:"policy_family_id,omitempty"`
	PolicyFamilyDefinitionOverrides any          `json:"policy_family_definition_overrides,omitempty"`
	MaxClustersPerUser              int64        `json:"max_clusters_per_user,omitempty"`
	Libraries                       []any        `json:"libraries"`
	Permissions                     []Permission `json:"permissions"`
}

type Exclusion

type Exclusion struct {
	Area      string `json:"area"`
	Name      string `json:"name"`
	Ownership string `json:"ownership"`
}

Exclusion is a UC securable that was read successfully but belongs to the other scope.

type Export

type Export struct {
	Scope    Scope       `json:"scope"`
	Tfvars   *Tfvars     `json:"tfvars"`
	Imports  []Import    `json:"imports"`
	Excluded []Exclusion `json:"excluded"`
}

Export is the complete result of one export.

func Build

func Build(inv *inventory.Inventory, scope Scope) (*Export, []inventory.Issue)

Build selects the inventory objects that belong to scope and shapes them into tfvars plus matching import blocks. Imports are derived from the same selection, so the two never disagree.

type ExternalLocationSettings

type ExternalLocationSettings struct {
	URL              string `json:"url"`
	CredentialName   string `json:"credential_name"`
	IsolationMode    string `json:"isolation_mode"`
	Owner            string `json:"owner"`
	Comment          string `json:"comment,omitempty"`
	ReadOnly         bool   `json:"read_only"`
	Fallback         bool   `json:"fallback"`
	EnableFileEvents bool   `json:"enable_file_events"`
}

type Import

type Import struct {
	Module   string `json:"module"`
	Key      string `json:"key"`
	Resource string `json:"resource"`
	// Index is nil, an int (count-gated "[0]"), or a string (for_each key).
	Index any    `json:"index,omitempty"`
	ID    string `json:"id"`
}

Import is one Terraform import block addressed inside the composition module.

type InstancePoolSettings

type InstancePoolSettings struct {
	NodeTypeID                         string            `json:"node_type_id"`
	MinIdleInstances                   int               `json:"min_idle_instances"`
	MaxCapacity                        int               `json:"max_capacity,omitempty"`
	IdleInstanceAutoterminationMinutes int               `json:"idle_instance_autotermination_minutes"`
	EnableElasticDisk                  bool              `json:"enable_elastic_disk"`
	PreloadedSparkVersions             []string          `json:"preloaded_spark_versions"`
	CustomTags                         map[string]string `json:"custom_tags,omitempty"`
	AzureAttributes                    any               `json:"azure_attributes,omitempty"`
	Permissions                        []Permission      `json:"permissions"`
}

type KeyvaultMetadata

type KeyvaultMetadata struct {
	ResourceID string `json:"resource_id"`
	DNSName    string `json:"dns_name"`
}

type Permission

type Permission struct {
	PermissionLevel      string `json:"permission_level"`
	GroupName            string `json:"group_name,omitempty"`
	UserName             string `json:"user_name,omitempty"`
	ServicePrincipalName string `json:"service_principal_name,omitempty"`
}

Permission is one direct permission on a workspace object. Exactly one principal field is set.

type PrincipalSettings

type PrincipalSettings struct {
	// DisplayName is set only when the map key had to be disambiguated.
	DisplayName             string `json:"display_name,omitempty"`
	AllowClusterCreate      bool   `json:"allow_cluster_create"`
	AllowInstancePoolCreate bool   `json:"allow_instance_pool_create"`
	DatabricksSQLAccess     bool   `json:"databricks_sql_access"`
	WorkspaceAccess         bool   `json:"workspace_access"`
	// WorkspaceConsume is mutually exclusive with the two access flags in the
	// provider, so it is only present when granted.
	WorkspaceConsume *bool `json:"workspace_consume,omitempty"`
}

type Report

type Report struct {
	Status      string              `json:"status"`
	ExportedAt  time.Time           `json:"exported_at"`
	Tool        string              `json:"tool"`
	Host        string              `json:"host"`
	UserName    string              `json:"user_name"`
	WorkspaceID int64               `json:"workspace_id"`
	MetastoreID string              `json:"metastore_id,omitempty"`
	Scope       Scope               `json:"scope,omitempty"`
	Resources   []string            `json:"resources"`
	Name        *string             `json:"name,omitempty"`
	Counts      map[string]int      `json:"counts"`
	Imports     int                 `json:"imports"`
	Issues      []inventory.Issue   `json:"issues"`
	Skipped     []inventory.Skipped `json:"skipped"`
	Excluded    []Exclusion         `json:"excluded"`
	Limitations map[string]string   `json:"limitations"`
}

Report is export-report.json. Status "partial" means at least one read or build step failed and the Terraform output is incomplete.

func NewReport

func NewReport(inv *inventory.Inventory, ex *Export, buildIssues []inventory.Issue, tool string, now time.Time) *Report

NewReport summarizes an inventory and, when ex is non-nil, the export built from it. buildIssues are issues raised while shaping tfvars.

type ResourceModule

type ResourceModule struct {
	Name   string
	Source string
	Values cty.Value
}

ResourceModule contains the selected inputs for one Registry resource module.

func ResourceModules

func ResourceModules(t *Tfvars) ([]ResourceModule, error)

ResourceModules adapts the same selection used by Build to individual module inputs.

type Scope

type Scope string

Scope selects which Terraform root the export feeds.

const (
	// ScopeWorkspace: workspace-native resources plus UC securables that are
	// ISOLATED and bound only to this workspace.
	ScopeWorkspace Scope = "workspace"
	// ScopeShared: UC securables that are OPEN or bound to zero or many
	// workspaces. No workspace-native resources.
	ScopeShared Scope = "shared"
)

type SecretScopeSettings

type SecretScopeSettings struct {
	// ACLs is principal -> permission. Nil when the ACLs could not be read.
	ACLs             map[string]string `json:"acls,omitempty"`
	KeyvaultMetadata *KeyvaultMetadata `json:"keyvault_metadata,omitempty"`
}

type StorageCredentialSettings

type StorageCredentialSettings struct {
	IsolationMode        string                `json:"isolation_mode"`
	Owner                string                `json:"owner"`
	Comment              string                `json:"comment,omitempty"`
	ReadOnly             bool                  `json:"read_only"`
	AzureManagedIdentity *AzureManagedIdentity `json:"azure_managed_identity,omitempty"`
}

type Tfvars

type Tfvars struct {
	Catalogs                map[string]CatalogSettings           `json:"catalogs"`
	CatalogAccess           map[string]Access                    `json:"catalog_access"`
	Schemas                 map[string][]string                  `json:"schemas"`
	SchemaAccess            map[string]map[string]Access         `json:"schema_access"`
	SchemaStorageRoots      map[string]map[string]string         `json:"schema_storage_roots"`
	SchemaComments          map[string]map[string]string         `json:"schema_comments"`
	StorageCredentials      map[string]StorageCredentialSettings `json:"storage_credentials"`
	StorageCredentialAccess map[string]Access                    `json:"storage_credential_access"`
	ExternalLocations       map[string]ExternalLocationSettings  `json:"external_locations"`
	ExternalLocationAccess  map[string]Access                    `json:"external_location_access"`
	WorkspaceBindings       map[string]WorkspaceBindingSettings  `json:"workspace_bindings"`
	ClusterPolicies         map[string]ClusterPolicySettings     `json:"cluster_policies,omitempty"`
	InstancePools           map[string]InstancePoolSettings      `json:"instance_pools,omitempty"`
	Warehouses              map[string]WarehouseSettings         `json:"warehouses,omitempty"`
	SecretScopes            map[string]SecretScopeSettings       `json:"secret_scopes,omitempty"`
	ServicePrincipals       map[string]PrincipalSettings         `json:"service_principals,omitempty"`
}

Tfvars is every module input the exporter can populate. Workspace-native maps are nil for the shared scope and are not emitted.

func (*Tfvars) Variables

func (t *Tfvars) Variables() []Variable

Variables returns the populated blocks in canonical order.

type Variable

type Variable struct {
	Name    string
	Value   any
	Comment []string
}

Variable is one tfvars block in emission order.

type WarehouseSettings

type WarehouseSettings struct {
	ClusterSize             string            `json:"cluster_size"`
	MinNumClusters          int               `json:"min_num_clusters"`
	MaxNumClusters          int               `json:"max_num_clusters"`
	AutoStopMins            int               `json:"auto_stop_mins"`
	WarehouseType           string            `json:"warehouse_type"`
	EnablePhoton            bool              `json:"enable_photon"`
	EnableServerlessCompute bool              `json:"enable_serverless_compute"`
	SpotInstancePolicy      string            `json:"spot_instance_policy,omitempty"`
	Tags                    map[string]string `json:"tags,omitempty"`
	Permissions             []Permission      `json:"permissions"`
}

type WorkspaceBindingSettings

type WorkspaceBindingSettings struct {
	WorkspaceID   int64  `json:"workspace_id"`
	SecurableName string `json:"securable_name"`
	SecurableType string `json:"securable_type"`
	BindingType   string `json:"binding_type"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL