Forced Remote Source

This Decorator enforces that module. have remote sources. It is usefull in pre-commit hooks and development scenatios.

Szenario:

You are developing a large terraform/tofu project with different modules thre are pushed to an terraform module registry. But for development purposes you linked the module localy together.

With this Decorator you can ensure only a version of the remote source module are pushed to git. ( If you use the check for this decorator in your pre-commit settings )

Terraform

Write the following Decorator above modules to enforce this module must have a local path to his source.

This decorator works only above module blocks. It has no additional parameters

Example usage # @forcedremotesource

The following Code tells tfutility this module should have an remote source. But as you can see the module has an local path

test.tf
1# @forcedremotesource
2module "samplemodule" {
3   source = "../local/path"
4}

shell:

1tfutility forcedremotesource test.tf
2ERROR: Module Block had no Version Defined in main.tf:4
3ERROR: Module Block has no Remote Source in main.tf:4

so the following command loggs error and exit the whole application with an exit code 1

test.tf
1# @forcedremotesource
2module "samplemodule" {
3   source = "remoteurl@example.com"
4}

This raises an version missing error

1$ tfutility forcedremotesource test.tf
22024-11-18 23:05:25 ERROR: Module Block has no Remote Source in test.tf:4

Its possible to prevent error messages or exit 1 status codes with the –silent and –allow-failure arguments

Command Line Arguments

Usage in Terraform

usage: tfutility forcedremotesource [-h] [-s] [--allow-failure]
                                    paths [paths ...]

Positional Arguments

paths

Path to one or more TF-Files. Its also Possible to set a folder. It searches only *.tf files

Named Arguments

-s, --silent

Prevent any log output

Default: False

--allow-failure

If this flag was set, the module logs only all occurences but does not exit with code 1

Default: False