https://github.com/nilsty/robotframework-terraformlibrary
A RobotFramework wrapper for the Terraform / OpenTofu CLI
https://github.com/nilsty/robotframework-terraformlibrary
opentofu robotframework terraform
Last synced: 8 months ago
JSON representation
A RobotFramework wrapper for the Terraform / OpenTofu CLI
- Host: GitHub
- URL: https://github.com/nilsty/robotframework-terraformlibrary
- Owner: Nilsty
- License: apache-2.0
- Created: 2024-07-12T18:21:40.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-22T16:25:42.000Z (over 1 year ago)
- Last Synced: 2025-02-07T10:50:12.495Z (over 1 year ago)
- Topics: opentofu, robotframework, terraform
- Language: Python
- Homepage: https://nilsty.github.io/robotframework-terraformlibrary/
- Size: 93.8 KB
- Stars: 6
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Terraform Library for Robot Framework
[](https://pypi.org/project/robotframework-terraformlibrary/)[](https://pypi.python.org/pypi/robotframework-terraformlibrary)
TerraformLibrary is a wrapper for the [Hashicorp Terraform CLI](https://developer.hashicorp.com/terraform/cli)
The library can also be configured to run [OpenTofu](https://opentofu.org/) instead of Terraform.
---
## Keyword Documentation
[Link to the keyword documentation](https://nilsty.github.io/robotframework-terraformlibrary/terraformlibrary.html)
---
## 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.
``` robotframework
*** 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](https://pypi.org/project/robotframework-terraformlibrary/).
To release a new version of the library to PyPi, a few steps are needed.
- update the version number in [pyproject.toml](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](.github/workflows/publish.yml) publishing the release to PyPi via a trusted publisher setup.