ARTIFACTORY: How to manually configure Terrafarm CLI with Artifactory, when you don’t have a Browser installed on your Unix machine to Authorize Terraform CLI with Artifactory.

Bandi Harish Goud
2022-05-22 11:30

Fact:

From Artifactory version 7.38.4 and above 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.

Prerequisites: 

Artifactory supports Terraform CLI version 1.0.0 and above. So install Terraform CLI.

Problem statement:

While configuring Terraform CLI with Artifactory the request will be routed to JFrog platform browser page to Authorise Terraform CLI to access Artifactory. The screenshot is as below:

User-added image

Steps to Manually configure Terraform CLI with Artifactory

  1. So install Terraform CLI from Terraform CLI
  2. Create dedicated Module and Provider registries.
  3. Create a Terraform Backend Repository in Artifactory.
  4. Generate an Access Token between Artifactory and the Terraform CLI
Navigate to JFrog_Platform_UI | Admin | User Management | Generate Token |
 
User-added image

 

5. Create a “credentials.tfrc.json” under “~/.terraform.d/” path. The file path should be as below:
~/.terraform.d/credentials.tfrc.json
6. Update your Access Token generated in the previous step in the “credentials.tfrc.json” file and initialize via the command “terrafram init
Example format below:#cat ~/.terraform.d/credentials.tfrc.json
{
  "credentials": {
"servername.jfrog.io": {"token": "ACCESS TOKEN" }
  }
}

Note: If you are using Access Token in “credentials.tfrc.json” you don’t have to login again (terraform login servername.jfrog.io [not required] )