Skip to content

Commit

Permalink
further small changes and notes on functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodmanBen committed Mar 4, 2022
1 parent 7541751 commit 592737d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
8 changes: 5 additions & 3 deletions command/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
flag "github.com/spf13/pflag"
)

// ApplyCommand is a command which computes a new state and pushes it to remote state.
// ApplyCommand is a command which computes a new state and pushes it to the remote state.
type ApplyCommand struct {
Meta
}
Expand All @@ -32,7 +32,7 @@ func (c *ApplyCommand) Run(args []string) int {
log.Printf("[DEBUG] [command] config: %#v\n", c.config)

c.Option = newOption()
// The option may contains sensitive values such as environment variables.
// The option may contain sensitive values such as environment variables.
// So logging the option set log level to DEBUG instead of INFO.
log.Printf("[DEBUG] [command] option: %#v\n", c.Option)

Expand Down Expand Up @@ -75,6 +75,8 @@ func (c *ApplyCommand) Run(args []string) int {
return 0
}

// TODO: The file runner and history runner is what actually runs the apply/plan functions
// TODO: Elements of the config contain information on remote backend type
// applyWithoutHistory is a helper function which applies a given migration file without history.
func (c *ApplyCommand) applyWithoutHistory(filename string) error {
fr, err := NewFileRunner(filename, c.config, c.Option)
Expand All @@ -85,7 +87,7 @@ func (c *ApplyCommand) applyWithoutHistory(filename string) error {
return fr.Apply(context.Background())
}

// applyWithHistory is a helper function which applies all unapplied pending migrations and save them to history.
// applyWithHistory is a helper function which applies all unapplied pending migrations and saves them to history.
func (c *ApplyCommand) applyWithHistory(filename string) error {
ctx := context.Background()
hr, err := NewHistoryRunner(ctx, filename, c.config, c.Option)
Expand Down
6 changes: 4 additions & 2 deletions command/file_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewFileRunner(filename string, config *config.TfmigrateConfig, option *tfmi
return nil, err
}

m, err := mc.Migrator.NewMigrator(option)
m, err := mc.Migrator.NewMigrator(option) // TODO: What does this NewMigrator file do?
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -61,12 +61,14 @@ func loadMigrationFile(filename string) (*tfmigrate.MigrationConfig, error) {
return config, nil
}

// TODO: Here is where the action occurs for Plan
// Plan plans a single migration.
func (r *FileRunner) Plan(ctx context.Context) error {
return r.m.Plan(ctx)
}

// Apply applies a single migration..
// TODO: Here is where the action occurs for Apply
// Apply applies a single migration.
func (r *FileRunner) Apply(ctx context.Context) error {
return r.m.Apply(ctx)
}
Expand Down
19 changes: 14 additions & 5 deletions tfexec/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,21 @@ terraform {
}
log.Printf("[INFO] [executor@%s] switch back to remote\n", c.Dir())

// TODO: First just see if removing the -reconfigure statement will work?
// TODO: Need to detect if the configuration uses Terraform cloud as the backend, instead of the
// TODO: hacky fix
// TODO: First just see if removing the -reconfigure statement will work? Yes it does, which is good.
// TODO: Possible solutions:
// TODO: 1) Pass in a command line argument into tfmigrate
// This option (might) be the cleanest, but not necessarily to implement. Will be helpful
// to figure out how command line arguments are used with this tool regardless.
// TODO: 2) New argument in configuration?
// This would be likely easier to reference within the code,
// but it would be not the best user experience to have to add the extra configuration. It feels
// like it is a step behind the optimal situation which would be just to infer it directly from
// the terraform itself.
// TODO: 3) Have tfmigrate read the terraform block's configuration for a cloud {} block.
// Likely will be tricky to implement, but this is a "public" tool and so should implement the
// smoothest/most automated solution.

stdOut, err := c.Init(ctx, "-input=false", "-no-color") //, "-reconfigure")
// TODO: Debugging this new functionality here
log.Printf(stdOut)

if (err != nil) && (stdOut == "\nInitializing Terraform Cloud...") {
_, err = c.Init(ctx, "-input=false", "-no-color")
Expand Down
2 changes: 1 addition & 1 deletion tfmigrate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type MigratorConfig interface {
NewMigrator(o *MigratorOption) (Migrator, error)
}

// MigratorOption customizes a behaviror of Migrator.
// MigratorOption customizes a behavior of Migrator.
// It is used for shared settings across Migrator instances.
type MigratorOption struct {
// ExecPath is a string how terraform command is executed. Default to terraform.
Expand Down
2 changes: 1 addition & 1 deletion tfmigrate/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Migrator interface {

// Apply computes a new state and pushes it to remote state.
// It will fail if terraform plan detects any diffs with the new state.
// We are intended to this is used for state refactoring.
// This is intended for solely state refactoring.
// Any state migration operations should not break any real resources.
Apply(ctx context.Context) error
}
Expand Down

0 comments on commit 592737d

Please sign in to comment.