Both of the protocols allow for a base path.
For a provider registry, you can put a URL with a path in the service discovery document for your domain. For example:
{
"providers.v1": "https://terraform.example.com/repositories/dabesteam/terraform_providers/"
}
If your implementation of the API lives on the same host as the discovery document itself, which seems to be the case in your examples here, then you can use a root-relative URL to specify the location and thus avoid duplicating the hostname:
{
"providers.v1": "/repositories/dabesteam/terraform_providers/"
}
(Terraform Registry itself uses this root-relative URL approach in the registry.terraform.io
discovery document.)
For a provider network mirror, there is no service discovery indirection and the base URL is just specified directly in the CLI configuration’s network_mirror
block:
provider_installation {
network_mirror {
url = "https://terraform.example.com/repositories/dabesteam/terraform_providers"
}
}
The provider registry protocol may be harder to implement via static files because it doesn’t use a .json
extension for the metadata endpoints and not all static site systems are capable of serving with the application/json
content type unless that extension is present.
The network mirror protocol, on the other hand, was intentionally designed to be static-file-hosting friendly by using metadata URLs that end with index.json
.
If Nexus’s capabilities are friendly to implementing the registry protocol then I’d recommend it, because that’ll be the easier path for users of the hypothetical terraform.example.com/awesomecorp/happycloud
provider. Terraform will, with its default settings, automatically know to talk to the provider registry at terraform.example.com
in order to find a package for that provider, and so there’ll be no special CLI configuration required in order to resolve that provider.
However, if you do find that the registry protocol is not implementable withing the capabilities of Nexus you could instead set up a “pseudo-mirror” of providers that belong to a hostname that doesn’t actually have an upstream registry, at the expense of having to explicitly configure Terraform on each machine where you’ll run it so it will use the network mirror for that provider, instead of the direct
installation method (which consults the registry host given in the provider address):
provider_installation {
network_mirror {
url = "https://terraform.example.com/repositories/dabesteam/terraform_providers"
include = ["terraform.example.com/*/*"]
}
direct {
exclude = ["terraform.example.com/*/*"]
}
}
If you put the above in the CLI configuration (not your module .tf
files) then it will tell Terraform to consult the given mirror URL for providers that have the origin host terraform.example.com
, but to use the normal direct lookup method for all other providers.