Use .kitchen.yml file which cans specify where the terraform code exists to execute:
provisioner:
name: terraform
directory: path/to/terraform/code
variable_files:
- path/to/terraform/variables.tfvars
Create a main.tf in the test location which will buld all the infrastucture you want. the order of execution should be controlled by the dependencies of the resources.
Taking that your testing is in the same repository as your module, do something like this:
├── .kitchen.yml
├── Gemfile
├── Gemfile.lock
├── README.md
├── terraform
│ ├── my_module
│ ├── main.tf
│ └── variables.tf
├── test
├── main.tf
└── terraform.tfvars
the .kitchen.yml file should look something like this:
provisioner:
name: terraform
directory: test
variable_files:
- test/variables.tfvars
variables:
access_key: <%= ENV['AWS_ACCESS_KEY_ID'] %>
secret_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
Your test/main.tf will create the module with any other test code you want:
provider "aws" {
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
region = "${var.region}"
}
...
module "my_module" {
name = "foo"
source = "../terraform/my_module"
...
}
resource "aws_instance" "test_instance_1" {
...
}