The terraform publish
command packs and deploys the Terraform modules to the designated Terraform repository in Artifactory.
Before running the terraform publish
command on a project for the first time, the project should be configured using the terraform-config
command.
The modules are deployed to the configured Terraform repository according to the following layout.
Note that the moduleName
is determined by the name of the module directory
namespace/moduleName/provider/tag.zip
To publish a specific module, access the Modules’ root directory.
Before running terraform publish
, cd into the directory which contains the Terraform modules. Note that those modules will later share common layout arguments (namespace, provider, and tag) in Artifactory.
Rules and Guidelines for Packing Terraform modules
The File system is scanned from the current working directory.
A directory that contains at least one file with a
.tf
extension is considered as a Terraform module and all its content will be packed in one zip file (including the submodules directories) and will be deployed to Artifactory.Recursive scanning does not run inside the module directory after it is packed, as a result, the submodules will not be packed and deployed separately to Artifactory.
Adding Exclusions Using Patterns
There is an option to set patterns to exclude modules that may contain:
A directory that matches the pattern will not be scanned.
Files that match the pattern won’t be packed in the relevant zip file.
The following table lists the command arguments and flags:
Argument/ Flag | Description |
---|---|
Command-name | terraform publish |
Abbreviation | tfp |
--exclusions | [Optional] A list of Semicolon-separated exclude patterns. Allows using wildcards. |
Command arguments | |
--namespace | The namespace of the Terraform project that its modules are being published. |
--provider | The provider of the Terraform project that it’s modules are being published. |
--tag | The tag of the modules that are being published. |
Example of Packing and Publishing Terraform Modules
Before running this command on a project for the first time, the project should be configured using theterraform-config
command.
To pack and publish the Terraform module, run the following command.
This command packs and deploys all the modules under the current working directory.
The modules will be published to the configured repository, using this layout: tera/moduleName/aws/v0.1.2.zip
.
Modules and files which include test
and ignore
will be excluded (read more in the “exclusions” section).
jf tf p -namespace=tera -provider=aws -tag=v0.1.2 -exclusions=”*test*;*ignore*"
For more information try this terraform project example.