Sign inSign up

mattffffff/terraform-test

By mattffffff

•Updated about 7 years ago

Forked from microsoft/terraform-test for terraform 0.12.

Image
0

357

mattffffff/terraform-test repository overview

⁠Overview

This Docker image (see Dockerfile) is for testing Azure Terraform modules.

⁠Usage

This image can be used for terraform lint or end to end tests against Azure.

⁠Lint Tests

These tests ensure consistency in formatting for the terraform module code.

Setup the environment variable which specifies the root path of the module code on the local machine.

export MODULE_PATH=/user/me/source/Azure/terraform-azurerm-modulename

Now run the lint tests:

docker run -v $MODULE_PATH:/tf-test/module --rm microsoft/terraform-test rake -f ../Rakefile build

⁠End to End Tests

These tests will execute a terraform apply to deploy the azure module as defined in the /test/integration directory and then terraform destroy to delete them.

⁠Pre-requisites

Azure Setup The container uses Azure SPN Keys to access Azure. The following environment variables need to be set on the local machine running the container image.

 ARM_SUBSCRIPTION_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
 ARM_CLIENT_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
 ARM_CLIENT_SECRET=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
 ARM_TENANT_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
 ARM_TEST_LOCATION=westus
 ARM_TEST_LOCATION_ALT=westus
⁠Log Setup

The logs generated by the test will be stored in the /tf-test/.kitchen directory in the container. Mount this directory to the location of your choice so you can keep the logs once the test have completed.

⁠Secret Setup

Some test may require SSH keys or other secrets to be passed to the container. For SSH keys, mount the directory where they are located as /root/.ssh in the container. If you are reusing your keys, the above command should be:

⁠Running the Tests

Setup the environment variable which specifies the root path of the module code on the local machine.

export MODULE_PATH=/user/me/source/Azure/terraform-azurerm-modulename

Now run the tests using this docker command:

docker run -v ~/.ssh:/root/.ssh/ -v $MODULE_PATH/logs:/tf-test/module/.kitchen -v $MODULE_PATH:/tf-test/module -e ARM_CLIENT_ID -e ARM_TENANT_ID -e ARM_SUBSCRIPTION_ID -e ARM_CLIENT_SECRET -e ARM_TEST_LOCATION -e ARM_TEST_LOCATION_ALT --rm microsoft/terraform-test rake -f ../Rakefile e2e

This may take a number of minutes depending on the size of the module and there will be no output to the terminal until the tests complete. To see progress, look at the files being generated and updated under the local $MODULE_PATH/logs directory.

Tag summary

Content type

Image

Digest

Size

586.9 MB

Last updated

about 7 years ago

docker pull mattffffff/terraform-test