migrate

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2025 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConflictingImports = map[string]ConflictResolution{
	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry": {
		ConflictsWith: "github.com/hashicorp/terraform-provider-aws/internal/retry",
		Resolution: ImportSpec{
			Path: "github.com/hashicorp/terraform-provider-aws/internal/retry",
			Name: "intretry",
		},
		PrefixMapping: map[string]string{
			"retry": "intretry",
		},
	},
}

ConflictingImports defines import conflicts that need special handling

View Source
var MigrationPatterns = []string{
	`smerr\.EnrichAppend`,
	`smarterr\.EnrichAppend`,
	`response\.Diagnostics\.Append`,
	`resp\.Diagnostics\.Append`,
	`response\.Diagnostics\.AddError`,
	`resp\.Diagnostics\.AddError`,
	`sdkdiag\.AppendFromErr`,
	`sdkdiag\.AppendErrorf`,
	`create\.AppendDiagError`,
	`create\.AddError`,
	`create\.ProblemStandardMessage`,
	`return.*fmt\.Errorf`,
	`fmt\.Errorf.*(?i)unexpected format`,
	`return append\(diags,`,
	`tfresource\.NotFound`,
	`return nil, "", err`,
	`(?m)return nil, err$`,
	`return nil, &retry\.NotFoundError`,
	`return nil, tfresource\.NewEmptyResultError`,
	`return tfresource\.AssertSingleValueResult`,
}

MigrationPatterns defines the patterns that indicate code needs migration

View Source
var RequiredImports = []ImportSpec{
	{
		Path: "github.com/YakDriver/smarterr",
		Name: "",
	},
	{
		Path: "github.com/hashicorp/terraform-provider-aws/internal/smerr",
		Name: "",
	},
	{
		Path: "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag",
		Name: "",
	},
}

RequiredImports defines the imports needed for smarterr migrations

Functions

func NeedsMigration

func NeedsMigration(content string) bool

NeedsMigration is a convenience function for checking if content needs migration

Types

type ConflictResolution

type ConflictResolution struct {
	ConflictsWith string            // The import path that conflicts
	Resolution    ImportSpec        // How to resolve the conflict
	PrefixMapping map[string]string // How to change prefixes in code
}

ConflictResolution defines how to resolve import conflicts

type ImportInfo

type ImportInfo struct {
	Path string // Import path without quotes
	Name string // Import name/alias (empty for default)
}

ImportInfo represents information about an import

type ImportManager

type ImportManager struct {
	// contains filtered or unexported fields
}

ImportManager handles Go import management for migrations

func NewImportManager

func NewImportManager(content string) *ImportManager

NewImportManager creates a new import manager for the given content

func (*ImportManager) AddAliasedRetryImport

func (im *ImportManager) AddAliasedRetryImport() string

AddAliasedRetryImport adds the internal retry import with an alias (legacy method for compatibility)

func (*ImportManager) AddImportWithAlias

func (im *ImportManager) AddImportWithAlias(path, alias string) string

AddImportWithAlias adds an import with a specific alias

func (*ImportManager) AddRequiredImports

func (im *ImportManager) AddRequiredImports() string

AddRequiredImports adds all required imports for smarterr migrations

func (*ImportManager) GetImports

func (im *ImportManager) GetImports() ([]ImportInfo, error)

GetImports returns all imports found in the content using AST parsing

func (*ImportManager) GetRetryPrefix

func (im *ImportManager) GetRetryPrefix() string

GetRetryPrefix returns the appropriate retry prefix based on import conflicts

func (*ImportManager) HasConflictingRetryImport

func (im *ImportManager) HasConflictingRetryImport() bool

HasConflictingRetryImport checks if there's a conflicting retry import (legacy method for compatibility)

func (*ImportManager) ResolveImportConflicts

func (im *ImportManager) ResolveImportConflicts() (string, map[string]string)

ResolveImportConflicts resolves known import conflicts and returns the prefix mapping

type ImportSpec

type ImportSpec struct {
	Path string // Import path
	Name string // Import name/alias (empty for default)
}

ImportSpec represents an import specification

type MigrationDetector

type MigrationDetector struct{}

MigrationDetector handles detection of code that needs migration

func NewMigrationDetector

func NewMigrationDetector() *MigrationDetector

NewMigrationDetector creates a new migration detector

func (*MigrationDetector) NeedsMigration

func (md *MigrationDetector) NeedsMigration(content string) bool

NeedsMigration checks if the given content contains patterns that need migration

type Migrator

type Migrator struct {
	// contains filtered or unexported fields
}

Migrator handles the overall migration process

func NewMigrator

func NewMigrator(opts MigratorOptions) *Migrator

NewMigrator creates a new migrator with the given options

func (*Migrator) MigrateContent

func (m *Migrator) MigrateContent(content string) string

MigrateContent applies all pattern groups to the content in order

type MigratorOptions

type MigratorOptions struct {
	DryRun  bool
	Verbose bool
}

MigratorOptions configures the migration behavior

type Pattern

type Pattern struct {
	Name        string
	Description string
	Regex       *regexp.Regexp
	Replace     func(string) string // For complex replacements
	Template    string              // For simple replacements
}

Pattern represents a single transformation rule

type PatternGroup

type PatternGroup struct {
	Name     string
	Patterns []Pattern
	Order    int // Execution order
}

PatternGroup represents a logical group of related patterns

func CreateBareErrorPatterns

func CreateBareErrorPatterns() PatternGroup

CreateBareErrorPatterns creates patterns for bare error returns

func CreateFrameworkPatterns

func CreateFrameworkPatterns() PatternGroup

CreateFrameworkPatterns creates patterns for Terraform Plugin Framework

func CreateHelperPatterns

func CreateHelperPatterns() PatternGroup

CreateHelperPatterns creates patterns for helper functions and standard library

func CreateImportPatterns

func CreateImportPatterns() PatternGroup

CreateImportPatterns creates patterns for import-related transformations

func CreateSDKv2Patterns

func CreateSDKv2Patterns() PatternGroup

CreateSDKv2Patterns creates patterns for Terraform Plugin SDKv2

func CreateTfresourcePatterns

func CreateTfresourcePatterns() PatternGroup

CreateTfresourcePatterns creates patterns for tfresource-related transformations

func LoadPatterns

func LoadPatterns() []PatternGroup

LoadPatterns loads all pattern groups from the registry

Jump to

Keyboard shortcuts

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