ARTIFACTORY: How to configure Terraform repositories in Artifactory

AuthorFullName__c
Tatarao Vana, Logeshwaran R
articleNumber
000005478
FirstPublishedDate
2022-11-30T08:56:48Z
lastModifiedDate
2025-05-15

ARTIFACTORY: How to configure Terraform repositories in Artifactory

How to configure Terraform repositories in Artifactory

JFrog provides a fully-fledged Terraform repository solution giving you full control of your deployment and resolution process of Terraform Modules, Providers, and Backend packages from Artifactory 7.38.4 version onwards. 

In this knowledge base article, we will discuss the following topics. 

  1. Deploy/Resolve Terraform module artifact to Artifactory
  2. Deploy/Resolve Terraform provider artifact to Artifactory
  3. Troubleshooting the Terraform issues
Deploy/Resolve Terraform module artifact to Artifactory:

We can follow the below steps to deploy modules to Artifactory:
1. Create a new Terraform module by adding your contents to the tf file. Below is a sample of a new directory followed by

a “terraform init” command. 
cat main.tf
terraform {
 required_version = ">= 0.12.26"
}
output "hello_world" {
 value = "Hello, World!"
}


2. Navigate to the newly created directory and perform the following command to pack its contents into a zip file and name it according to the module version: 
zip -r 1.0.0.zip .  
adding: main.tf (deflated 9%)

3. Deploy the module using the cURL command found on the “Set Me Up” page as seen below.

Please note that my virtual repository name is test-terraform which consists of the local repository test-terraform-modules-local.

curl -utestuser:testpassword -XPUT "https://jpd.local/artifactory/test-terraform/myns/mymodule/myprovider/1.0.0.zip" -T 1.0.0.zip 
{
  "repo" : "test-terraform-modules-local",
  "path" : "/myns/mymodule/myprovider/1.0.0.zip",
  "created" : "2022-09-29T07:06:57.015Z",
  "createdBy" : "testuser",
  "downloadUri" : "https://jpd.local/artifactory/test-terraform-modules-local/myns/mymodule/myprovider/1.0.0.zip",
  "mimeType" : "application/zip",
  "size" : "253",
  "checksums" : {
    "sha1" : "a1f8d4026ddad3026278b072b3d476e4b50bf5de",
    "md5" : "5f7fb91cd0849148a15ebffe48958dcf",
    "sha256" : "a2bc2961618ab39dc18a559e7dccf58f2b83ebc70446dcdd5cc7dcc0f9f2f9a5"
  },
  "originalChecksums" : {
    "sha256" : "a2bc2961618ab39dc18a559e7dccf58f2b83ebc70446dcdd5cc7dcc0f9f2f9a5"
  },
  "uri" : "https://jpd.local/artifactory/test-terraform-modules-local/myns/mymodule/myprovider/1.0.0.zip"
}


4. In other Terraform projects (client machine for example), consume the published module using the following snippet: 

cat main.tf 
module "mymodule" {
    source  = "jpd.local/test-terraform__myns/mymodule/myprovider"
}


5. Execute Terraform login command. 
terraform login jfrog.local

6. Execute the Terraform init command to resolve it. 
terraform init
Initializing modules...
Downloading jpd.local/test-terraform__myns/mymodule/myprovider 1.0.0 for mymodule...
- mymodule in .terraform/modules/mymodule
Initializing the backend...
Initializing provider plugins...
Terraform has been successfully initialized!
 

Deploy/Resolve Terraform provider artifact to Artifactory:

While creating the Terraform provider name it is as terraform-provider-<name>. Otherwise, we will get the following error message while performing terraform init.

Error: Failed to install provider
 
Error while installing testns/test v1.0.0: provider binary not found: could not find executable file starting with terraform-provider-test

Later, zip the created terraform provider and deploy it to the Artifactory using the curl command from the Set Me Up page.

For example:

curl -u<username> -XPUT "https://<Artifactory_URL>/artifactory/logesh-terraform-provider-local/testns/test/1.0.0/terraform-provider-test_1.0.0_darwin_amd64.zip" -T terraform-provider-example.zip


While uploading the provider, we need to make sure that we are providing the correct platform details where we are going to install the provider. Otherwise, we encounter the following error message while installing the provider.
Error: Incompatible provider version 
Provider registry.terraform.io/testns/test v1.0.0 does not have a package available for your current platform, darwin_arm64.
 
Provider releases are separate from Terraform CLI releases, so not all providers are available for all platforms. Other versions of this provider may have different platforms supported.

In the above context, we deployed a Terraform provider artifact for the platform amd64. Later, we tried to install the same artifact in the arm64 machine which is a different architecture and faced the below error message. Later, we deployed the Terraform provider artifact for arm64 platform and was able to install it.

After successfully deploying the provider file to the local repository, we need to create a main.tf file using the template from the Set Me Up page and then we can perform the terraform init to install the provider.

Sample main.tf file configuration
terraform {
    required_providers {
        template = {
            version = "1.0.0"
            source = "testns/test"
        }
    }
}

Terraform client output


User-added image
 

Troubleshooting the Terraform issues

Kindly enable the debugger logger in the 
$JFROG_HOME/artifactory/var/etc/artifactory/logback.xml
 file and does not require a restart for log changes to take effect:

<appender name="terraform" class="ch.qos.logback.core.rolling.RollingFileAppender">
  <File>${log.dir}/artifactory-terraform.log</File>
  <rollingPolicy class="org.jfrog.common.logging.logback.rolling.FixedWindowWithDateRollingPolicy">
    <FileNamePattern>${log.dir.archived}/artifactory-terraform.%i.log.gz</FileNamePattern>
    <maxIndex>10</maxIndex>
  </rollingPolicy>
  <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
    <MaxFileSize>25MB</MaxFileSize>
  </triggeringPolicy>
  <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
    <layout class="org.jfrog.common.logging.logback.layout.BackTracePatternLayout">
      <pattern>%date{yyyy-MM-dd'T'HH:mm:ss.SSS, UTC}Z [jfrt ] [%-5p] [%-16X{uber-trace-id}] [%-30.30(%c{3}:%L)] [%-20.20thread] - %m%n</pattern>
    </layout>
  </encoder>
</appender>
 
<logger name="org.artifactory.addon.terraform" additivity="false">
<level value="debug"/>
<appender-ref ref="terraform"/>
</logger>
 
<logger name="org.jfrog.repomd.terraform" additivity="false">
<level value="debug"/>
<appender-ref ref="terraform"/>
</logger>


You should temporarily enable this logger for debugging purposes, then remove it! 

On the client side, enable Terraform client debug using the command: 

export TF_LOG=TRACE

By following the above steps, we can effectively deploy, and resolve Terraform modules and providers using JFrog Artifactory in your infrastructure automation workflows.