Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support terraform test #107

Open
joshuaspence opened this issue Jun 24, 2024 · 2 comments
Open

Support terraform test #107

joshuaspence opened this issue Jun 24, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@joshuaspence
Copy link

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 joshuaspence added the enhancement New feature or request label Jun 24, 2024
@joshuaspence
Copy link
Author

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

@marboledacci
Copy link
Contributor

Hi @joshuaspence, any contribution is welcome. It looks like you already have part of the work done, feel free to submit a PR and we will review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants