dtan4 / terraforming

Export existing AWS resources to Terraform style (tf, tfstate) / No longer actively maintained
http://terraforming.dtan4.net/
MIT License
4.3k stars 659 forks source link

bug on merging with exisitn terraform.tfstate file #491

Open StL-Jim opened 4 years ago

StL-Jim commented 4 years ago

Here's the error I get when I try to merge into an existing terraform.tfstate terraforming cwa --tfstate --merge=terraform.tfstate --profile xxxxxxx /var/lib/gems/2.3.0/gems/terraforming-0.18.0/lib/terraforming/cli.rb:269:in tfstate': undefined method[]' for nil:NilClass (NoMethodError) from /var/lib/gems/2.3.0/gems/terraforming-0.18.0/lib/terraforming/cli.rb:250:in execute' from /var/lib/gems/2.3.0/gems/terraforming-0.18.0/lib/terraforming/cli.rb:25:incwa' from /var/lib/gems/2.3.0/gems/thor-1.0.1/lib/thor/command.rb:27:in run' from /var/lib/gems/2.3.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:ininvoke_command' from /var/lib/gems/2.3.0/gems/thor-1.0.1/lib/thor.rb:392:in dispatch' from /var/lib/gems/2.3.0/gems/thor-1.0.1/lib/thor/base.rb:485:instart' from /var/lib/gems/2.3.0/gems/terraforming-0.18.0/bin/terraforming:5:in <top (required)>' from /usr/local/bin/terraforming:23:inload' from /usr/local/bin/terraforming:23:in `

'

StL-Jim commented 4 years ago

Also, I installed using gem install terraforming, here's the list of installed gems gem list

LOCAL GEMS

aws-eventstream (1.0.3) aws-partitions (1.259.0) aws-sdk-autoscaling (1.30.0) aws-sdk-cloudwatch (1.31.0) aws-sdk-core (3.86.0) aws-sdk-dynamodb (1.41.0) aws-sdk-ec2 (1.129.0) aws-sdk-efs (1.23.0) aws-sdk-elasticache (1.29.0) aws-sdk-elasticloadbalancing (1.19.0) aws-sdk-elasticloadbalancingv2 (1.39.0) aws-sdk-iam (1.32.0) aws-sdk-kms (1.27.0) aws-sdk-rds (1.74.0) aws-sdk-redshift (1.35.0) aws-sdk-route53 (1.30.0) aws-sdk-s3 (1.60.1) aws-sdk-sns (1.21.0) aws-sdk-sqs (1.23.1) aws-sigv4 (1.1.0) bigdecimal (1.2.8) did_you_mean (1.0.0) io-console (0.4.5) jmespath (1.4.0) json (1.8.3) minitest (5.8.4) multi_json (1.12.2) net-telnet (0.1.1) power_assert (0.2.7) psych (2.0.17) rake (10.5.0) rdoc (4.2.1) terraforming (0.18.0) test-unit (3.1.7) thor (1.0.1)

richstokes commented 4 years ago

Running into something similar here. Did you ever find a solution?

Traceback (most recent call last):
    9: from /usr/local/bin/terraforming:23:in `<main>'
    8: from /usr/local/bin/terraforming:23:in `load'
    7: from /Library/Ruby/Gems/2.6.0/gems/terraforming-0.18.0/bin/terraforming:5:in `<top (required)>'
    6: from /Library/Ruby/Gems/2.6.0/gems/thor-1.0.1/lib/thor/base.rb:485:in `start'
    5: from /Library/Ruby/Gems/2.6.0/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
    4: from /Library/Ruby/Gems/2.6.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
    3: from /Library/Ruby/Gems/2.6.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
    2: from /Library/Ruby/Gems/2.6.0/gems/terraforming-0.18.0/lib/terraforming/cli.rb:120:in `iamu'
    1: from /Library/Ruby/Gems/2.6.0/gems/terraforming-0.18.0/lib/terraforming/cli.rb:250:in `execute'
/Library/Ruby/Gems/2.6.0/gems/terraforming-0.18.0/lib/terraforming/cli.rb:269:in `tfstate': undefined method `[]' for nil:NilClass (NoMethodError)
LunaticZorr commented 4 years ago

Same error here too

Traceback (most recent call last):
    9: from /usr/local/bin/terraforming:23:in `<main>'
    8: from /usr/local/bin/terraforming:23:in `load'
    7: from /var/lib/gems/2.5.0/gems/terraforming-0.18.0/bin/terraforming:5:in `<top (required)>'
    6: from /usr/lib/ruby/vendor_ruby/thor/base.rb:444:in `start'
    5: from /usr/lib/ruby/vendor_ruby/thor.rb:369:in `dispatch'
    4: from /usr/lib/ruby/vendor_ruby/thor/invocation.rb:126:in `invoke_command'
    3: from /usr/lib/ruby/vendor_ruby/thor/command.rb:27:in `run'
    2: from /var/lib/gems/2.5.0/gems/terraforming-0.18.0/lib/terraforming/cli.rb:215:in `vpc'
    1: from /var/lib/gems/2.5.0/gems/terraforming-0.18.0/lib/terraforming/cli.rb:250:in `execute'
/var/lib/gems/2.5.0/gems/terraforming-0.18.0/lib/terraforming/cli.rb:269:in `tfstate': undefined method `[]' for nil:NilClass (NoMethodError)
shanezeller commented 3 years ago

I am getting parse error in Multi-json thrign to merge anything. vagrant@ubuntu1804:~/SpecialProjects/Output$ terraforming alb --tfstate --merge=.terraform.tfstate --overwrite Traceback (most recent call last): 11: from /usr/local/bin/terraforming:23:in <main>' 10: from /usr/local/bin/terraforming:23:inload' 9: from /var/lib/gems/2.5.0/gems/terraforming-0.18.0/bin/terraforming:5:in <top (required)>' 8: from /var/lib/gems/2.5.0/gems/thor-1.0.1/lib/thor/base.rb:485:instart' 7: from /var/lib/gems/2.5.0/gems/thor-1.0.1/lib/thor.rb:392:in dispatch' 6: from /var/lib/gems/2.5.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:ininvoke_command' 5: from /var/lib/gems/2.5.0/gems/thor-1.0.1/lib/thor/command.rb:27:in run' 4: from /var/lib/gems/2.5.0/gems/terraforming-0.18.0/lib/terraforming/cli.rb:15:inalb' 3: from /var/lib/gems/2.5.0/gems/terraforming-0.18.0/lib/terraforming/cli.rb:250:in execute' 2: from /var/lib/gems/2.5.0/gems/terraforming-0.18.0/lib/terraforming/cli.rb:267:intfstate' 1: from /var/lib/gems/2.5.0/gems/multi_json-1.12.2/lib/multi_json.rb:122:in load' /var/lib/gems/2.5.0/gems/multi_json-1.12.2/lib/multi_json/adapter.rb:20:inload': JSON::ParserError (MultiJson::ParseError)

tingwei628 commented 3 years ago

If there's no property "modules" in terraform.tfstate file, the following codes would cause NoMethodError problem.

tfstate["modules"][0]["resources"] = tfstate["modules"][0]["resources"].merge(klass.tfstate)

UPDATE I found another tool to merge Terraform state files into one.