CircleCI-Public / terraform-orb

Deploy your infrastructure via a CircleCI pipeline using the Terraform orb. Integrate Infrastructure-as-Code (IaC) to help provision and manage any cloud, infrastructure, or service of your choice.
https://circleci.com/orbs/registry/orb/circleci/terraform
MIT License
10 stars 44 forks source link

Support `terraform test` #107

Open joshuaspence opened 2 months ago

joshuaspence commented 2 months ago

Is your feature request related to a problem? Please describe. I have written unit tests for a Terraform module (see https://developer.hashicorp.com/terraform/language/tests) and want to run them in CircleCI.

Describe the solution you'd like A terraform/test command and terraform/test job.

Describe alternatives you've considered I am currently using my own job definition to achieve this.

jobs:
  terraform-test:
    description: 'Execute Terraform tests.'
    executor:
      name: 'terraform/default'
      resource_class: '<< parameters.resource_class >>'
      tag: '<< parameters.tag >>'
    parameters:
      checkout:
        description: 'Perform checkout as first step in job.'
        type: 'boolean'
        default: false
      path:
        description: 'Path to the Terraform module.'
        type: 'string'
        default: '.'
      resource_class:
        description: 'Specify the resource class for Docker executor.'
        type: 'string'
        default: 'medium'
      tag:
        description: 'Specify the Terraform Docker image tag for the executor.'
        type: 'string'
        default: '1.0.0'
      test_directory:
        description: 'Set the Terraform test directory.'
        type: 'string'
        default: 'tests'
      timeout:
        description: 'Configure a custom timeout limit'
        type: 'string'
        default: '10m'
    steps:
      - when:
          condition: '<< parameters.checkout >>'
          steps:
            - 'checkout'
      - run:
          command: 'terraform -chdir=<< parameters.path >> init -input=false -test-directory=<< parameters.test_directory >>'
          name: 'terraform init'
      - run:
          command: 'terraform -chdir=<< parameters.path >> test -test-directory=<< parameters.test_directory >>'
          name: 'terraform test'
          no_output_timeout: '<< parameters.timeout >>'
joshuaspence commented 2 months ago

I am happy to submit a PR if there is interest in this.