Developing a module is slightly trickier than just writing straight Terraform. Here are some tips to help you ease the process.
When writing a module you will need some code to call that module and test if it works. Far and away the easiest way to do this is create a subdirectory for your module, put all your module config in there, call it from the main Terraform config and finally copy all that config to this repo when it is working.
module "example" {
source = "./module"
...
}
If the workspace is processed locally i.e. not in Terraform Cloud, you can have this repo checked out locally and link to it within the module using a relative or full path.
Note. This will not work if the workspace is processed in Terraform Cloud as TFC cannot resolve the path.
module "example" {
source = "../../oak-terraform-modules/modules/example"
...
}
It is possible to work from this repo, although this is a slower process.
- Point the module to your new branch
- Push your changes to Github
- Update Terraform
terraform init -upgrade
- Repeat from 2. until it works
Note. If the branch name has a /
in it you need to replace that with the URL encoded equivalent: %2F
module "example" {
source = "github.com/oaknational/oak-terraform-modules//modules/example?ref=feat%2Fexample"
...
}