migration

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateFromPlan

func GenerateFromPlan(planJSON []byte, dir string) ([]byte, error)

GenerateFromPlan returns bytes of a migration file which reverts a given planned changes. The dir is set to a dir attribute in a migration file.

func NewDefaultDictionary

func NewDefaultDictionary() *schema.Dictionary

NewDefaultDictionary returns a default built-in Dictionary.

Types

type Conflict

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

Conflict is a planned resource change. It also has a status of whether it has already been resolved.

func NewConflict

func NewConflict(rc *tfjson.ResourceChange) *Conflict

NewConflict returns a new instance of Conflict.

func (*Conflict) Address

func (c *Conflict) Address() string

Address returns an absolute address. (e.g. aws_s3_bucket_acl.example)

func (*Conflict) IsResolved

func (c *Conflict) IsResolved() bool

IsResolved return true if the conflict has already been resolved.

func (*Conflict) MarkAsResolved

func (c *Conflict) MarkAsResolved()

MarkAsResolved marks the conflict as resolved.

func (*Conflict) PlannedActionType

func (c *Conflict) PlannedActionType() string

PlannedActionType returns a string that represents the type of action. Currently some actions that may be included in the plan are not supported. It returns "unknown" if not supported. The valid values are:

  • create
  • unknown

func (*Conflict) ResourceAfter

func (c *Conflict) ResourceAfter() (schema.Resource, error)

ResourceAfter retruns a planned resource after change. It doesn't contains attributes known after apply.

func (*Conflict) ResourceType

func (c *Conflict) ResourceType() string

ResourceType returns a resource type. (e.g. aws_s3_bucket_acl)

type Plan

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

Plan is a type which wraps Plan of terraform-json and exposes some operations which we need.

func NewPlan

func NewPlan(planJSON []byte) (*Plan, error)

NewPlan parses a plan file in JSON format and creates a new instance of Plan.

func (*Plan) ResourceChanges

func (p *Plan) ResourceChanges() []*tfjson.ResourceChange

ResourceChanges returns a list of changes in plan.

type PlanAnalyzer

type PlanAnalyzer interface {
	// Analyze analyzes a given plan and generates a state migration so that
	// the plan results in no changes.
	// The dir is set to a dir attribute in a migration file.
	Analyze(plan *Plan, dir string) (*StateMigration, error)
}

PlanAnalyzer is an interface that abstracts the analysis rules of plan.

func NewDefaultPlanAnalyzer

func NewDefaultPlanAnalyzer(d *schema.Dictionary) PlanAnalyzer

NewDefaultPlanAnalyzer returns a new instance of defaultPlanAnalyzer. The current implementation only supports import, but allows us to compose multiple resolvers for future extension.

type Resolver

type Resolver interface {
	// Resolve tries to resolve some conflicts in a given subject and returns the
	// updated subject and state migration actions.
	Resolve(s *Subject) (*Subject, []StateAction, error)
}

Resolver is an interface that abstracts a rule for solving a subject.

func NewStateImportResolver

func NewStateImportResolver(d *schema.Dictionary) Resolver

NewStateImportResolver returns a new instance of StateImportResolver.

type StateAction

type StateAction interface {
	// MigrationAction returns a string of action for state migration.
	// It escapes special characters in HCL for use as an action in a tfmigrate's
	// migration file.
	MigrationAction() string
}

StateAction is an interface of action for state migration.

func NewStateImportAction

func NewStateImportAction(address string, id string) StateAction

NewStateImportAction returns a new instance of StateImportAction.

type StateImportAction

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

StateImportAction implements the StateAction interface.

func (*StateImportAction) MigrationAction

func (a *StateImportAction) MigrationAction() string

MigrationAction returns a string of action for state migration. It escapes special characters in HCL for use as an action in a tfmigrate's migration file.

type StateImportResolver

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

StateImportResolver is an implementation of Resolver for import.

func (*StateImportResolver) Resolve

func (r *StateImportResolver) Resolve(s *Subject) (*Subject, []StateAction, error)

Resolve tries to resolve some conflicts in a given subject and returns the updated subject and state migration actions. It translates a planned create action into an import state migration.

type StateMigration

type StateMigration struct {
	// A name label of migration block
	Name string
	// A working directory for executing terraform command.
	Dir string
	// A list of state action.
	Actions []StateAction
}

StateMigration is a type which corresponds to tfmigrate.StateMigratorConfig and config.MigrationBlock in minamijoyo/tfmigrate. The current implementation doesn't encode migration actions to a file directly with gohcl, so we define only what we need here.

func NewStateMigration

func NewStateMigration(name string, dir string) *StateMigration

NewStateMigration returns a new instance of StateMigration.

func (*StateMigration) AppendActions

func (m *StateMigration) AppendActions(actions ...StateAction)

AppendActions appends a list of actions to migration.

func (*StateMigration) Render

func (m *StateMigration) Render() ([]byte, error)

Render converts a state migration config to bytes. Return an empty slice when no action without error. Encoding StateMigratorConfig directly with gohcl has some problems. An array contains multiple elements is output as one line. It's not readable for multiple actions. In additon, the default value is set explicitly, it's not only redundant but also increases cognitive load for user who isn't familiar with tfmigrate. So we use text/template to render a migration file.

type Subject

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

Subject is a problem to be solved. It contains multiple conflicts.

func NewSubject

func NewSubject(plan *Plan) *Subject

NewSubject finds conflicts contained in a given plan and defines a problem.

func (*Subject) IsResolved

func (s *Subject) IsResolved() bool

IsResolved returns true if all conflicts have been resolved, otherwise false.

func (*Subject) UnresolvedConflicts

func (s *Subject) UnresolvedConflicts() []*Conflict

UnresolvedConflicts returns a list of unresolved conflicts.

Directories

Path Synopsis
aws

Jump to

Keyboard shortcuts

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