Skip to content

Nilsty/robotframework-terraformlibrary

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform Library for Robot Framework

PyPIPyPi downloads

TerraformLibrary is a wrapper for the Hashicorp Terraform CLI

The library can also be configured to run OpenTofu instead of Terraform.


Keyword Documentation

Link to the keyword documentation


Installation

If you already have Python >= 3.8 with pip installed, you can simply run:
pip install --upgrade robotframework-terraformlibrary


Getting started

Some examples how to import and use the library.

*** Settings ***
Library            TerraformLibrary

*** Variables ***
${PATH_TO_TERRAFORM_SCRIPT}    ${CURDIR}/terraform-script

*** Test Cases ***
Run Terraform Init
    ${rc}    ${output}    Terraform Init    ${PATH_TO_TERRAFORM_SCRIPT}

Run Terraform Plan
    Set TF Var    my_var    test_value
    ${rc}    ${output}    Terraform Plan    ${PATH_TO_TERRAFORM_SCRIPT}
    Should Contain    ${output}    Plan: 1 to add, 0 to change, 0 to destroy.

Run Terraform Apply
    ${rc}    ${output}    Terraform Apply    ${PATH_TO_TERRAFORM_SCRIPT}
    Should Contain    ${output}    Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Inspect Terraform State
    ${output}    Get Terraform State    ${PATH_TO_TERRAFORM_SCRIPT}
    Should Be Equal As Strings    ${output["values"]["root_module"]["resources"][0]["name"]}    foo

Run Terraform Destroy
    ${rc}    ${output}    Terraform Destroy    ${PATH_TO_TERRAFORM_SCRIPT}
    Should Contain    ${output}    Destroy complete! Resources: 1 destroyed.

Development

Install poetry on your system with pip install poetry.

Then setup the current project in a virtual env for development:

$ poetry env use $(which python3)
$ source $(poetry env info --path)/bin/activate
$ poetry install

Run the unit tests:

$ poetry run invoke utests

Run the acceptance tests:

$ poetry run invoke atests

Run all tests:

$ poetry run invoke tests

Exit the virtualenv

deactivate

Releasing new versions to PyPi

The Robotframework-TerraformLibrary is released on PyPi.org. To release a new version of the library to PyPi, a few steps are needed.

  • update the version number in pyproject.toml
  • rebuild the keyword documentation with the command poetry run libdoc
  • create a pull request with the updated pyproject.toml and the keyword documentation under docs/terraformlibrary.html
  • once the pull request is merged a new github release can be created and published which will trigger a github action publishing the release to PyPi via a trusted publisher setup.