Extra Files
An Extra File is a file that the Runner should additionally add to the root of the Module after it fetches the source module. You can define either a Namespace Extra File (which will be added for all Modules in the Namespace) or a Module Extra File.
You can see the full specifications here:
Example Usage: Provider Initialization
One case where Extra Files are particularly useful is when the referenced module does not have a providers.tf file. This is often the case, since providers are normally initialized from the root project, and pure modules are normally referenced from there, with the providers being passed in. In this case you could use two Extra Files to create the following two files. I.e., one to define how the providers should be initialized, and one to allow you to pass additional variables the providers might need.
extra_providers.tf:
provider "azurerm" {
subscription_id = var.subscription_id
tenant_id = var.tenant_id
features {}
}extra_providers_vars.tf:
variable "subscription_id" {}
variable "tenant_id" {}Example Usage: Backend Configuration
In Terraform / OpenTofu the backend must be defined in the terraform block. It cannot be set from the command line. Typically in a pure module the root.tf looks like this (i.e. there is no backend block), so a local backend will be used. The backend is normally defined in the root project that references the module.
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "4.20.0"
}
}
}In this case you can create an Extra File as follows in order to define which backend should be used:
extra_backend.tf:
terraform {
backend "azurerm" {}
}How the backend should be configured is something you can control either by passing in relevant Env Vars, or by setting the init_backend_args parameter on the Module, as is shown in the example usage here.