Is it possible to get data from the terraform registry via an API in some way?

Hello, I’m just wondering if there is any way I could possibly get data from the terraform registry via an API or something? I’m trying to get info into a bash script.

For example, If I were to run an api call against Terraform Registry I would like to retrieve all possible arguments and attributes in a list. Is this possible?

Hi @andre.pilakis,

The general module registry protocol that all module registries implement is focused only on the problem of finding a module to install, and doesn’t expose any details about the contents of the module.

However, if you are working only with modules on the official public Terraform registry at registry.terraform.io you can use the public registry’s own API, which has additional operations for retrieving certain metadata about modules.

I think the specific operation you’d use for your use-case of finding the input variables and output values would be Get a Specific Module.

The name of that operation is a bit of a misnomer because it’s actually getting information about a specific module package – an entry in the module registry refers to a repository that could potentially contain many modules. So in the example response you’ll see that there’s both a root property describing the metadata of the module that’s at the root of the package and also submodules giving similar information about modules included in subdirectories of the repository.

If you have a module address like example/foo/bar then that’s the address of a root module in the module package at example/foo/bar, described by the root property. If you have an address like example/foo/bar//modules/beep then you’d need to search in the submodules array for an object which has path set to modules/beep.

There’s a helper library terraform-registry-address which has functions for parsing Terraform’s registry address syntax, so if you are working in Go then you could use tfaddr.ParseModuleSource to parse an address like example/foo/bar//modules/beep into its component parts. The Package field of the result would be the address to send to the registry API, while the Subdir field is the path to search for in submodules, if it’s not an empty string.

(If you’re expecting arbitrary input then probably also best to check whether mod.Package.Host == tfaddr.DefaultModuleRegistryHost, so you can fail quickly when given an address in some other registry that wouldn’t necessarily support this extended API. The constant tfaddr.DefaultModuleRegistryHost contains the hostname of the public registry, registry.terraform.io.)