terraspace icon indicating copy to clipboard operation
terraspace copied to clipboard

Terraspace seed error with one-line variable declaration

Open pilchkinstein-perspectum opened this issue 3 years ago • 1 comments

Also reported in hcl_parser#3

Checklist

  • [ ] Upgrade Terraspace: Are you using the latest version of Terraspace? This allows Terraspace to fix issues fast. There's an Upgrading Guide: https://terraspace.cloud/docs/misc/upgrading/
  • [ x] Reproducibility: Are you reporting a bug others will be able to reproduce and not asking a question. If you're unsure or want to ask a question, do so on https://community.boltops.com
  • [ x] Code sample: Have you put together a code sample to reproduce the issue and make it available? Code samples help speed up fixes dramatically. If it's an easily reproducible issue, then code samples are not needed. If you're unsure, please include a code sample.

My Environment

Software Version
Operating System Ubuntu 20.04LTS
Terraform v1.1.3
Terraspace 1.0.0
Ruby 3.0.3

Expected Behaviour

Seed command should produce a tfvars file

Current Behavior

Terraspace seed command fails when variables.tf contains a one-line variable declaration

Step-by-step reproduction instructions

  1. terraspace new stack bob
  2. Edit app/stacks/bob/variables.tf
variable "var_0" {}
variable "var_n" {}
  1. TS_ENV=alice terraspace seed bob

Results in error message:

hcl_parser-0.2.1/lib/hcl_parser/loader.rb:56:in `block in rewrite_complex_types': bad value for range (ArgumentError)

Error appears to be the logic that assumes the closing brace of a variable will be the first char on a line, because the following variables.tf results in no error when the seed command is run:

# app/stacks/bob/variables.tf
variable "var_0" {}
variable "var_n" {
}

Solution Suggestion

Modify hcl_parser/loader.rb to match a closing brace anywhere on a line in variables.tf

hi, we are experiencing this issue as well and confirm that the workaround for our variables.tf allows us to generate a tfvars.

bannedintx avatar Feb 17 '22 16:02 bannedintx

Fixed in https://github.com/boltops-tools/hcl_parser/pull/5 To use, update the hcl_parser gem to 0.2.2. In your terraspace project

bundle update hcl_parser

This updates the Gemfile.lock pin of hcl_parser. You'll need at least hcl_parser 0.2.2

tongueroo avatar Aug 26 '22 16:08 tongueroo