Adding a new module repository for Terraform or OpenTofu
Module repositories for various systems can still be added.
Where to place the code
-
If the repository introduces no more dependencies, then the core code can be placed in the
iac-publishers-base-plugin
. -
If it does introduce additional dependencies i.e. AWS, Google Cloud etc., then it should be placed in a subproject of its own, which then will have a project dependency on
iac-publishers-base-plugin
andiac-base-plugin
.
-
If both are supported and additional dependencies are needed, then additional subprojects need to be created for both tools. This means that there will be three subprojects.
-
If only one of the two tools is supported, and additional dependencies are required, then all of the code can be placed within only one subproject.
-
If both are supported, but no additional dependencies are needed, then
opentofu-publishers-plugin
andterraform-publishers-plugin
can be extended.
Levels of configuration
There are two levels of configuration:
-
Configuration that applies to the target repository itself. This configuration is applied in the DSL block of the repository.
-
Configuration that applies specifically to the pairing of a repository and module. This is applied in a
module
block within the DSL block of the repository.
If no repository-module configuration is required, the repository base class should implement NoConfigurationModulePublishTarget
.
abstract class AbstractLocal extends ModuleRepository implements NoConfigurationModulePublishTarget {
@Override
void module(String moduleName) {
}
In most cases, repository-module configuration is required. Use ModulePublishTarget
and supply a configuration class.
abstract class ExampleRepo extends ModuleRepository implements ModulePublishTarget<Configurator> {
static class Configurator { (1)
}
@Override
void module(String moduleName, Action<T> c) { (2)
}
}
1 | The Configurator class becomes a DSL for configuring the pairing.
It is best to create instances via the ObjectFactory.newInstance Gradle API. |
2 | This ties a module to a publisher. This method is responsible for registering all tasks. It should also take care of not attempting tasks on subsequent calls. |
All base classes must also extend ModuleRepository