seb4stien

charmkeeper-terraform

Use this skill when asked to write, test or fix terraform modules for a charm.

seb4stien 0 Updated 6mo ago

Resources

1
GitHub

Install

npx skillscat add seb4stien/charmkeeper/charmkeeper-terraform

Install via the SkillsCat registry.

About this skill

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.

SKILL.md

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.12
    • juju provider: ~> 1.0
  • The module should only have a "model_uuid" variable, no "model" variable.

  • Lint terraform modules with terraform fmt --recursive and tflint --recursive (fix the errors and the warnings).

Testing

Writing terraform tests

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:/workdir

For each TERRAFORM_MODULE

multipass exec charmkeeper -d /workdir/$TERRAFORM_MODULE -- terraform init
multipass exec charmkeeper -d /workdir/$TERRAFORM_MODULE -- terraform test

CI 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-directories to 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.