Comments (8)
Nice thanks! That's one of the things I tried before so makes sense
from tfmigrate.
@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.
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.
Wow 😮 it contains space and also double-quote...
The current implementation of parsing action string is here:
tfmigrate/tfmigrate/state_action.go
Line 27 in 7b86880
tfmigrate/tfmigrate/multi_state_action.go
Line 26 in 7b86880
We probably need to escape special characters. go-shellwords
may help us to simulate shell escape logic.
from tfmigrate.
@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.
@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.
Okay, then I guess your solution seems like the best way to go forward
from tfmigrate.
@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)
- Migrating states from codebases with different terraform version HOT 3
- tfmigrate reports success despite backend not properly configured HOT 1
- Cannot use `*` with tfmigrate actions HOT 4
- Feature request: Display of state plan for to_dir in multi-state HOT 3
- tfmigrate reports migration plan success when Terraform plan command returns an error HOT 2
- Feature request: add an option to skip `terraform plan`-ing HOT 4
- Feature request: support replace-provider HOT 5
- Change tfmigrate-storage license from MPL2 to MIT HOT 3
- Feature request: support skip_plan in state migration HOT 2
- Feature request: support actions spanning multiple HCL files targeting the same projects HOT 4
- multi_state xmv attempts to migrate data sources? HOT 4
- Possible to optimise multi_state_mv execution time?
- Possible to optimise multi_state_mv execution time? HOT 1
- OpenTofu support HOT 3
- Add terraform >=1.1 moved resource documentation? HOT 1
- [bug] Does not work when working with terragrunt & dynamic backend config
- Error executing ftmigrate on MacOS 14.0 (ARM) HOT 1
- split resources with dependencies. HOT 1
- Bug when you have module that have the same resource names
- High vulnerability in golang library HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tfmigrate.