I originally intended to publish an article that explains Terraform variables. However, I ultimately opted to begin with a tutorial on how to use Artifactory for managing Terraform modules. I have written blog posts about Artifactory and Chapter 4: Creating a Module. Today, I will integrate them together.
When collaborating with coworkers, we may need to share our modules with them. An artifact manager system should be used to manage Terraform modules effectively in such situations. We can use https://registry.terraform.io or a private registry, such as Artifactory.
First, we need to create a Terraform Repo in Artifactory:
Create an access token and configure your JF command credentials.
Use the following command to configure JF credentials: type in the JF server and token that you generated.
# You can define "jf-server-key/id" by yourself. In this example, it is defined as "tf".
jf config add ${jf-server-key/id}
<aside> 💡 Notice: To download the JF CLI, please refer to https://jfrog.com/help/r/jfrog-cli/general?tocId=GP5vAWerbd8vOwR_IDiu_w
</aside>
To configure Terraform publish, use the jf tfc
command in your module workspace. The following is the output:
~/terraform-ali/tf_modules/ [chapter-4-2] jf tfc
Configuration file already exists at /Users/swill/Desktop/terraform-ali/tf_modules/.jfrog/projects/terraform.yaml. Override it? (y/n) [n]? y
Deploy project artifacts to Artifactory? (y/n) [y]? y ➊
Set Artifactory server ID [tf]: tf ➋
Set repository for artifacts deployment (press Tab for options): swill-tf ➌
14:43:59 [🔵Info] terraform build config successfully created.
➊:Type "y".
➋: The server ID is the one that you configured. # You can define "jf-server-key/id" by yourself. In this example, it is defined as "tf". jf config add ${jf-server-key/id}
➌The repository key is the key you created in First, we need to create a Terraform Repo in Artifactory:
Use the following command to publish it to Jfrog Artifactory.
jf tf p --namespace=${namespace} --provider=alicloud --tag=${version}
In this example, the following command is completed:
jf tf p --namespace=new-space --provider=alicloud --tag=1.0.2
If everything is okay, you can view the output in the following section:
You can check this on the Artifactory server at the same time:
Click the Set Me Up
button in the top right corner.
To generate a token, please enter your password first:
After that, you will receive the following information:
To log in with a registry in your terminal, type the name of your specific registry and press enter when prompted with "yes.”
Please update your module source and define its version.
module "my_module" {
# source = "${jfrog_server}/${repository_id}__${NAMESPACE}/${MODULE-NAME}/${PROVIDER}"
source = "${jfrog_server}/swill-tf__new-space/tf_modules/alicloud"
version = "1.0.2"
vpc_main_name = "main"
vpc_main_cidr_block = "192.168.0.0/16"
vswitch_master-1_name = "master-1"
vswitch_master-1_cidr_block = "192.168.0.0/24"
vswitch_master-1_zone = "cn-beijing-a"
}
<aside> 👇🏾 ps: Generated by AI.
</aside>