Giter VIP home page Giter VIP logo

Comments (8)

entropitor avatar entropitor commented on June 13, 2024 1

Nice thanks! That's one of the things I tried before so makes sense

from tfmigrate.

minamijoyo avatar minamijoyo commented on June 13, 2024

@entropitor Thank you for opening issue!

I didn't know the fact that an address of resource could contain spaces.
To clarify what are you trying, could you provide a sample Terraform configuration and state mv command?

from tfmigrate.

entropitor avatar entropitor commented on June 13, 2024
resource "docker_image" "nginx" {
  name  = "nginx:latest"
  keep_locally = false
}

resource "docker_container" "nginx" {
  for_each = {
    "This is an example" = "example"
  }

  image = docker_image.nginx.latest
  name = each.value
}

Output of terraform state list

docker_container.nginx["This is an example"]
docker_image.nginx

Output of tf state show 'docker_container.nginx["This is an example"]' (I truncated it a bit to hide some potential sensitive values)

# docker_container.nginx["This is an example"]:
resource "docker_container" "nginx" {
    attach            = false
    command           = [
        "nginx",
        "-g",
        "daemon off;",
    ]
    cpu_shares        = 0
    dns               = []
    dns_opts          = []
    entrypoint        = [
        "/docker-entrypoint.sh",
    ]
    image             = "sha256:f35646e83998b844c3f067e5a2cff84cdf0967627031aeda3042d78996b68d35"
    name              = "example"
    network_mode      = "default"
    privileged        = false
    publish_all_ports = false
    read_only         = false
    restart           = "no"
    rm                = false
    shm_size          = 64
    start             = true
}

Potentially something like #4 (comment) could help with this? Then you don't have to do this additional parsing?

from tfmigrate.

minamijoyo avatar minamijoyo commented on June 13, 2024

Wow 😮 it contains space and also double-quote...

The current implementation of parsing action string is here:

args := strings.Fields(cmdStr)

args := strings.Fields(cmdStr)

We probably need to escape special characters. go-shellwords may help us to simulate shell escape logic.

from tfmigrate.

entropitor avatar entropitor commented on June 13, 2024

@minamijoyo Does it actually make sense that you do need to do parsing? I don't know hcl very well but wouldn't it make more sense if the developer already provided the splitted string?

from tfmigrate.

minamijoyo avatar minamijoyo commented on June 13, 2024

@entropitor Using such a schema-less string for action is intentional by design. It allows us to easily copy terraform state command to action.

Every design choice has pros and cons. I know the strictly typed-schema you mentioned will provide us fine-grained controls. Actually my initial idea was it. However, I wrote some examples of migration file and found that it's very redundant to write migration files. If I want to split a tfstate and move 10 resources to other tfstate, it requires approximately 4 lines x 10 resources = 40 lines. In addition, it also added cognitive load to users. Most of Terraform users know the terraform state command syntax, but probably don't remember what is a correct name of attribute for each action in migration file.

I prefer to a design solving most common use-cases simply rather than imposing complexity on users only to support a minor edge case.

from tfmigrate.

entropitor avatar entropitor commented on June 13, 2024

Okay, then I guess your solution seems like the best way to go forward

from tfmigrate.

minamijoyo avatar minamijoyo commented on June 13, 2024

@entropitor Fixed in v0.1.1.

Note that we need to escape double-quote ( \" ). It's a HCL limitation.

migration "state" "test" {
  dir = "tmp/test5"
  actions = [
    "mv docker_container.nginx 'docker_container.nginx[\"This is an example\"]'",
  ]
}

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.