boltops-tools / terraspace

Terraspace: The Terraform Framework
https://terraspace.cloud
Apache License 2.0
678 stars 46 forks source link

[Module Testing] tfvars file is not being used by terraspace test #125

Closed thuandt closed 2 years ago

thuandt commented 3 years ago

Checklist

My Environment

Software Version
Operating System Ubuntu 20.04 (WSL2)
Terraform 1.0.2
Terraspace 0.6.11
Ruby ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x86_64-linux]

Expected Behaviour

Current Behavior

variable "myvar" {
  type        = string
  description = "Required variable"
}
terraspace test                                     
=> cd test && bundle exec rspec

main
Terraspace.logger has been reconfigured to /tmp/terraspace/log/test.log
Building test harness at: /tmp/terraspace/test-harnesses/mybug-harness
Test harness built.
=> terraspace up mybug -y
=> terraspace down mybug -y

Finished in 9.3 seconds (files took 0.42923 seconds to load)
0 examples, 0 failures
[2021-07-15T11:17:07 #17971 ]: Building .terraspace-cache/us-west-2/test/modules/mybug
[2021-07-15T11:17:10 #17971 ]: Built in .terraspace-cache/us-west-2/test/modules/mybug
[2021-07-15T11:17:10 #17971 ]: Current directory: .terraspace-cache/us-west-2/test/modules/mybug
[2021-07-15T11:17:10 #17971 ]: => terraform plan -input=false -out /tmp/terraspace/plans/mybug-3f31c6546719d94c6bba70979b8e06d2.plan
[2021-07-15T11:17:10 #17971 ]: ╷
[2021-07-15T11:17:10 #17971 ]: │ Error: No value for required variable
[2021-07-15T11:17:10 #17971 ]: │ 
[2021-07-15T11:17:10 #17971 ]: │   on variables.tf line 3:
[2021-07-15T11:17:10 #17971 ]: │    3: variable "myvar" {
[2021-07-15T11:17:10 #17971 ]: │ 
[2021-07-15T11:17:10 #17971 ]: │ The root module input variable "myvar" is not set, and has no default
[2021-07-15T11:17:10 #17971 ]: │ value. Use a -var or -var-file command line argument to provide a value for
[2021-07-15T11:17:10 #17971 ]: │ this variable.
[2021-07-15T11:17:10 #17971 ]: ╵
[2021-07-15T11:17:10 #17971 ]: Error running command: terraform plan -input=false -out /tmp/terraspace/plans/mybug-3f31c6546719d94c6bba70979b8e06d2.plan
[2021-07-15T11:17:10 #17971 ]: Building .terraspace-cache/us-west-2/test/modules/mybug
[2021-07-15T11:17:11 #17971 ]: Built in .terraspace-cache/us-west-2/test/modules/mybug
[2021-07-15T11:17:11 #17971 ]: => terraform plan -input=false -destroy
[2021-07-15T11:17:12 #17971 ]: ╷
[2021-07-15T11:17:12 #17971 ]: │ Error: No value for required variable
[2021-07-15T11:17:12 #17971 ]: │ 
[2021-07-15T11:17:12 #17971 ]: │   on variables.tf line 3:
[2021-07-15T11:17:12 #17971 ]: │    3: variable "myvar" {
[2021-07-15T11:17:12 #17971 ]: │ 
[2021-07-15T11:17:12 #17971 ]: │ The root module input variable "myvar" is not set, and has no default
[2021-07-15T11:17:12 #17971 ]: │ value. Use a -var or -var-file command line argument to provide a value for
[2021-07-15T11:17:12 #17971 ]: │ this variable.
[2021-07-15T11:17:12 #17971 ]: ╵
[2021-07-15T11:17:12 #17971 ]: Error running command: terraform plan -input=false -destroy

Step-by-step reproduction instructions

Code Sample

Solution Suggestion

NA

tongueroo commented 2 years ago

Don't believe the example specifies the usage of the tfvars file. Suppose to specify tfvars files explicitly by design so you can use different tfvars in the test harness if needed. Here's an example repo:

    terraspace.build_test_harness(
      name: "example-harness",
      modules: {example: mod_path},
      # See: https://terraspace.cloud/docs/testing/test-harness/
      # config: "spec/fixtures/config",
      tfvars: {demo: "spec/fixtures/tfvars/test.tfvars"}, # <-- Make sure to have this
    )

Also covered in docs: https://terraspace.cloud/docs/testing/stack/