From Jamf Console to Code, Part 3: Building Your First Jamf Pro Terraform Project
You do not need a large module or a CI pipeline to get started. A provider, a small resource, and a safe sandbox are enough to learn the basic Terraform workflow.
Create a small, isolated project, connect it to a Jamf Pro sandbox, and inspect your first plan.
In the last post, we translated Terraform’s main concepts into Jamf-admin language. Now let’s put a few of them together. We’ll create a tiny Terraform project that defines one Jamf Pro category, initialize Terraform, validate the configuration, and review a plan.
This is a learning exercise, not a production deployment. Use a Jamf Pro sandbox or a dedicated test tenant, and do not apply changes to a production environment.
Before you begin
You will need:
- A non-production Jamf Pro tenant and permission to create a category
- A Jamf Platform API integration with only the capabilities needed for the test
- Terraform installed at a version supported by your provider
- The official Jamf Pro Platform provider documentation
Provider schemas and versions change. Check the provider documentation for the version you select, and use the version approved for your environment. The example below follows the provider configuration pattern used in my current project; it is a starting point, not a promise that every future version uses an identical schema.
Make a small project
Create a new directory for the exercise and add four files:
1
2
3
4
5
jamf-terraform-lab/
├── versions.tf
├── provider.tf
├── variables.tf
└── main.tf
The first file declares the Terraform and provider versions. Pinning the provider makes installs predictable and makes upgrades an intentional change.
1
2
3
4
5
6
7
8
9
10
11
# versions.tf
terraform {
required_version = ">= 1.15.8"
required_providers {
jamfplatform = {
source = "jamf/jamfplatform"
version = "1.9.0"
}
}
}
The version numbers shown here match the project this series is based on. Before using them, verify the current versions and compatibility in the Terraform Registry and with your own Terraform installation.
Next, declare inputs for the Jamf Platform API connection:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# variables.tf
variable "jamfplatform_base_url" {
description = "Jamf Platform API base URL"
type = string
}
variable "jamfplatform_environment_id" {
description = "Jamf Platform environment ID"
type = string
}
variable "jamfplatform_client_id" {
description = "Jamf Platform API client ID"
type = string
}
variable "jamfplatform_client_secret" {
description = "Jamf Platform API client secret"
type = string
sensitive = true
}
Then configure the provider to use those values:
1
2
3
4
5
6
7
# provider.tf
provider "jamfplatform" {
base_url = var.jamfplatform_base_url
environment_id = var.jamfplatform_environment_id
client_id = var.jamfplatform_client_id
client_secret = var.jamfplatform_client_secret
}
Do not put real credentials in these files. For a local test, Terraform can read input variables from environment variables prefixed with TF_VAR_. For example, TF_VAR_jamfplatform_client_secret supplies the jamfplatform_client_secret variable. Use your shell’s secure secret-handling method and avoid saving secrets in shell history or committed files. We will go deeper on credentials and state in the next post.
Define one resource
For the first resource, use a category. It is straightforward to recognize in Jamf Pro and does not require us to solve policy scope or package dependencies yet.
1
2
3
4
5
# main.tf
resource "jamfplatform_pro_category" "iac_lab" {
name = "IaC Series Lab"
priority = 9
}
Here, jamfplatform_pro_category is the resource type. iac_lab is Terraform’s local name for this resource. The Jamf display name is IaC Series Lab. Confirm the resource type and arguments against the documentation for your selected provider version.
Initialize, validate, and plan
From the project directory, initialize Terraform:
1
terraform init
Terraform downloads the provider and creates a local .terraform directory and lock file. The lock file records the selected provider version and checksums; commit it to version control so other users get a consistent provider selection.
Check that the configuration is structurally valid:
1
terraform validate
Validation does not prove that the API credentials work or that the change is operationally appropriate. Next, ask Terraform to create a plan:
1
terraform plan
Terraform will need to connect to the configured Jamf environment to plan managed resources. Check the tenant and environment ID before proceeding. The plan should propose creating the category. Read the full output, especially the resource address and any create, update, replace, or delete actions.
For this exercise, stop after reviewing the plan. Do not apply it unless you are in your dedicated test tenant and understand the result. A normal terraform plan does not create the Jamf category.
What Terraform created locally
Terraform will create local working files, including .terraform/ and a state file after it records managed objects. These are not Jamf objects, but they are important to Terraform. Keep .terraform/, state files, saved plans, and variable files containing secrets out of Git. Add suitable ignore rules before you commit the project.
This first project uses local state only to make the workflow visible. Local state is not a good collaboration model, and a laptop is not a reliable place for shared production state. In the next post, we’ll look at state backends, credentials, access control, and how to keep this project safe as it grows.
Try it
In your sandbox, change the category name in the configuration and run terraform plan again. Notice how Terraform describes the proposed change. Then change it back and plan once more. Do not apply either plan; the point is to get comfortable reading the preview before making changes.