Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing newline when appending to moves.tf after second run of tfautomv #81

Closed
untcha opened this issue Feb 20, 2024 · 3 comments · Fixed by #82
Closed

Missing newline when appending to moves.tf after second run of tfautomv #81

untcha opened this issue Feb 20, 2024 · 3 comments · Fixed by #82
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@untcha
Copy link

untcha commented Feb 20, 2024

Hi!

first of all: tfautomv is awesome! It is currently saving us a lot of work!

We are currently in the progress of refactoring an AWS VPC module which needs to be applied to a lot of VPCs afterward. We are executing tfautomv in two terragrunt hooks:

terraform {
  source = local.module_source

  before_hook "tfautomv_1" {
    commands = ["plan"]
    execute  = ["tfautomv", "-vvv", "--skip-init", "--skip-refresh"]
  }

  before_hook "tfautomv_2" {
    commands = ["plan"]
    execute  = ["tfautomv", "-vvv", "--skip-init", "--skip-refresh"]
  }
}

The reason for executing tfautomv twice is the fact that the moves cannot be identified correctly for vpc_route_table_associations since terraform does not know the subnet_id and route_table_id after the first plan.

When executing tfautomv a second time the moved blocks are not correctly appended to the moves.tf resulting in the following error:

│ Error: Missing newline after block definition
│ 
│   on moves.tf line 80, in moved:
│   77: moved {
│   78:   from = module.this.aws_vpc_ipv4_cidr_block_association.this[1]
│   79:   to   = aws_vpc_ipv4_cidr_block_association.this["nr_172.16.0.0/20"]
│   80: }moved {
│ 
│ A block definition must end with a newline.

In tfautomv\pkg\terraform\move.go I added a \n to:

func (m Move) block() string {
	return fmt.Sprintf("moved {\n  from = %s\n  to   = %s\n}\n", m.FromAddress, m.ToAddress)
}

With that small change, our approach is successful and moved blocks are correctly written in the first run and appended correctly in the second run.

It would be awesome if you could implement a corresponding fix.

Thanks a lot!

@busser busser added the bug Something isn't working label Feb 21, 2024
@busser
Copy link
Owner

busser commented Feb 21, 2024

Thanks for bringing this to my attention! I'll get right on it 😄

@busser busser added the good first issue Good for newcomers label Feb 21, 2024
busser added a commit that referenced this issue Feb 26, 2024
busser added a commit that referenced this issue Feb 26, 2024
@busser
Copy link
Owner

busser commented Feb 26, 2024

Fixed in release v0.6.1. Thanks again for reporting this!

@untcha
Copy link
Author

untcha commented Feb 26, 2024

Thanks a lot!!! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants