Skip to content

Latest commit

 

History

History
 
 

examples

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Examples

This directory contains an example Terraform project that creates infrastructure on Amazon Web Services (AWS) and utilizes kitchen-terraform for testing the server instances.

While the complexity of the Terraform code has been kept to a minimum, it is possible that the configuration of a user's AWS account may still prevent the successful execution of this example.

Terraform Configuration

variables.tf defines the required inputs for the example module.

example.tf creates three server instances: two in the kitchen_terraform_example_1 group and one in the kitchen_terraform_example_2 group.

outputs.tf defines two output variables: the hostnames of the instances in the test suite's only group and an address to use in the suite's Inspec controls.

Test Kitchen Configuration

The Test Kitchen configuration includes all of the plugins provided by kitchen-terraform.

Driver

The driver has no configuration options.

Provisioner

The provisioner is configured to use a [variables file] to provide some of the variables required by the example module.

Transport

The SSH transport is used due to the AMI used in the example module.

Verifier

The verifier is configured with a single group named contrived.

The contrived group uses the value of the different_host_address output to define an Inspec control attribute named other_host_address and includes all of the suite's profile's controls. The group uses the value of the contrived_hostnames output to obtain the targets to execute the controls on and provides a static port and username based on the AMI used in the example module.

Platforms

The platforms configuration is currently irrelevant but must not be empty.

Suites

The suite name corresponds to the integration test directory pathname as usual.

Missing Configuration

Several required configuration options are missing from the Test Kitchen configuration; these must be provided in a local Test Kitchen configuration.

Before continuing, review the instructions on configuring the AWS account with an isolated user for enhanced security.

.kitchen.local.yml

---
transport:
  ssh_key: <pathname/of/private/ssh/key>
suites:
  - name: example
    provisioner:
      variables:
        - access_key=<aws_access_key_id>
        - public_key_pathname=<pathname/of/public/ssh/key>
        - secret_key=<aws_secret_access_key>

Executing Tests

WARNING Creating AWS resources could cost money and be charged to the AWS Account's bill; neither kitchen-terraform nor its maintainers are responsible for any incurred costs.

Assuming that the missing configuration has been provided, testing the example module is simple:

$ bundle install
$ bundle exec kitchen test --destroy always