Skip to content

Commit

Permalink
fix: compilation errors in test files
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodmanBen committed Mar 10, 2022
1 parent ebe6d77 commit 5053630
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

ENHANCEMENTS:

Support Terraform Cloud as a remote backend ([#72](https://github.com/minamijoyo/tfmigrate/pull/72)).
Support Terraform Cloud as a remote backend in Terraform 1.1.+ with the `cloud` block.

## 0.3.1 (2022/01/26)

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ An example of configuration file is as follows.
```hcl
tfmigrate {
migration_dir = "./tfmigrate"
is_backend_terraform_cloud = true
history {
storage "s3" {
bucket = "tfmigrate-test"
Expand All @@ -378,6 +379,13 @@ tfmigrate {
}
```

#### is_backend_terraform_cloud
Whether the remote backend specified in Terraform files references a
[terraform cloud remote backend](https://www.terraform.io/language/settings/terraform-cloud),
in particular specified as a `cloud` block within the `terraform` config block. This backend
type was introduced in Terraform 1.1.+ and is the recommended way to specify a Terraform backend.
Attribute defaults to `false`.

#### tfmigrate block

The `tfmigrate` block has the following attributes:
Expand Down
1 change: 0 additions & 1 deletion tfexec/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ terraform {
return nil, fmt.Errorf("failed to switch backend to local: %s", err)
}

// TODO
switchBackToRemoteFunc := func() {
log.Printf("[INFO] [executor@%s] remove the override file\n", c.Dir())
err := os.Remove(path)
Expand Down
2 changes: 1 addition & 1 deletion tfexec/terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ resource "aws_security_group" "bar" {}
t.Fatalf("an override file already exists: %s", err)
}

switchBackToRemotekFunc, err := terraformCLI.OverrideBackendToLocal(context.Background(), filename, workspace)
switchBackToRemotekFunc, err := terraformCLI.OverrideBackendToLocal(context.Background(), filename, workspace, false)
if err != nil {
t.Fatalf("failed to run OverrideBackendToLocal: %s", err)
}
Expand Down
1 change: 0 additions & 1 deletion tfmigrate/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type Migrator interface {

// setupWorkDir is a common helper function to set up work dir and returns the
// current state and a switch back function.
// TODO: Needs to except a string
func setupWorkDir(ctx context.Context, tf tfexec.TerraformCLI, workspace string, isBackendTerraformCloud bool) (*tfexec.State, func(), error) {
// check if terraform command is available.
version, err := tf.Version(ctx)
Expand Down
2 changes: 1 addition & 1 deletion tfmigrate/mock_migrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestMockMigratorConfigNewMigrator(t *testing.T) {

for _, tc := range cases {
t.Run(tc.desc, func(t *testing.T) {
got, err := tc.config.NewMigrator(tc.o)
got, err := tc.config.NewMigrator(tc.o, false)
if tc.ok && err != nil {
t.Fatalf("unexpected err: %s", err)
}
Expand Down
1 change: 0 additions & 1 deletion tfmigrate/multi_state_migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/minamijoyo/tfmigrate/tfexec"
)

// TODO: Changes needed here that match the state_migrator.go changes
// MultiStateMigratorConfig is a config for MultiStateMigrator.
type MultiStateMigratorConfig struct {
// FromDir is a working directory where states of resources move from.
Expand Down
4 changes: 2 additions & 2 deletions tfmigrate/multi_state_migrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestMultiStateMigratorConfigNewMigrator(t *testing.T) {

for _, tc := range cases {
t.Run(tc.desc, func(t *testing.T) {
got, err := tc.config.NewMigrator(tc.o)
got, err := tc.config.NewMigrator(tc.o, false)
if tc.ok && err != nil {
t.Fatalf("unexpected err: %s", err)
}
Expand Down Expand Up @@ -280,7 +280,7 @@ func TestAccMultiStateMigratorApply(t *testing.T) {
o.PlanOut = "foo.tfplan"
}

m := NewMultiStateMigrator(fromTf.Dir(), toTf.Dir(), tc.fromWorkspace, tc.toWorkspace, actions, o, tc.force)
m := NewMultiStateMigrator(fromTf.Dir(), toTf.Dir(), tc.fromWorkspace, tc.toWorkspace, actions, o, tc.force, false)
err = m.Plan(ctx)
if err != nil {
t.Fatalf("failed to run migrator plan: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion tfmigrate/state_import_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ resource "aws_iam_user" "baz" {
NewStateImportAction("aws_iam_user.baz", "baz"),
}

m := NewStateMigrator(tf.Dir(), "default", actions, &MigratorOption{}, false)
m := NewStateMigrator(tf.Dir(), "default", actions, &MigratorOption{}, false, false)
err = m.Plan(ctx)
if err != nil {
t.Fatalf("failed to run migrator plan: %s", err)
Expand Down
6 changes: 3 additions & 3 deletions tfmigrate/state_migrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestStateMigratorConfigNewMigrator(t *testing.T) {

for _, tc := range cases {
t.Run(tc.desc, func(t *testing.T) {
got, err := tc.config.NewMigrator(tc.o)
got, err := tc.config.NewMigrator(tc.o, false)
if tc.ok && err != nil {
t.Fatalf("unexpected err: %s", err)
}
Expand Down Expand Up @@ -181,7 +181,7 @@ resource "aws_iam_user" "qux" {
NewStateImportAction("aws_iam_user.qux", "qux"),
}

m := NewStateMigrator(tf.Dir(), tc.workspace, actions, &MigratorOption{}, false)
m := NewStateMigrator(tf.Dir(), tc.workspace, actions, &MigratorOption{}, false, false)
err = m.Plan(ctx)
if err != nil {
t.Fatalf("failed to run migrator plan: %s", err)
Expand Down Expand Up @@ -254,7 +254,7 @@ resource "aws_security_group" "baz" {}
o := &MigratorOption{}
o.PlanOut = "foo.tfplan"

m := NewStateMigrator(tf.Dir(), "default", actions, o, true)
m := NewStateMigrator(tf.Dir(), "default", actions, o, true, false)
err = m.Plan(ctx)
if err != nil {
t.Fatalf("failed to run migrator plan: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion tfmigrate/state_mv_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ resource "aws_security_group" "baz" {}
NewStateMvAction("aws_security_group.bar", "aws_security_group.bar2"),
}

m := NewStateMigrator(tf.Dir(), "default", actions, &MigratorOption{}, false)
m := NewStateMigrator(tf.Dir(), "default", actions, &MigratorOption{}, false, false)
err = m.Plan(ctx)
if err != nil {
t.Fatalf("failed to run migrator plan: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion tfmigrate/state_rm_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ resource "aws_security_group" "baz" {}
NewStateRmAction([]string{"aws_security_group.qux"}),
}

m := NewStateMigrator(tf.Dir(), "default", actions, &MigratorOption{}, false)
m := NewStateMigrator(tf.Dir(), "default", actions, &MigratorOption{}, false, false)
err = m.Plan(ctx)
if err != nil {
t.Fatalf("failed to run migrator plan: %s", err)
Expand Down

0 comments on commit 5053630

Please sign in to comment.