migrate

package
v0.112.7 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TerraformToolName = "terraform"
	TofuToolName      = "tofu"
	TerraformDisplay  = "Terraform"
	OpenTofuDisplay   = "OpenTofu"
)

Tool names and display names

View Source
const (
	MinRequiredVersion      = "1.5"
	MinRemovedBlocksVersion = "1.7"
)

Version requirements

View Source
const (
	ProviderConfigFile     = "provider.tf"
	ImportConfigFile       = "imports.tf"
	RemovedBlocksFile      = "removals.tf"
	PipelineCloudRulesFile = "pcrs.tf"
)

File names

View Source
const (
	SeparatorLength = 80
	SeparatorChar   = "="
)

UI constants

View Source
const (
	ColorReset  = "\033[0m"
	ColorBold   = "\033[1m"
	ColorCyan   = "\033[1;36m"
	ColorYellow = "\033[1;33m"
)

ANSI color codes

View Source
const (
	MigrationRecommendationsTitle = "IMPORTANT: CI/CD MIGRATION RECOMMENDATIONS"
	SuccessMessage                = "✅ Local workspace setup completed successfully!"
	MigrationCompleteMessage      = "Migration workspace prepared successfully! 🎉"
	AccountMismatchWarning        = "⚠️  WARNING: ACCOUNT ID MISMATCH DETECTED"
)

Messages

View Source
const ImportBlockTemplate = `import {
  to = newrelic_pipeline_cloud_rule.%s
  id = "%s"
}`

Import block template

View Source
const OptionalRegionEnvVar = "NEW_RELIC_REGION"
View Source
const ProviderConfigTemplate = `` /* 305-byte string literal not displayed */

Provider configuration template

View Source
const RemovedBlockTemplate = `removed {
  from = newrelic_nrql_drop_rule.%s

  lifecycle {
    destroy = false
  }
}`

Removed block template

Variables

View Source
var Command = &cobra.Command{
	Use:   "migrate",
	Short: "Commands to support migration of New Relic Resources for EOLs and more.",
}
View Source
var ConflictingFilePatterns = []string{
	".tfstate",
	".tfstate.backup",
	".terraform",
	ProviderConfigFile,
	ImportConfigFile,
	PipelineCloudRulesFile,
}

File patterns for workspace validation (removed blocks file only included when needed)

View Source
var LoadingDots = []string{".", "..", "...", "...."}

Loading animation

View Source
var RequiredEnvVars = []string{"NEW_RELIC_ACCOUNT_ID", "NEW_RELIC_API_KEY"}

Environment variables

Functions

func GenerateImportConfigFromIDs added in v0.106.0

func GenerateImportConfigFromIDs(pipelineRuleIDs []string) string

func GenerateImportConfigFromResources added in v0.106.0

func GenerateImportConfigFromResources(resources []string) string

func GetConflictingFilePatternsWithRemoved

func GetConflictingFilePatternsWithRemoved() []string

GetConflictingFilePatternsWithRemoved returns file patterns including removed blocks file

func ValidateAndExtractPipelineRuleIDs added in v0.106.0

func ValidateAndExtractPipelineRuleIDs(workspacePath string, resources []string, config *ToolConfig) ([]string, error)

func WriteConfigToFile added in v0.106.0

func WriteConfigToFile(workspacePath, config, fileName string)

Types

type CommandContext added in v0.106.0

type CommandContext struct {
	ToolConfig    *ToolConfig
	WorkspacePath string
	SkipPrompts   bool
	CommandType   CommandType
	ResourceIDs   []string
}

CommandContext holds shared context and configuration for commands

func NewCommandContext added in v0.106.0

func NewCommandContext(useTofu bool, workspacePath string, skipPrompts bool, cmdType CommandType, resourceIDs []string) (*CommandContext, error)

NewCommandContext creates and initializes a command context

func (*CommandContext) CheckProviderVersion added in v0.106.0

func (ctx *CommandContext) CheckProviderVersion() error

CheckProviderVersion validates New Relic provider version for update operations

func (*CommandContext) ExecuteCommand added in v0.106.0

func (ctx *CommandContext) ExecuteCommand(command, actionName string) error

ExecuteCommand runs a command with proper logging and immediate output display

func (*CommandContext) ExecuteStandardFlow added in v0.106.0

func (ctx *CommandContext) ExecuteStandardFlow(planCmd, actionCmd string, resources []string) error

ExecuteStandardFlow runs the standard plan->confirm->action workflow with improved UX

func (*CommandContext) GenerateTargetCommands added in v0.106.0

func (ctx *CommandContext) GenerateTargetCommands(resources []string) (planCmd, actionCmd string)

GenerateTargetCommands creates terraform commands with target flags This function validates resources and is used only for display purposes

func (*CommandContext) GetDropRuleResources added in v0.106.0

func (ctx *CommandContext) GetDropRuleResources() ([]string, error)

GetDropRuleResources retrieves NRQL drop rule resources from state

func (*CommandContext) InitializeCommand added in v0.106.0

func (ctx *CommandContext) InitializeCommand() error

InitializeCommand performs common initialization steps

func (*CommandContext) PrintCommands added in v0.106.0

func (ctx *CommandContext) PrintCommands(planCmd, actionCmd string)

PrintCommands displays generated commands to the user

func (*CommandContext) PrintCommandsForResourceIDs added in v0.106.0

func (ctx *CommandContext) PrintCommandsForResourceIDs()

PrintCommandsForResourceIDs displays commands for provided resource identifiers

func (*CommandContext) PromptForActionConfirmation added in v0.106.0

func (ctx *CommandContext) PromptForActionConfirmation() bool

PromptForActionConfirmation asks for confirmation before destructive actions

func (*CommandContext) PromptForExecution added in v0.106.0

func (ctx *CommandContext) PromptForExecution() bool

PromptForExecution asks user if they want to execute commands

func (*CommandContext) ValidateResults added in v0.106.0

func (ctx *CommandContext) ValidateResults(resources []string)

ValidateResults performs post-action validation based on command type

type CommandType added in v0.106.0

type CommandType int

CommandType represents the type of operation being performed

const (
	CommandUpdate CommandType = iota
	CommandImport
	CommandDelist // Removed CommandDestroy since we use CommandDelist for safe state removal
)

type DropRuleInput

type DropRuleInput struct {
	DropRuleResourceIDs []DropRuleResource `json:"drop_rule_resource_ids"`
}

DropRuleInput represents the input structure containing drop rule resources

type DropRuleResource

type DropRuleResource struct {
	Name                      string `json:"name"`
	ID                        string `json:"id"`
	PipelineCloudRuleEntityID string `json:"pipeline_cloud_rule_entity_id"`
}

DropRuleResource represents a single drop rule resource with its metadata

type TerraformState added in v0.106.0

type TerraformState struct {
	Values struct {
		RootModule struct {
			Resources []struct {
				Address string                 `json:"address"`
				Values  map[string]interface{} `json:"values"`
			} `json:"resources"`
		} `json:"root_module"`
	} `json:"values"`
}

type ToolConfig

type ToolConfig struct {
	UseTofu     bool
	ToolName    string
	DisplayName string
}

ToolConfig holds configuration for the Terraform/OpenTofu tool being used

Jump to

Keyboard shortcuts

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