Skip to content

Commit

Permalink
doc for terraform test module
Browse files Browse the repository at this point in the history
  • Loading branch information
mschuchard committed Aug 15, 2024
1 parent e520896 commit 9e75f22
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 5 deletions.
2 changes: 1 addition & 1 deletion plugins/modules/goss_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
description: The specific gossfile used for rendering the output.
required: false
default: goss.yaml
type: str
type: path
package:
description: The package type to use.
required: false
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/goss_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
description: The specific gossfile used for serveing the output.
required: false
default: goss.yaml
type: str
type: path
max_concur:
description: Max number of tests to run concurrently
required: false
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/goss_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
description: The specific gossfile used for validating the output.
required: false
default: goss.yaml
type: str
type: path
max_concur:
description: Max number of tests to run concurrently
required: false
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/terraform_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
description: Location of the directory containing the Terraform root module config files.
required: false
default: cwd
type: str
type: path
force_copy:
description: Suppress prompts about copying state data when initializating a new state backend. This is equivalent to providing a "yes" to all confirmation prompts.
required: false
Expand Down Expand Up @@ -90,7 +90,7 @@
description: The raw Terraform command executed by Ansible.
type: str
returned: always
sample: 'terraform init -machine-readable /home/terraform'
sample: 'terraform init /home/terraform'
'''

from pathlib import Path
Expand Down
87 changes: 87 additions & 0 deletions plugins/modules/terraform_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright (c) Matthew Schuchard
# MIT License (see LICENSE or https://opensource.org/license/mit)
"""ansible module for terraform test"""
__metaclass__ = type

DOCUMENTATION = r'''
---
module: terraform_test
short_description: Module to manage Terraform automated integration tests against current configuration.
version_added: "1.1.0"
description: Executes automated integration tests against the current Terraform configuration. Terraform will search for .tftest.hcl files within the current configuration and testing directories. Terraform will then execute the testing run blocks within any testing files in order, and verify conditional checks and assertions against the created infrastructure. This command creates real infrastructure and will attempt to clean up the testing infrastructure on completion. Monitor the output carefully to ensure this cleanup process is successful.
options:
cloud_run:
description: Terraform will execute this test run remotely using HCP Terraform or Terraform Enterpise. You must specify the source of a module registered in a private module registry as the argument to this parameter. This allows Terraform to associate the cloud run with the correct HCP Terraform or Terraform Enterprise module and organization.
required: false
type: str
config_dir:
description: Location of the directory containing the Terraform root module config files.
required: false
default: cwd
type: path
filter:
description: Terraform will only execute the test files specified by this parameter.
required: false
default: []
type: list
json:
description: Machine readable output will be output to stdout in JSON format.
required: false
default: false
type: bool
test_dir:
description: Set the Terraform test directory.
required: false
default: tests
type: path
var:
description: Set values for one or more of the input variables in the root module of the configuration.
required: false
default: []
type: list
var_file:
description: Load variable values from the given HCL2 files in addition to the default files terraform.tfvars and *.auto.tfvars.
required: false
default: []
type: list
requirements:
- terraform >= 1.0
author: Matthew Schuchard (@mschuchard)
'''

EXAMPLES = r'''
# execute tests in /path/to/terraform_config_dir/my_tests
- name: Execute tests in /path/to/terraform_config_dir/my_tests
mschuchard.general.terraform_test:
config_dir: /path/to/terraform_config_dir
test_dir: my_tests
# execute tests for current directory with json output and variable inputs
- name: Execute tests for current directory with json output and variable inputs
mschuchard.general.terraform_test:
json: true
var:
- var_name: var_value
- var_name_other: var_value_other
var_file:
- one.pkrvars.hcl
- two.pkrvars.hcl
'''

RETURN = r'''
command:
description: The raw Terraform command executed by Ansible.
type: str
returned: always
sample: 'terraform test -json'
'''

0 comments on commit 9e75f22

Please sign in to comment.