Giter VIP home page Giter VIP logo

Comments (3)

minamijoyo avatar minamijoyo commented on June 7, 2024

I think the feature was implemented in v0.2.2 via #11.
I cannot reproduce it with the latest (v0.2.7). Which version are you using?

bash-5.0# tfmigrate -v
0.2.7

bash-5.0# terraform state list
aws_security_group.bar
aws_security_group.foo

bash-5.0# cat main.tf
resource "aws_security_group" "foo2" {
  name = "foo"
}

resource "aws_security_group" "bar2" {
  name = "bar"
}

bash-5.0# cat test.hcl
migration "state" "test" {
  force = true
  actions = [
    "mv aws_security_group.foo aws_security_group.foo2",
  ]
}

bash-5.0# tfmigrate plan test.hcl
2021/09/03 07:15:37 [INFO] [runner] load migration file: test.hcl
2021/09/03 07:15:37 [INFO] [migrator] start state migrator plan
2021/09/03 07:15:37 [INFO] [migrator@.] terraform version: 1.0.5
2021/09/03 07:15:37 [INFO] [migrator@.] initialize work dir
2021/09/03 07:15:39 [INFO] [migrator@.] switch to remote workspace default
2021/09/03 07:15:40 [INFO] [migrator@.] get the current remote state
2021/09/03 07:15:41 [INFO] [migrator@.] override backend to local
2021/09/03 07:15:41 [INFO] [executor@.] create an override file
2021/09/03 07:15:41 [INFO] [migrator@.] creating local workspace folder in: terraform.tfstate.d/default
2021/09/03 07:15:41 [INFO] [executor@.] switch backend to local
2021/09/03 07:15:43 [INFO] [migrator@.] compute a new state
2021/09/03 07:15:43 [INFO] [migrator@.] check diffs
2021/09/03 07:15:46 [INFO] [migrator@.] unexpected diffs, ignoring as force option is true: failed to run command (exited 2): terraform plan -state=/tmp/tmp096906093 -out=/tmp/tfplan045121000 -input=false -no-color -detailed-exitcode
stdout:
aws_security_group.bar: Refreshing state... [id=sg-e5de8a85]
aws_security_group.foo2: Refreshing state... [id=sg-21ac42f1]

Note: Objects have changed outside of Terraform

Terraform detected the following changes made outside of Terraform since the
last "terraform apply":

  # aws_security_group.foo2 has been changed
  ~ resource "aws_security_group" "foo2" {
        id                     = "sg-21ac42f1"
        name                   = "foo"
      + tags                   = {}
        # (7 unchanged attributes hidden)
    }
  # aws_security_group.bar has been changed
  ~ resource "aws_security_group" "bar" {
        id                     = "sg-e5de8a85"
        name                   = "bar"
      + tags                   = {}
        # (7 unchanged attributes hidden)
    }

Unless you have made equivalent changes to your configuration, or ignored the
relevant attributes using ignore_changes, the following plan may include
actions to undo or respond to these changes.

─────────────────────────────────────────────────────────────────────────────

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create
  - destroy

Terraform will perform the following actions:

  # aws_security_group.bar will be destroyed
  - resource "aws_security_group" "bar" {
      - arn                    = "arn:aws:ec2:ap-northeast-1:000000000000:security-group/sg-e5de8a85" -> null
      - description            = "Managed by Terraform" -> null
      - egress                 = [
          - {
              - cidr_blocks      = [
                  - "0.0.0.0/0",
                ]
              - description      = ""
              - from_port        = 0
              - ipv6_cidr_blocks = []
              - prefix_list_ids  = []
              - protocol         = "-1"
              - security_groups  = []
              - self             = false
              - to_port          = 0
            },
        ] -> null
      - id                     = "sg-e5de8a85" -> null
      - ingress                = [] -> null
      - name                   = "bar" -> null
      - owner_id               = "000000000000" -> null
      - revoke_rules_on_delete = false -> null
      - tags                   = {} -> null
      - tags_all               = {} -> null
    }

  # aws_security_group.bar2 will be created
  + resource "aws_security_group" "bar2" {
      + arn                    = (known after apply)
      + description            = "Managed by Terraform"
      + egress                 = (known after apply)
      + id                     = (known after apply)
      + ingress                = (known after apply)
      + name                   = "bar"
      + name_prefix            = (known after apply)
      + owner_id               = (known after apply)
      + revoke_rules_on_delete = false
      + tags_all               = (known after apply)
      + vpc_id                 = (known after apply)
    }

Plan: 1 to add, 0 to change, 1 to destroy.

─────────────────────────────────────────────────────────────────────────────

Saved the plan to: /tmp/tfplan045121000

To perform exactly these actions, run the following command to apply:
    terraform apply "/tmp/tfplan045121000"

stderr:
2021/09/03 07:15:46 [INFO] [executor@.] remove the override file
2021/09/03 07:15:46 [INFO] [executor@.] remove the workspace state folder
2021/09/03 07:15:46 [INFO] [executor@.] switch back to remote
2021/09/03 07:15:48 [INFO] [migrator] state migrator plan success!

P.S. Thank for your offering, but I'm currently not accepting any money for my OSS projects. Thanks!

from tfmigrate.

jeffgran avatar jeffgran commented on June 7, 2024

Hi, thank you for your reply! I am on the latest version:

 $ tfmigrate -v
0.2.7

I think maybe this only happens when it's a multi_state migration. I should have mentioned that in the original post, sorry.

from tfmigrate.

minamijoyo avatar minamijoyo commented on June 7, 2024

@jeffgran I confirmed and fixed it in v0.2.9 via #40. Thank you for reporting!

from tfmigrate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.