newcontext-oss / kitchen-terraform

Test Kitchen plugins for testing Terraform configurations
https://github.com/newcontext/kitchen-terraform
Apache License 2.0
1.13k stars 145 forks source link

#<Kitchen::Terraform::Error: no implicit conversion of Array into String> #359

Closed lmayorga1980 closed 5 years ago

lmayorga1980 commented 5 years ago

I was able to add some debugging and got this

{:name=>"agent", :backend=>"ssh", :hosts_output=>"agent_address", :key_files=>["cert/agent.key"], :controls=>["operating_system"], :user=>"ubuntu", :reporter=>["cli"]}
#<Kitchen::Terraform::Error: tcagent: no implicit conversion of Array into String>
/Users/user/.rvm/gems/ruby-2.5.1/gems/kitchen-terraform-5.1.0/lib/kitchen/terraform/system.rb:78:in `rescue in verify'
/Users/user/.rvm/gems/ruby-2.5.1/gems/kitchen-terraform-5.1.0/lib/kitchen/terraform/system.rb:72:in `verify'
/Users/user/.rvm/gems/ruby-2.5.1/gems/kitchen-terraform-5.1.0/lib/kitchen/verifier/terraform.rb:176:in `verify'
/Users/user/.rvm/gems/ruby-2.5.1/gems/kitchen-terraform-5.1.0/lib/kitchen/verifier/terraform.rb:187:in `block in verify_systems'
/Users/user/.rvm/gems/ruby-2.5.1/gems/kitchen-terraform-5.1.0/lib/kitchen/verifier/terraform.rb:185:in `each'
/Users/user/.rvm/gems/ruby-2.5.1/gems/kitchen-terraform-5.1.0/lib/kitchen/verifier/terraform.rb:185:in `verify_systems'
/Users/user/.rvm/gems/ruby-2.5.1/gems/kitchen-terraform-5.1.0/lib/kitchen/verifier/terraform.rb:104:in `call'
/Users/user/.rvm/gems/ruby-2.5.1/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:459:in `block in verify_action'
/Users/user/.rvm/gems/ruby-2.5.1/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:552:in `synchronize_or_call'
/Users/user/.rvm/gems/ruby-2.5.1/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:514:in `block in action'
/Users/user/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/benchmark.rb:293:in `measure'
/Users/user/.rvm/gems/ruby-2.5.1/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:513:in `action'
/Users/user/.rvm/gems/ruby-2.5.1/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:451:in `verify_action'
/Users/user/.rvm/gems/ruby-2.5.1/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:382:in `block (2 levels) in transition_to'
/Users/user/.rvm/gems/ruby-2.5.1/gems/test-kitchen-2.2.5/lib/kitchen/lifecycle_hooks.rb:45:in `run_with_hooks'
/Users/user/.rvm/gems/ruby-2.5.1/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:381:in `block in transition_to'
/Users/user/.rvm/gems/ruby-2.5.1/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:380:in `each'
/Users/user/.rvm/gems/ruby-2.5.1/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:380:in `transition_to'
/Users/user/.rvm/gems/ruby-2.5.1/gems/test-kitchen-2.2.5/lib/kitchen/instance.rb:162:in `verify'
/Users/user/.rvm/gems/ruby-2.5.1/gems/test-kitchen-2.2.5/lib/kitchen/command.rb:197:in `public_send'
/Users/user/.rvm/gems/ruby-2.5.1/gems/test-kitchen-2.2.5/lib/kitchen/command.rb:197:in `run_action_in_thread'
/Users/user/.rvm/gems/ruby-2.5.1/gems/test-kitchen-2.2.5/lib/kitchen/command.rb:169:in `block (2 levels) in run_action'

test_path

test/integration/agent/controls/

output.tf

output "agent_address" {
  value = ["${openstack_compute_instance_v2.agent.*.access_ip_v4}"]
}

kitchen.yml

---
driver:
  name: terraform
  command_timeout: 1000
  variable_files:
    - my-variables.tfvars

provisioner:
  name: terraform

transport:
  name: ssh
  ssh_key: ./cert/agent.key
  username: ubuntu
  port: 22

platforms:
  - name: ubuntu

verifier:
  name: terraform
  systems:
    - name: agent
      backend: ssh
      hosts_output: agent_address
      key_files:
        - cert/agent.key
      controls:
        - operating_system
      user: ubuntu
      reporter:
        - cli
suites:
  - name: agent

terraform: 0.12.7

ruby: 2.5.1

gemset

addressable (2.6.0)
aws-eventstream (1.0.3)
aws-partitions (1.206.0)
aws-sdk (2.11.340)
aws-sdk-apigateway (1.34.0)
aws-sdk-apigatewayv2 (1.13.0)
aws-sdk-athena (1.19.0)
aws-sdk-autoscaling (1.22.0)
aws-sdk-budgets (1.25.0)
aws-sdk-cloudformation (1.25.0)
aws-sdk-cloudhsm (1.18.0)
aws-sdk-cloudhsmv2 (1.18.0)
aws-sdk-cloudtrail (1.17.0)
aws-sdk-cloudwatch (1.28.0)
aws-sdk-cloudwatchlogs (1.25.0)
aws-sdk-codecommit (1.28.0)
aws-sdk-codedeploy (1.26.0)
aws-sdk-codepipeline (1.23.0)
aws-sdk-configservice (1.35.0)
aws-sdk-core (3.64.0, 2.11.340)
aws-sdk-costandusagereportservice (1.17.0)
aws-sdk-dynamodb (1.34.0)
aws-sdk-ec2 (1.106.0)
aws-sdk-ecr (1.20.0)
aws-sdk-ecs (1.46.0)
aws-sdk-eks (1.24.0)
aws-sdk-elasticache (1.24.0)
aws-sdk-elasticbeanstalk (1.25.0)
aws-sdk-elasticloadbalancing (1.18.0)
aws-sdk-elasticloadbalancingv2 (1.33.0)
aws-sdk-elasticsearchservice (1.26.0)
aws-sdk-firehose (1.20.0)
aws-sdk-iam (1.29.0)
aws-sdk-kafka (1.12.0)
aws-sdk-kinesis (1.19.0)
aws-sdk-kms (1.24.0)
aws-sdk-lambda (1.29.0)
aws-sdk-organizations (1.17.0)
aws-sdk-rds (1.64.0)
aws-sdk-redshift (1.31.0)
aws-sdk-resources (2.11.340)
aws-sdk-route53 (1.29.0)
aws-sdk-route53domains (1.17.0)
aws-sdk-route53resolver (1.10.0)
aws-sdk-s3 (1.46.0)
aws-sdk-securityhub (1.12.0)
aws-sdk-ses (1.25.0)
aws-sdk-sms (1.16.0)
aws-sdk-sns (1.19.0)
aws-sdk-sqs (1.21.0)
aws-sdk-ssm (1.54.0)
aws-sigv4 (1.1.0)
azure_graph_rbac (0.17.1)
azure_mgmt_key_vault (0.17.4)
azure_mgmt_resources (0.17.6)
bcrypt_pbkdf (1.0.1)
bigdecimal (default: 1.3.4)
builder (3.2.3)
bundler (default: 1.17.3)
bundler-unload (1.0.2)
cmath (default: 1.0.0)
coderay (1.1.2)
concurrent-ruby (1.1.5)
csv (default: 1.0.0)
date (default: 1.0.0)
dbm (default: 1.0.0)
declarative (0.0.10)
declarative-option (0.1.0)
did_you_mean (1.2.0)
diff-lcs (1.3)
docker-api (1.34.2)
domain_name (0.5.20190701)
dry-configurable (0.8.3)
dry-container (0.7.2)
dry-core (0.4.9)
dry-equalizer (0.2.2)
dry-inflector (0.1.2)
dry-logic (0.6.1)
dry-types (0.14.1)
dry-validation (0.13.3, 0.13.0)
ed25519 (1.2.4)
equatable (0.6.1)
erubis (2.7.0)
etc (default: 1.0.0)
excon (0.66.0)
executable-hooks (1.6.0)
faraday (0.15.4)
faraday-cookie_jar (0.0.6)
faraday_middleware (0.12.2)
fcntl (default: 1.0.0)
ffi (1.11.1)
fiddle (default: 1.0.0)
fileutils (default: 1.0.2)
gdbm (default: 2.0.0)
gem-wrappers (1.4.0)
google-api-client (0.23.9)
googleauth (0.6.7)
gssapi (1.3.0)
gyoku (1.3.1)
hashie (3.6.0)
htmlentities (4.3.4)
http-cookie (1.0.3)
httpclient (2.8.3)
inifile (3.0.0)
inspec (4.12.0, 3.9.3)
io-console (default: 0.4.6)
ipaddr (default: 1.2.0)
jmespath (1.4.0)
json (2.2.0, default: 2.1.0)
json-schema (2.8.1)
jwt (2.2.1)
kitchen-terraform (5.1.0, 4.9.0)
license-acceptance (1.0.13)
little-plugger (1.1.4)
logging (2.2.2)
memoist (0.16.0)
method_source (0.9.2)
mime-types (3.2.2)
mime-types-data (3.2019.0331)
minitest (5.10.3)
mixlib-install (3.11.18)
mixlib-log (3.0.1)
mixlib-shellout (2.4.4)
mixlib-versioning (1.2.7)
ms_rest (0.7.4)
ms_rest_azure (0.11.1)
multi_json (1.13.1)
multipart-post (2.1.1)
necromancer (0.5.0)
net-scp (2.0.0, 1.2.1)
net-ssh (5.2.0, 4.2.0)
net-ssh-gateway (2.0.0)
net-telnet (0.1.1)
nori (2.6.0)
openssl (default: 2.1.0)
os (1.0.1)
parallel (1.17.0)
parslet (1.8.2)
pastel (0.7.3)
power_assert (1.1.1)
pry (0.12.2)
psych (default: 3.0.2)
public_suffix (3.1.1)
rake (12.3.0)
rbnacl (4.0.2)
rdoc (default: 6.0.1)
representable (3.0.4)
retriable (3.1.2)
rspec (3.8.0)
rspec-core (3.8.2)
rspec-expectations (3.8.4)
rspec-its (1.3.0)
rspec-mocks (3.8.1)
rspec-support (3.8.2)
rubygems-bundler (1.4.5)
rubyntlm (0.6.2)
rubyzip (1.2.3)
rvm (1.11.3.9)
scanf (default: 1.0.0)
sdbm (default: 1.0.0)
semverse (3.0.0)
signet (0.11.0)
sslshake (1.3.0)
stringio (default: 0.0.1)
strings (0.1.5)
strings-ansi (0.1.0)
strscan (default: 1.0.0)
term-ansicolor (1.7.1)
test-kitchen (2.2.5, 1.25.0)
test-unit (3.2.7)
thor (0.20.3)
timeliness (0.3.10)
tins (1.21.1)
tomlrb (1.2.8)
train (3.0.2, 1.7.6)
train-aws (0.1.11)
train-habitat (0.2.11)
train-winrm (0.2.3)
tty-box (0.4.0)
tty-color (0.5.0)
tty-cursor (0.7.0)
tty-prompt (0.19.0)
tty-reader (0.6.0)
tty-screen (0.7.0)
tty-table (0.11.0)
tty-which (0.4.1)
uber (0.1.0)
unf (0.1.4)
unf_ext (0.0.7.2)
unicode-display_width (1.6.0)
unicode_utils (1.4.0)
webrick (default: 1.4.2)
winrm (2.3.2)
winrm-elevated (1.1.1)
winrm-fs (1.3.2)
wisper (2.0.0)
xmlrpc (0.3.0)
zlib (default: 1.0.0)
edmeister commented 5 years ago

Running into the same issue after upgrading to the latest versions.

lmayorga1980 commented 5 years ago

The error stopped happening after I switch to a string in the output.tf

before

value = ["${openstack_compute_instance_v2.agent.*.access_ip_v4}"]

after

value = "${openstack_compute_instance_v2.agent.access_ip_v4}"

edmeister commented 5 years ago

Yeah, this makes sense according to the error. Unfortunately I need the lists. It's probably something rather easy to fix, but my Ruby knowledge is non-existent.

lmayorga1980 commented 5 years ago

Ok I was able to test in both scenarios and it seems like there is an extra array of 1 element around the already existing array

Using Arrays in outputs.tf

https://github.com/newcontext-oss/kitchen-terraform/blob/943805dbb22ea2c4d40db5f311a4d2798658050b/lib/kitchen/terraform/system.rb#L42

This works because of that extra array return by @hosts = @hosts.+ Array hosts[0]

Maybe the proper logic needs to be added during the fetch method

https://github.com/newcontext-oss/kitchen-terraform/blob/943805dbb22ea2c4d40db5f311a4d2798658050b/lib/kitchen/terraform/system_hosts_resolver.rb#L30

edmeister commented 5 years ago

Apparently Terraform 0.12.7 made a nested list of the output, so that's why kitchen-terraform cannot parse it anymore:

consul_ips = [
         [
           "10.xxx.xxx.11",
           "10.xxx.xxx.11",
           "10.xxx.xxx.11",
         ],
       ]
lmayorga1980 commented 5 years ago

Interesting that I did not that change coming https://github.com/hashicorp/terraform/releases on their 0.12.7 release page.

edmeister commented 5 years ago

Apparently we still had explicit brackets surrounding some of our outputs, causing the nested lists.

lmayorga1980 commented 5 years ago

@aaron-lane I think this should be tagged as a bug with affect versions 0.12.x

aaron-lane commented 5 years ago

I think this could be partially addressed by #354, but as @edmeister noted, this is a result of Terraform 0.12 removing the need for much of the extraneous string interpolation from previous versions. Outputs which are simply forwarding lists from resources or other sources no longer need to be surrounded by brackets. I'm not clear on a use case for a nested list providing values to hosts_output, but if there is one, please share it here.

lmayorga1980 commented 5 years ago

This can be closed as I was able to update output.tf and remove the extra brackets.