inspec / kitchen-inspec

Test-Kitchen Plugin for InSpec
Other
109 stars 58 forks source link

'aws_lambda' resource not identified #275

Open mihirvijdeshpande opened 3 years ago

mihirvijdeshpande commented 3 years ago

Version:

Test Kitchen version 2.10.0

Environment:

Ubuntu 20.04 Terraform 13.5 ruby 2.7.1

Using Kitchen-terraform to test aws infra

Scenario:

We are trying to run tests on resource aws_lambda but are unable to, the verify command fails with error.

Steps to Reproduce:

Write the following code in lambda_spec.rb:

control 'lambda' do
    describe aws_lambdas('tdd-terraform-lambda') do
        it { should exist}
        its ('handler') { should eq 'lambda'}
#        its ('version') { should eq '$LATEST' }
        its ('runtime') { should eq 'go1.x' }
    end
end

Tree:

.
├── Gemfile
├── Gemfile.lock
├── <redacted>.pem
├── main.tf
├── output.tf
├── src
│   ├── lambda
│   └── lambda.go
├── tdd-terraform-lambda.zip
├── terraform.tfstate.d
├── terraform.tfvars
├── test
│   └── integration
│       └── default
│           ├── controls
│           │   ├── ec2_spec.rb
│           │   ├── httpd_spec.rb
│           │   ├── lambda_spec.rb
│           ├── files
│           │   └── terraform.json
│           └── inspec.yml
├── user-data
│   └── user-data.sh
└── variables.tf

kitchen.yml:

---
driver:
  name: terraform
  variable_files:
    - terraform.tfvars
  region: "us-east-1"

provisioner:
  name: terraform

platforms:
  - name: ubuntu

verifier:
  name: terraform
  systems:
    - name: default
      controls:
        - httpd
      backend: ssh
      user: <redacted>
      key_files:
        - <redacted>.pem
      hosts_output: private_ip
      reporter:
        - documentation
    - name: aws
      controls:
        - lambda
      backend: aws
      reporter:
        - documentation

suites:
  - name: default

AWS Credentials exported in the ENV

run command kitchen converge to create aws resources >> this Passes

run command kitchen verify to run tests >> this Fails

Expected Result:

Run test and return result if Lambda function is present (or not)

Actual Result:

 1) Control Source Code Error /home/ubuntu/tdd-test/terraform-tdd/kitchen/test/integration/default/controls/lambda_spec.rb:1
     Failure/Error: its(location) { fail e.message } # rubocop: disable Style/SignalException
     RuntimeError:
       undefined local variable or method `aws_lambdas' for #<Inspec::Rule:0x00007f5e88277070>