Thank you for your interest in contributing to the Terraform MAAS Provider! We appreciate your help in making this project better. This document provides information on how to set up your development environment and best practices for contributing to the project.
- Terraform >= 1.4.x
- Go >= 1.23
- A MAAS installation running. See the maas-dev-setup repository for more information on a development setup.
- CLA signed with the email used with git and GitHub.
This project follows a fork-based development model with a single long-running master branch. All contributions should be made via pull requests (PRs) from forked repositories.
- Fork the Repository:
- Go to the repository on GitHub and click "Fork" in the top-right corner.
- Clone your fork locally:
git clone <https-or-ssh-url-to-your-fork> cd terraform-provider-maas
- Add the upstream repository (the original repo) as a second remote:
git remote add upstream <https-or-ssh-url-to-original>
- Create a Feature Branch:
git checkout -b feat/feature-name
- Keep Your Branch Up to Date:
- Before working, sync your branch with the latest changes from master:
git fetch upstream git checkout master git merge upstream/master
- Then, rebase or merge your feature branch if necessary:
git checkout feat/feature-name git rebase master
- Before working, sync your branch with the latest changes from master:
- Commit and Push Changes:
- Follow commit message guidelines (e.g., fix: correct typo in readme).
- Push your branch to your forked repository:
git push origin feat/feature-name
- Submit a Pull Request:
- Go to the your forked repository on GitHub.
- Click "New Pull Request". Select your feature branch to merge from your forked repo, into the master branch of the original repo.
- Address Review Feedback. Once approved, a maintainer will merge your PR. 🎉
We follow the Conventional Commits specification. Conventional Commits defines the following structure for the Git commit message:
<type>[scope][!]: <description>
[body]
[footer(s)]Where
typeis the kind of the change (e.g. feature, bug fix, documentation change, refactor).scopemay be used to provide additional contextual information (e.g. which system component is affected). If scope is provided, it’s enclosed in parentheses.!MUST be added if commit introduces a breaking change.descriptionis a brief summary of a change (try to keep it short, so overall title no more than 72 characters).footeris detailed information about the change (e.g. breaking change, related bugs, etc.).
- Run
make buildto build the provider binary locally, located in./bin. - Run
make create_dev_overridesand follow any output instructions. More info here. - Run
make create_dev_envto create a development directory and follow any output instructions. - In your
.devenvdirectory, use these commands to get started:- Run
terraform fmtto format themain.tffile. - Run
terraform initto initialize the provider. - Run
terraform planto see the changes that will be applied. - Run
terraform applyto apply the changes. These should be reflected in the MAAS environment. - Run
terraform destroyto destroy the resources.
- Run
Assuming you have already setup dev-overrides:
- Make a change to the provider.
- Rebuild the provider binary locally with
make build. - In your dev-env directory, you can immediately run
terraform applywith your new changes.
Tests are written as advised in the Terraform docs. They are split into unit tests and acceptance tests, with the latter creating real resources in the MAAS environment. Therefore, you will need to ensure MAAS is running locally for these tests to pass.
To run the tests:
-
Ensure
MAAS_API_KEY,MAAS_API_URL, andMAAS_VERSIONenvironment variables are set in your shell, corresponding to your running MAAS installation. -
Run the tests:
- Run the unit tests:
make test - Run both the unit tests and all Terraform acceptance tests:
make testacc
[!NOTE] You may need to set specific environment variables for some tests to pass, for example machine ids. Add these to your
env.shfile before sourcing it again, if required:export TF_ACC_NETWORK_INTERFACE_MACHINE=<system_id> # b68rn4 export TF_ACC_TAG_MACHINES=<system_id> # b68rn4 export TF_ACC_VM_HOST_ID=<system_id> # maas-host export TF_ACC_BLOCK_DEVICE_MACHINE=<system_id> # b68rn4 export TF_ACC_RACK_CONTROLLER_HOSTNAME=<name> # maas-dev
- Run a specific acceptance test:
make testacc TESTARGS="-run=TestAcc<resource_name>_basic" - Run a group of acceptance tests with names matching the regex:
make testacc TESTARGS="-run=TestAcc<resource_name>"
- Run the unit tests:
If acceptance tests fail or are interrupted, they may leave resources in your MAAS environment. Use sweepers to clean up these leftover test resources:
make sweepImportant: Sweepers will delete infrastructure. Only run them in test environments.
Sweepers require the same environment variables as acceptance tests (MAAS_API_KEY, MAAS_API_URL) plus any resource-specific variables (e.g., TF_ACC_NETWORK_INTERFACE_MACHINE). Test resources are identified by naming patterns (e.g., tf-nic-* for network interfaces) and will be automatically removed.
To run specific sweepers or pass additional options:
make sweep SWEEPARGS="-sweep-run=maas_network_interface"Check for existing issues here, or open a new one for bugs and feature requests.
Releases are handled by the maintainers, see RELEASING.md.