Terraform/OpenTofu and Terraform Backend Repositories
Terraform and OpenTofu are infrastructure as code (IaC) tools you use to build, change, and version infrastructure. Integrating Terraform and OpenTofu with JFrog Artifactory gives you a private registry for modules and providers, and remote state storage for your configurations. For more information, see the Terraform documentation and the OpenTofu documentation.
Artifactory fully supports Terraform repositories, including the following capabilities:
- Storing private Terraform modules and providers in local Terraform Registry repositories.
- Proxying and caching modules and providers from remote sources, including Git repositories, GitLab, Terraform Cloud, and other Artifactory endpoints.
- Resolving and deploying modules and providers through a single URL with a virtual repository that aggregates local and remote registries.
- Publishing and installing modules and providers with the Terraform CLI or the OpenTofu CLI. You can publish modules with the JFrog CLI.
- Storing Terraform remote state in local Terraform Backend repositories, with state locking, encrypted state files, state snapshot history, and named workspaces.
- Calculating metadata for modules and providers stored in local Terraform repositories.
Warning
Terraform state files in Terraform Backend repositories are encrypted with the
master.key. Back up themaster.keyand keep it safe. If you lose the key, Artifactory can't recover the state files that depend on it.
Note
Terraform Backend repositories in Artifactory are aligned with HashiCorp common practices and support the official HashiCorp enterprise-grade Terraform backend provider. This includes features such as locking, data encoding, smart comparisons, and additional common practices.
Terraform Backend repositories in Artifactory are unaffected by the HashiCorp
artifactorybackend provider deprecation action from 2022.
Get Started with Terraform Registry and Terraform Backend
To get started working with Terraform Registry and Terraform Backend, complete the following main steps:
Create a Terraform Repository
This topic describes how to create a Terraform repository. You need to create one before you upload and install Terraform packages. The following repository types are available:
- Local repositories: Where you store and share first-party and second-party packages with your organization.
- Remote repositories: Enable you to download from any remote location including external package registries or other Artifactory endpoints.
- Virtual repositories: Enable aggregating remote and local repositories enabling your organization to scale by providing a single URL that provides access to multiple repositories and types.
For more information on JFrog repositories, see Repository Management.
Prerequisite: You need Admin or Project Admin permissions to create a Terraform repository. If you don't have Admin permissions, the option will not be available.
To create a Terraform repository:
-
In the Administration module, click Repositories > Create a Repository.

-
Select the repository type you want to create: Local, Remote, or Virtual.
Note
Terraform Backend repositories are available as local repositories only.
-
Select Terraform / OpenTofu or Terraform Backend. For more information, see Terraform Registry and Backend.
-
Configure the required fields:
-
For Local Repositories:
- In the Repository Key field, type a meaningful name for the repository. For example,
terraform-local. - From Terraform Registry repositories, select MODULE or PROVIDER from the Terraform Registry Type list. This option sets either
terraform-module-defaultorterraform-provider-defaultas the repository layout. - If you selected PROVIDER, set a GPG key pair for the repository. For more information, see Generate GPG Keys and Upload GPG Keys.
For more information on local repositories and all their possible settings, see Local Repositories.
- In the Repository Key field, type a meaningful name for the repository. For example,
-
For Remote Repositories, verify the URL and update if needed. For more information on remote repositories and all their possible settings, see Remote Repositories and Configure a Remote Terraform Repository.
-
For Virtual Repositories, select one or more local or remote repository types to include in the virtual repository. For more information on virtual repositories and all their possible settings, see Virtual Repositories.
-
-
Click Create Local Repository, Create Remote Repository, or Create Virtual Repository. The repository is created, and the Repositories page opens.
Connect Your Terraform or OpenTofu Client to Artifactory
This section provides details on configuring Terraform and OpenTofu to work with Artifactory.
Prerequisite: Before connecting your Terraform/OpenTofu client to Artifactory, you must have an existing Terraform repository in Artifactory. For more information, see Create a Terraform Repository
Artifactory supports Terraform CLI 1.0.0 or above. Use the OpenTofu CLI with the same repository configuration.
Logged in vs. Anonymous Access: You can work with Artifactory as a logged-in user or an anonymous user. To use anonymous access, configure it in the Administration module under Security > General. For more information, see Allow Anonymous Access.
Configure Your Client for Terraform Registry
Use the Terraform Registry to store, version, and share private modules and providers. Configure your Terraform or OpenTofu client to authenticate with Artifactory and to install providers from your Terraform repository.
To configure your client for the Terraform Registry:
-
Run the following command to authenticate the client. The command generates an access token and saves it in
~/.terraform.d/credentials.tfrc.json.<CLIENT> login <JFROG_HOSTNAME>Where:
<CLIENT>: The client command. Possible values are:-
terraformfor Terraform CLI tofufor OpenTofu CLI
-
<JFROG_HOSTNAME>: Your JFrog Platform hostname. Don't includehttps://.
For example:
terraform login company.jfrog.iotofu login company.jfrog.io -
Click Approve on the Terraform CLI Authorization page.
The command line shows a success message after you obtain and save the token.
-
To resolve providers, add the following block to the Terraform CLI configuration file. The file is
~/.terraformrcon Linux and Unix, and%APPDATA%/terraform.rcon Windows.provider_installation { direct { exclude = ["<REGISTRY_HOSTNAME>/*/*"] } network_mirror { url = "https://<JFROG_HOSTNAME>/artifactory/api/terraform/<REPO_KEY>/providers/" } }Where:
<REGISTRY_HOSTNAME>: The appropriate registry hostname. Possible values are:registry.terraform.iofor Terraformregistry.opentofu.orgfor OpenTofu
<JFROG_HOSTNAME>: Your JFrog Platform hostname. Don't includehttps://.<REPO_KEY>: The Terraform repository key. If the configured depth is 0, point the base URL to the root of the repository.
For example:
provider_installation { direct { exclude = ["registry.terraform.io/*/*"] } network_mirror { url = "https://company.jfrog.io/artifactory/api/terraform/terraform-local/providers/" } }provider_installation { direct { exclude = ["registry.opentofu.org/*/*"] } network_mirror { url = "https://company.jfrog.io/artifactory/api/terraform/terraform-local/providers/" } }
The Provider Registry Protocol doesn't require changes to the .terraformrc file.
Note
You can also use JFrog Set Me Up to copy the snippet populated with your token and environment. For more information, see Use Artifactory Set Me Up for Configuring Package Manager Clients.
Next Steps:
Configure Your Client for Terraform Backend
Use a Terraform Backend repository to store your Terraform state remotely, with state locking and encrypted state files. Configure your Terraform or OpenTofu client to use Artifactory as its remote backend.
To configure the Terraform or OpenTofu client for Terraform Backend:
-
Run the following command to authenticate the client. The command generates an access token and saves it in
~/.terraform.d/credentials.tfrc.json.<CLIENT> login <JFROG_HOSTNAME>Where:
<CLIENT>: The client command. Possible values are:terraformfor Terraform CLItofufor OpenTofu CLI
<JFROG_HOSTNAME>: Your JFrog Platform hostname. Don't includehttps://.
For example:
terraform login company.jfrog.iotofu login company.jfrog.io -
Click Approve on the Terraform CLI Authorization page.
The command line shows a success message after you obtain and save the token.
-
To use Artifactory for remote state storage and locking, add the following block to
main.tf.terraform { backend "remote" { hostname = "<JFROG_HOSTNAME>" organization = "<REPO_KEY>" workspaces { prefix = "<WORKSPACE_PREFIX>" } } }Where:
<JFROG_HOSTNAME>: Your JFrog Platform hostname. Don't includehttps://.<REPO_KEY>: The Terraform Backend repository key.<WORKSPACE_PREFIX>: The prefix for workspace names in this repository.
For example:
terraform { backend "remote" { hostname = "company.jfrog.io" organization = "terraform-backend-local" workspaces { prefix = "my-prefix-" } } }
Note
You can also use JFrog Set Me Up to copy the snippet populated with your token and environment. For more information, see Use Artifactory Set Me Up for Configuring Package Manager Clients.
Next Steps:
Deploy Terraform Resources
Deploying Terraform resources makes them available to other users.
You can deploy Terraform resources via API or UI:
- Deploy Terraform Modules via API
- Deploy Terraform Providers via API
- Deploy Terraform Resources via the UI
Deploy Terraform Modules via API
You can publish Terraform modules via the REST API. When using this method, you can deploy by checksum or from an archive.
To deploy a Terraform module with the REST API:
-
Run the following command:
curl -u<USERNAME>:<TOKEN> -XPUT "<JFROG_PLATFORM_URL>/artifactory/<REPOSITORY_KEY>/<NAMESPACE>/<MODULE_NAME>/<PROVIDER_NAME>/<VERSION>.zip" -T <PATH_TO_FILE>Where:
<JFROG_PLATFORM_URL>: The URL of your JFrog Platform<USERNAME>: Your JFrog Platform username<TOKEN>: Your JFrog Platform password<REPOSITORY_KEY>: The name of your repository<NAMESPACE>: The owner or organization for this module<MODULE_NAME>: The name of the module<PROVIDER_NAME>: The name of the provider<VERSION>: The specific version of the module you're deploying<PATH_TO_FILE>: The path to the file on your local machine that you send to Artifactory
For example:
curl -uadmin:<TOKEN> -XPUT "https://company.jfrog.io/artifactory/terraform-local/jfrog/test-module/test-provider/1.0.0.zip" -T test-module-1.0.0.zip
Deploy Terraform Providers via API
You can publish Terraform providers via the REST API. When using this method, you can deploy by checksum or from an archive. The REST API supports the following deployment methods:
For more information, see Terraform Registry and Backend.
Deploy with the Provider Registry Protocol
Publish the provider binary, its GPG signature, and the SHA256SUMS file to an Artifactory repository.
To deploy a provider with the Provider Registry Protocol:
-
Deploy the provider binary
.zipfile:curl -u<USERNAME>:<TOKEN> -XPUT "<JFROG_PLATFORM_URL>/artifactory/<REPOSITORY_KEY>/<NAMESPACE>/<PROVIDER_NAME>/<VERSION>/terraform-provider-<PROVIDER_NAME>_<VERSION>_<OS>_<ARCH>.zip" -T <PATH_TO_FILE>Where:
<JFROG_PLATFORM_URL>: The URL of your JFrog Platform<USERNAME>: Your JFrog Platform username<TOKEN>: Your JFrog Platform password<REPOSITORY_KEY>: The name of your repository<NAMESPACE>: The owner or organization for this provider<PROVIDER_NAME>: The name of the provider<VERSION>: The specific version of the provider you're deploying<OS>: The target operating system for this provider build<ARCH>: The target CPU architecture for this provider build<PATH_TO_FILE>: The path to the file on your local machine that you send to Artifactory
For example:
curl -uadmin:<TOKEN> -XPUT "https://company.jfrog.io/artifactory/terraform-local/hashicorp/null/3.1.0/terraform-provider-null_3.1.0_linux_amd64.zip" -T test-provider-linux-amd64.zip -
Deploy the GPG signature
.sigfile:curl -u<USERNAME>:<TOKEN> -XPUT "<JFROG_PLATFORM_URL>/artifactory/<REPOSITORY_KEY>/<NAMESPACE>/<PROVIDER_NAME>/<VERSION>/terraform-provider-<PROVIDER_NAME>_<VERSION>_SHA256SUMS.sig" -T <PATH_TO_FILE>Where:
<JFROG_PLATFORM_URL>: The URL of your JFrog Platform<USERNAME>: Your JFrog Platform username<TOKEN>: Your JFrog Platform password<REPOSITORY_KEY>: The name of your repository<NAMESPACE>: The owner or organization for this provider<PROVIDER_NAME>: The name of the provider<VERSION>: The specific version of the provider you're deploying<PATH_TO_FILE>: The path to the file on your local machine that you send to Artifactory
For example:
curl -uadmin:<TOKEN> -XPUT "https://company.jfrog.io/artifactory/terraform-local/hashicorp/null/3.1.0/terraform-provider-null_3.1.0_SHA256SUMS.sig" -T terraform-provider-null_3.1.0_SHA256SUMS.sig -
Deploy the
SHA256SUMSfile:curl -u<USERNAME>:<TOKEN> -XPUT "<JFROG_PLATFORM_URL>/artifactory/<REPOSITORY_KEY>/<NAMESPACE>/<PROVIDER_NAME>/<VERSION>/terraform-provider-<PROVIDER_NAME>_<VERSION>_SHA256SUMS" -T <PATH_TO_FILE>Where:
<JFROG_PLATFORM_URL>: The URL of your JFrog Platform<USERNAME>: Your JFrog Platform username<TOKEN>: Your JFrog Platform password<REPOSITORY_KEY>: The name of your repository<NAMESPACE>: The owner or organization for this provider<PROVIDER_NAME>: The name of the provider<VERSION>: The specific version of the provider you're deploying<PATH_TO_FILE>: The path to the file on your local machine that you send to Artifactory
For example:
curl -uadmin:<TOKEN> -XPUT "https://company.jfrog.io/artifactory/terraform-local/hashicorp/null/3.1.0/terraform-provider-null_3.1.0_SHA256SUMS" -T terraform-provider-null_3.1.0_SHA256SUMS
Deploy with the Network Mirror Protocol
Publish the provider archive for a specific operating system and architecture to an Artifactory repository.
To deploy a provider with the Network Mirror protocol:
-
Deploy the provider archive. The required parameters are namespace, provider-name (system), version, operating-system (os) and architecture (arch):
curl -u<USERNAME>:<TOKEN> -XPUT "<JFROG_PLATFORM_URL>/artifactory/<REPOSITORY_KEY>/<NAMESPACE>/<PROVIDER_NAME>/<VERSION>/terraform-provider-<PROVIDER_NAME>_<VERSION>_<OS>_<ARCH>.zip" -T <PATH_TO_FILE>Where:
<JFROG_PLATFORM_URL>: The URL of your JFrog Platform<USERNAME>: Your JFrog Platform username<TOKEN>: Your JFrog Platform password<REPOSITORY_KEY>: The name of your repository<NAMESPACE>: The owner or organization for this provider<PROVIDER_NAME>: The name of the provider<VERSION>: The specific version of the provider you're deploying<OS>: The target operating system for this provider build<ARCH>: The target CPU architecture for this provider build<PATH_TO_FILE>: The path to the file on your local machine that you send to Artifactory
For example:
curl -uadmin:<TOKEN> -XPUT "https://company.jfrog.io/artifactory/terraform-local/hashicorp/null/3.1.0/terraform-provider-null_3.1.0_linux_amd64.zip" -T test-provider-linux-amd64.zip
Deploy Terraform Resources via the UI
You can deploy a Terraform module or provider from the Artifactory UI.
To deploy a Terraform resource via Artifactory UI:
-
In the Platform module, go to Artifactory > Artifacts.
-
Select the artifact you want to deploy, then click Deploy (Upload). Deploy options are displayed.

-
Verify the deploy options.
-
Click Deploy.
The resource is deployed.
Resolve Terraform Resources
You can resolve Terraform modules or providers from Artifactory.
Resolve Terraform Modules
Resolve a Terraform module from Artifactory by setting the module source in your configuration.
To resolve a Terraform module from an Artifactory repository:
-
Add the following information to your HCL file
(.tf):module "module-name" { source = "<JFROG_HOSTNAME>/<REPOSITORY_KEY>__<NAMESPACE>/<MODULE_NAME>/<PROVIDER>" }Where:
<JFROG_HOSTNAME>: Your JFrog Platform hostname. Don't includehttps://.<MODULE_NAME>: The name of the module.<REPOSITORY_KEY>: The name of your repository.<NAMESPACE>: The owner or organization for this module.<PROVIDER>: The name of the provider.
For example:
module "vpc" { source = "company.jfrog.io/terraform-local__terraform-aws-modules/vpc/aws" }
Resolve Terraform Providers
Resolve a Terraform provider from Artifactory by setting the provider source in your configuration.
To resolve a Terraform provider from an Artifactory repository:
-
Add the following information to your HCL
.tffile. Use the block for your protocol.terraform { required_providers { provider-name = { source = "<JFROG_HOSTNAME>/<REPOSITORY_KEY>-rt-ns-<NAMESPACE>/<PROVIDER>" version = "<VERSION>" } } }Where:
-
<JFROG_HOSTNAME>: Your JFrog Platform hostname. Don't includehttps://. -
<REPOSITORY_KEY>: The name of your repository. Include-rt-ns-after the repository name to differentiate the repository name from the namespace.
<NAMESPACE>: The owner or organization for the provider.<PROVIDER>: The name of the provider.<VERSION>: Version number.
For example:
terraform { required_providers { docker = { source = "company.jfrog.io/terraform-local-rt-ns-kreuzwerker/docker" version = "1.0.0" } } }terraform { required_providers { provider-name = { source = "<NAMESPACE>/<PROVIDER>" } } }Where:
<NAMESPACE>: The owner or organization for the provider<PROVIDER>: The name of the provider
For example:
terraform { required_providers { docker = { source = "kreuzwerker/docker" } } } -
Terraform Repository Configuration and Publishing
The following additional information is available with Terraform repositories:
- Terraform Registry and Backend
- Configure a Remote Terraform Repository
- Generate an Access Token Manually for Terraform
- Set Environment Variables for Terraform
- Publish Terraform Modules Using the JFrog CLI
- Calculate Terraform Repository Metadata
- Replicate Terraform Backend Repositories
Terraform Registry and Backend
Artifactory supports Terraform in two repository roles. A Terraform/OpenTofu repository hosts Terraform modules and Terraform providers. A Terraform Backend repository, available from Artifactory 7.38.4, stores remote state and works alongside the registry. For more information, see Terraform Backends.
A module configuration can include a backend that defines how Terraform runs operations and where it stores state. State maps the resources in your configuration to infrastructure. Some backends support named workspaces, so one configuration can have several states without a separate backend or new credentials.
Artifactory can serve providers through the following protocols.
| Protocol | How Terraform uses it | Trust |
|---|---|---|
| Provider Registry Protocol | Terraform discovers the registry from your hostname. A private registry requires terraform login once. | The registry signs providers with GPG. |
| Network Mirror | Terraform uses a network_mirror block in the CLI configuration. | Terraform verifies file checksums. Signature trust stays with the original source. |
Configure a Remote Terraform Repository
Remote repositories enable you to proxy and cache your remote Terraform modules and providers packages. Terraform remote repositories have additional package type-specific configuration options.
To set up a remote Terraform repository:
-
In the Administration module, go to Repositories.
-
Click Create a Repository.
-
Select Remote. The Select Package Type window opens.
-
Select Terraform / OpenTofu. The New Remote Repository page opens.
-
Follow the instructions in the following table for specific Terraform settings.
Field Description URL The URL of the Git repository that stores modules. The default is
https://github.com/.When using smart remote repositories, set the URL to
<JFROG_PLATFORM_URL>/artifactory/<REPO_KEY>.Password / Access Token From Artifactory version 7.118.2 and later, if you're using a proxy GitLab or Terraform Cloud registry with this remote repository, you must enter your bearer token. - For a proxy GitLab registry, create the bearer token in GitLab by selecting Access Token > Add new token in your GitLab registry.
- For a proxy Terraform Cloud registry, create the bearer token by selecting API Tokens > Generate an organization token in your Terraform Cloud registry.
Enable Token Authentication You must enable this setting if you're using a proxy GitLab or Terraform Cloud registry with this remote repository. Include Patterns/Exclude Patterns Specify Ant-like patterns to filter repositories when resolving the artifact locations. Repositories are selected using the include patterns (default: all). Any repository matching an exclude pattern is filtered out (default: none). Exclude patterns take priority over include patterns.
The following examples show patterns for different provider types.
HashiCorp Provider-
**/.terraform/providers/hashicorp/<PROVIDER_NAME>/**
For example: **/.terraform/providers/hashicorp/kubernetes/** -
**/terraform-provider-<PROVIDER_NAME>/**
For example:**/terraform-provider-kubernetes/**
-
**/external/github.com/<DEVELOPER_NAME>/terraform-provider-<PROVIDER_NAME>/**
For example:**/external/github.com/infobloxopen/terraform-provider-infoblox/** -
**/external/github.com/infobloxopen/terraform-provider-infoblox/**
For example: **/.terraform/providers/infobloxopen/infoblox/**
Git providers GitHub is the recommended selection when pointing the repository at the official HashiCorp Terraform Registry. You can also select BitBucket, Stash / Private BitBucket, Stash / Private BitBucket (prior to 5.1.0), Artifactory, or Custom. Registry URL The base URL of the registry API. - When using smart remote repositories, set the URL to
<JFROG_PLATFORM_URL>/artifactory/api/terraform/<REPO_KEY>. - When using OpenTofu, set the URL to
https://registry.opentofu.org/. - When using a GitLab proxy registry, set to
https://gitlab.com. - When using a Terraform Cloud proxy registry, set to
https://app.terraform.io.
Providers URL The base URL of the provider's storage API. - When using smart remote repositories, set the URL to
<JFROG_PLATFORM_URL>/artifactory/api/terraform/<REPO_KEY>/providers. - When using OpenTofu, set the URL to
https://github.com/.
-
If you're using a proxy GitLab or Terraform Cloud registry with this remote repository:
-
Click the Advanced tab.
-
In External Dependency Rewrite, select Enable Dependency Rewrite.
This allows you to define the trusted resources that the client can resolve from.
-
In Patterns Allow List, add all the URLs that you want to download from.
- To resolve all Terraform modules in Terraform Cloud, add:
https://*terraform*.io/** - To resolve all Terraform modules in Gitlab, add:
https://gitlab.com/**
- To resolve all Terraform modules in Terraform Cloud, add:
-
-
When you're finished configuring the remote repository, click Create Remote Repository.
-
(Optional) If you need to disable source URL override, set this system property:
artifactory.terraform.override.modules.source.hostname=falseNote
From version 7.39.4, source URL override is the default setting. It is recommended to keep this feature enabled.
Generate an Access Token Manually for Terraform
The token enables you to resolve Terraform modules and provider packages from the Terraform Registry, and to use a Terraform Backend repository for remote state and locking. You can generate the token manually or automatically.
To generate an access token manually for the Terraform or OpenTofu CLI:
-
Generate an identity token that you can use to connect Artifactory to the Terraform CLI. For more information, see Generate Identity Token.
-
Create a file named
credentials.tfrc.jsonin your Terraform directory,~/.terraform.d/credentials.tfrc.json. -
Update the token you generated in the
credentials.tfrc.jsonfile.#cat ~/.terraform.d/credentials.tfrc.json { "credentials": { "<JFROG_HOSTNAME>": { "token": "<TOKEN>" } } }Where:
<JFROG_HOSTNAME>: Your JFrog Platform hostname. Don't includehttps://.<TOKEN>: The identity token you generated.
For example:
#cat ~/.terraform.d/credentials.tfrc.json { "credentials": { "company.jfrog.io": { "token": "<TOKEN>" } } }
Note
If you added the access token to
credentials.tfrc.json, you can skipterraform login.
Set Environment Variables for Terraform
For CI/CD pipelines and automated deployments, using environment variables is often more secure and convenient than storing credentials in configuration files. Terraform automatically detects and uses host-specific environment variables. The environment variables approach offers the following benefits:
- Security: You keep credentials out of version control.
- Simplicity: You can skip creating and managing configuration files.
- Flexibility: You can switch between different environments.
- CI/CD friendly: Seamless integration with automated deployment pipelines.
If you don't set environment variables, Terraform falls back to the CLI configuration file, ~/.terraformrc or %APPDATA%\terraform.rc, and your .tf files.
For more information, see Terraform CLI configuration.
To use environment variables, complete the following tasks:
Set Environment Variables
Set the JFrog URL and access token in the shell before you run Terraform. Terraform uses the following naming pattern for environment variables:
TF_VAR_<VARIABLE_NAME>for Terraform variables- Host-specific variables like
JFROG_URLandJFROG_ACCESS_TOKENfor provider configuration
To set the JFrog URL and access token:
-
Set the JFrog URL:
export JFROG_URL=https://<JFROG_HOSTNAME>Where:
<JFROG_HOSTNAME>: Your JFrog Platform hostname. Don't includehttps://.
For example:
export JFROG_URL=https://company.jfrog.io -
Set the access token:
export JFROG_ACCESS_TOKEN=<TOKEN>
Add Credentials to a CI/CD Pipeline
Add the JFrog URL and access token to the pipeline environment instead of writing them in a configuration file.
To add the JFrog URL and access token to a CI/CD pipeline:
-
Add the following commands to the job. This example uses GitHub Actions:
echo "JFROG_URL=https://<JFROG_HOSTNAME>" >> $GITHUB_ENV echo "JFROG_ACCESS_TOKEN=<TOKEN>" >> $GITHUB_ENVWhere:
<JFROG_HOSTNAME>: Your JFrog Platform hostname. Don't includehttps://.<TOKEN>: The identity token stored in the pipeline secret.
For example:
- name: Configure JFrog credentials run: | echo "JFROG_URL=https://company.jfrog.io" >> $GITHUB_ENV echo "JFROG_ACCESS_TOKEN=${{ secrets.JFROG_ACCESS_TOKEN }}" >> $GITHUB_ENV
Publish Terraform Modules Using the JFrog CLI
JFrog CLI provides full support for packing Terraform modules and deploying them to JFrog Artifactory.
Working with Terraform modules requires JFrog CLI version 2.12.0 and above.
Set the Deployment Repository
Set the deployment repository before you publish Terraform modules to Artifactory with JFrog CLI.
To set the deployment repository:
-
Change to the root of the Terraform project.
-
Set the repository for this project:
jf terraform-configFor example:
jf tfc -
(Optional) Set the repository for all Terraform projects on this machine:
jf tfc --global
The following table lists the command arguments and flags.
| Argument or flag | Description |
|---|---|
| Command-name | terraform-config |
| Abbreviation | tfc |
--global | The default is false. Set this flag to true to apply the configuration to all projects on the machine. A project configuration overrides the global configuration. |
--server-id-deploy | Optional. Artifactory server ID for deployment. Configure the server with the jf c add command. |
--repo-deploy | Optional. The repository where you deploy artifacts. |
Publish Terraform Modules to Artifactory
The jf terraform publish command packs and deploys the Terraform modules to the designated Terraform repository in Artifactory.
Prerequisite: Before you run jf terraform publish on a project for the first time, configure the project with jf terraform-config. For more information, see Set the Deployment Repository.
To publish Terraform modules to Artifactory:
-
Change to the directory that contains the Terraform modules. Modules in that directory share the namespace, provider, and tag.
-
Pack and publish the modules:
jf terraform publish --namespace=<NAMESPACE> --provider=<PROVIDER> --tag=<TAG>Where:
<NAMESPACE>: The namespace of the Terraform project whose modules you publish<PROVIDER>: The provider of the Terraform project whose modules you publish<TAG>: The tag of the modules you publish
For example:
jf tf p --namespace=tera --provider=aws --tag=v0.1.2 --exclusions="*test*;*ignore*"This command packs and deploys all the modules under the current working directory. The modules are published using this layout:
tera/<MODULE_NAME>/aws/v0.1.2.zip, and the command excludes modules and files that includetestandignore. For more information, see Adding Exclusions Using Patterns.
Rules and Guidelines for Packing Terraform Modules
- JFrog CLI scans the file system from the current working directory.
- JFrog CLI treats a directory that contains a
.tffile as a Terraform module. It packs the directory contents, including submodule directories, in one zip file and deploys that file to Artifactory. - JFrog CLI doesn't scan inside a module directory after it packs the module. It doesn't pack submodules as separate modules.
Adding Exclusions Using Patterns
You can set patterns to exclude the following:
- JFrog CLI doesn't scan a directory that matches the pattern.
- JFrog CLI doesn't pack files that match the pattern.
The following table lists the command arguments and flags.
| Argument or flag | Description |
|---|---|
| Command-name | jf terraform publish |
| Abbreviation | tf p |
| --exclusions | Optional. A semicolon-separated list of exclude patterns. You can use wildcards. |
| Command arguments | |
| --namespace | The namespace of the Terraform project whose modules you publish. |
| --provider | The provider of the Terraform project whose modules you publish. |
| --tag | The tag of the modules you publish. |
For more information, see the Terraform project example.
Calculate Terraform Repository Metadata
You can trigger an asynchronous re-indexing of a local Terraform repository either through the UI or using the REST API.
The recalculation runs only for that local repository.
Prerequisite: You need Manage permission on the repository.
To recalculate the index for a local Terraform repository:
- In Artifacts, select your Terraform repository.
- Right-click the repository.
- Click Recalculate Index.
For more information, see Calculate Terraform Index API.
Replicate Terraform Backend Repositories
Artifactory supports replication of Terraform Backend repositories from version 7.77.x. To replicate Terraform Backend repositories, set encryptStates to false in the Local Repository Configuration JSON.
Terraform Limitations in Artifactory
The following are the limitations of Terraform in Artifactory:
-
Artifactory doesn't support Federated Repositories for Terraform Backend repositories.
This limitation prevents inconsistencies in the system state, which could lead to unexpected behavior or errors.
-
Artifactory doesn't support remote and virtual repositories for Terraform Backend repositories.
Related Topics
Updated 14 days ago

