Use this skill when asked to write, test or fix terraform modules for a charm.
Resources
1Install
npx skillscat add seb4stien/charmkeeper/charmkeeper-terraform Install via the SkillsCat registry.
This skill guides writing, testing, and fixing Terraform modules for Juju charms by enforcing implementation standards and running tests locally or in CI. It addresses the need for consistent, tested charm infrastructure code across the repository. Use it when working on Terraform modules that deploy or manage charms via Juju.
Plan:
- Find the terraform modules in the repository.
- Ensure each terraform module is following the implementation standards.
- Run the tests to ensure the modules work as expected.
Implementation standards
Expected versions:
terraform: ~> 1.12juju provider: ~> 1.0
The module should only have a "model_uuid" variable, no "model" variable.
Lint terraform modules with
terraform fmt --recursiveandtflint --recursive(fix the errors and the warnings).
Testing
Writing terraform tests
The
terraform/testsfolder should look like: https://github.com/canonical/platform-engineering-charm-template/tree/main/terraform/testsThere is a
setupfolder to configure the model. Follow the example from https://raw.githubusercontent.com/canonical/platform-engineering-charm-template/refs/heads/main/terraform/tests/setup/main.tfThere is
main.tftest.hclfile. Follow the example of https://raw.githubusercontent.com/canonical/platform-engineering-charm-template/refs/heads/main/terraform/tests/main.tftest.hcl- Ensure that there is a renovate directive above each "revision" line.
After adapting the tests. There should not be a
terraform/tests/main.tffile.
Local testing
The terraform tests should be run in a virtual machine named "charmkeeper".
If the machine doesn't exist, create it with: scripts/create-charmkeeper-vm.sh.
If not already done, mount the working directory folder in the machine with
multipass mount --type native $PWD charmkeeper:/workdirFor each TERRAFORM_MODULE
multipass exec charmkeeper -d /workdir/$TERRAFORM_MODULE -- terraform init
multipass exec charmkeeper -d /workdir/$TERRAFORM_MODULE -- terraform testCI testing
This workflow is the reference to use to implement or update CI tests: https://raw.githubusercontent.com/canonical/platform-engineering-charm-template/refs/heads/main/.github/workflows/test_terraform_modules.yaml
- Adapt the k8s-controller and lxd-controller value depending on the charm type.
- Adapt the
terraform-directoriesto reflect where the modules are in this charm.
Maintain
Configuring renovate
Configure renovate like https://raw.githubusercontent.com/canonical/platform-engineering-charm-template/refs/heads/main/renovate.json to
- Add a charmhub datasource and use it.
- Add a regex custom manager for revisions.
- Set ignorePath to an empty array to not exclude the tests/ folders of terraform.