Before you start working on this project, you'll need to install several tools to ensure your development environment is properly set up.
You will need an Integrated Development Environment (IDE) to write and manage your code efficiently. We recommend Visual Studio Code (VSCode) because of its flexibility and a wide range of available extensions for Terraform and Git integration.
- Terraform: Provides syntax highlighting, linting, and IntelliSense for Terraform files.
- YAML: Useful for working with GitHub Actions workflows.
- GitLens: Enhances Git capabilities within VSCode, showing Git blame information, commit history, and more.
- Prettier - Code Formatter: Ensures consistent formatting of your code.
Git is essential for version control and managing your project’s source code. Install it from the official website based on your operating system:
Once Git is installed, you can verify the installation by running the following command in your terminal or command prompt:
git --versionAfter installing Git, you need to configure your user information. This information is used to track who made the changes in the Git commit history.
Run the following commands to set your Git username and email globally (this can be specific to your GitHub account or organization).
git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"To verify that the configuration was successful, run:
git config --global --listTerraform is required to manage the infrastructure resources in this project. You can download it from the official Terraform website:
After installing Terraform, verify the installation by running the following command:
terraform --version- Create a New Repository: Start by forking or cloning this repository into your GitHub account. Ensure that you include all branches when you fork.
Optional: Clone and Push to Your New Repository: If cloning then take a local copy of this repo and then push it to your newly created repository:
git clone https://github.com/deploymenttheory/terraform-demo-jamfpro.git
cd terraform-demo-jamfpro
git remote set-url origin https://github.com/your-username/your-new-repo.git
git push -u origin mainReplace your-username and your-new-repo with your GitHub username and the name of your new repository.
- Configure Terraform Cloud Workspaces:
To manage your Jamf Pro infrastructure across different environments, you'll need to set up a terraform cloud organization, project and 3 workspaces. You will require a seperate workspace for each jamf pro envionrment you want to manage with terraform.
Setup an account within terraform cloud if you havent already -
And create a new terraform cloud organization. Organizations are privately shared spaces for teams to collaborate on infrastructure.

-
Create Terraform Cloud Project: Create a new project in Terraform Cloud for your Jamf Pro infrastructure.

-
Create Terraform Cloud Workspaces:
Assigned to your project three workspaces in Terraform Cloud with the following names:
terraform-jamfpro-sandboxterraform-jamfpro-stagingterraform-jamfpro-production
Use
API-driven workflowfor each workspace.
Each workspace holds a unique state for the correlating jamf pro environment.

-
Tag Workspaces: Tag each of these workspaces with the "jamf_pro" tag. This allows you to easily identify and group these workspaces and it will allow us to apply terraform variable sets (collections of variables true across multiple jamf pro environments)
-
Set Up Variable Set for Common Variables: Create a variable set for variables that are common across all environments, set the following variables as
Terraform variable:a. In Terraform Cloud, go to your organization settings. b. Click on "Variable sets" and then "Create variable set". c. Name it something like "Jamf Pro Common Variables". d. Add the following variables:
enable_client_sdk_logs: Set to "false"client_sdk_log_export_path: Set to "" - emptyjamfpro_jamf_load_balancer_lock: Set to "true"jamfpro_token_refresh_buffer_period_seconds: Set to "100"jamfpro_mandatory_request_delay_milliseconds: Set to "300"
f. Apply this variable set to all three Jamf Pro workspaces.
-
Configure Workspace-Specific Variables: For each workspace, set the following variables as
Terraform variable:a. Go to the workspace settings in Terraform Cloud. b. Navigate to the "Variables" section. c. Add the following variables:
jamfpro_instance_fqdn: The FQDN of your Jamf Pro instance for this environment.jamfpro_client_id: Your Jamf Pro client ID (for OAuth2)jamfpro_client_secret: Your Jamf Pro client secret (for OAuth2)jamfpro_basic_auth_username: Your Jamf Pro username (for basic auth)jamfpro_basic_auth_password: Your Jamf Pro password (for basic auth)
d. Mark sensitive variables (like passwords and secrets) as sensitive.
-
Access Controls: Set up appropriate access controls for each workspace:
a. Go to the "Team Access" section in each workspace's settings. b. Assign the appropriate permissions to team members based on their roles and the environment. c. Consider restricting access to production workspaces to a smaller group of trusted team members.
-
Generate Terraform Cloud API token: This token will be used by github actions to communicate with terraform cloud.
Within TFC go to account settings -> tokens -> generate an api token
Give this token a lifespan you are happy with and save it for later in use with github actions
- Configure Github Secrets: Set up the following secrets in your GitHub repository settings:
TF_API_TOKEN: Your Terraform Cloud API token for communication between GHA and the Terraform Cloud backend.
Optional:
These webhook URLs are used in the Send Notification workflow (send-notification.yml) to send terraform deployment status updates to your team. The workflow determines which service to use based on the notification_channel input.
MSTEAMS_WEBHOOK_URL: Your Microsoft Teams webhook URL for sending notifications.SLACK_WEBHOOK_URL: Your Slack webhook URL for sending notifications.
The presenance of one of these environment variables will run the notification job for MS Teams or Slack utilising the defined webhook URL. If both values are set, MS Teams takes presedence.
To set up the notification webhooks on the messaging tool side, perform one of the following:
a. For Microsoft Teams:
- In your Teams channel, click the '...' next to the channel name and select
Connectors. - Find
Incoming Webhookand clickConfigure. - Provide a name for your webhook and optionally upload an image.
- Click 'Create' and copy the webhook URL provided.
- In your GitHub repository, go to Settings > Secrets and variables > Actions.
- Click "New repository secret", name it
MSTEAMS_WEBHOOK_URL, and paste the webhook URL as the value.
b. For Slack:
- Go to your Slack workspace's App Directory and create a new app (or use an existing one).
- Under 'Features', select
Incoming Webhooksand activate them. - Click 'Add New Webhook to Workspace' and select the channel for notifications.
- Copy the webhook URL provided.
- In your GitHub repository, go to Settings > Secrets and variables > Actions.
- Click "New repository secret", name it
SLACK_WEBHOOK_URL, and paste the webhook URL as the value.
- Configure Terraform Cloud Secrets:
Set up the following secrets in your Terraform Cloud workspace variable settings for each environment (Sandbox, Staging, Production):
JAMFPRO_INSTANCE_FQDN: Your Jamf Pro instance URL. For example:https://your-instance.jamfcloud.com.JAMFPRO_AUTH_METHOD: Can be eitherbasicoroauth2.JAMFPRO_CLIENT_ID: Your Jamf Pro client id whenJAMFPRO_AUTH_METHODis set to 'oauth2'.JAMFPRO_CLIENT_SECRET: Your Jamf Pro client secret whenJAMFPRO_AUTH_METHODis set to 'oauth2'.JAMFPRO_BASIC_AUTH_USERNAME: Your Jamf Pro username whenJAMFPRO_AUTH_METHODis set to 'basic'.JAMFPRO_BASIC_AUTH_PASSWORD: Your Jamf Pro user password whenJAMFPRO_AUTH_METHODis set to 'basic'.
Note: For Terraform Cloud, when setting variables you do not need to prefix your env vars with TF_VAR_ as Terraform Cloud automatically does this for you. Additionally, ensure to select the variable category as Terraform variable, with the HCL tickbox unchecked.
- GitHub Repository-Level Setting:
At the repository level, you need to explicitly allow GitHub Actions to create or approve pull requests by adjusting the workflow permissions for your demo repository.
Steps:
- Navigate to the repository on GitHub.
- Go to Settings > Actions > General.
- Scroll down to Workflow permissions.
- Choose "Read and write permissions".
- Check the box for "Allow GitHub Actions to create and approve pull requests".
- Click Save.
-
Navigate to Repository Settings:
- Go to your repository on GitHub.
- Click on Settings in the repository navigation.
-
Access Rulesets:
- In the Settings sidebar, scroll down and click on Rules.
- Then, select Rulesets.
-
Create a New Ruleset:
- Click the New ruleset button to create a new branch protection ruleset.
-
Give the Ruleset a Name:
- In the Name field, enter a name of your choice, such as
ruleset-protect-staging+production.
- In the Name field, enter a name of your choice, such as
-
Set the Bypass List:
- In the Bypass list section, add
Organization adminas an exemption. This will allow organization admins to bypass the rules if necessary.
- In the Bypass list section, add
-
Target Branches:
- Under Target branches, add the branches you want to protect:
stagingproduction
-
Configure Branch Rules:
-
Set the following branch protection rules:
-
Restrict deletions: Enable this option to prevent deletion of the
stagingandproductionbranches. -
Require a pull request before merging: Enable this option to ensure that all changes are reviewed before merging.
-
Required approvals: Set this to
1to ensure at least one approval is required for merging. -
Dismiss stale pull request approvals when new commits are pushed: Enable this option to dismiss previous approvals when new commits are made.
-
Require approval of the most recent reviewable push: Enable this option to ensure that only the most recent commit is reviewed and approved.
-
Require conversation resolution before merging: Enable this option to ensure that all review conversations are resolved before the pull request can be merged.
-
Require status checks to pass: Enable this to ensure that all required status checks (e.g., CI/CD tests) pass before a pull request is merged.
-
Block force pushes: Enable this to block any force pushes to the
stagingandproductionbranches, ensuring that no one can overwrite the branch history.
-
-
Save the Ruleset:
- After configuring all of the rules, click Create or Save to apply the new ruleset to the
stagingandproductionbranches.
- After configuring all of the rules, click Create or Save to apply the new ruleset to the
-
Update Terraform Variables: Modify the
terraformblock in your.tffiles to match your Jamf Pro instance details. For example:
provider "jamfpro" {
jamfpro_instance_fqdn = var.jamfpro_instance_fqdn
jamfpro_load_balancer_lock = var.jamfpro_jamf_load_balancer_lock
auth_method = var.jamfpro_auth_method
client_id = var.jamfpro_client_id
client_secret = var.jamfpro_client_secret
log_level = var.jamfpro_log_level
log_output_format = var.jamfpro_log_output_format
log_console_separator = var.jamfpro_log_console_separator
log_export_path = var.jamfpro_log_export_path
export_logs = var.jamfpro_export_logs
hide_sensitive_data = var.jamfpro_hide_sensitive_data
token_refresh_buffer_period_seconds = var.jamfpro_token_refresh_buffer_period_seconds
mandatory_request_delay_milliseconds = var.jamfpro_mandatory_request_delay_milliseconds
}It's strongly recommended to ensure that jamfpro_load_balancer_lock is set to true, to avoid any issues with the Jamf Cloud load balancer.
-
Backend Configuration: For our multi-environment setup, we'll be using Terraform workspaces. This approach allows us to use a single set of configuration files while maintaining separate states for each environment. Here's how to structure it:
In your main Terraform configuration file (e.g.,
main.tf):terraform { cloud { organization = "deploymenttheory" workspaces { tags = ["jamf_pro"] } } }
This configuration tells Terraform to use Terraform Cloud with the "deploymenttheory" organization and to work with any workspace tagged with "jamfpro".
-
Terraform Provider Configuration: Specify the provider source and version:
terraform { required_providers { jamfpro = { source = "deploymenttheory/jamfpro" version = "0.3.1" } } }
-
Define Your Resources: Use Terraform resource definitions to manage your Jamf Pro resources.
-
Create a New Branch: When starting work on a new feature, bug fix, or any other change, create a new branch with an appropriate prefix. This naming convention is enforced by our workflows and helps categorize the type of work being done.
Use one of the following prefixes based on the nature of your work:
feat-: For new featuresfix-: For bug fixesdocs-: For documentation changesstyle-: For formatting, missing semi colons, etc; no code changerefactor-: For refactoring production codetest-: For adding missing tests, refactoring tests; no production code changechore-: For updating grunt tasks etc; no production code changebuild-: For changes that affect the build system or external dependenciesci-: For changes to our CI configuration files and scriptsperf-: For performance improvements
To create a new branch:
-
Ensure you're on the default branch (sandbox) and it's up to date:
git checkout sandbox git pull origin sandbox
-
Create and switch to a new branch with an appropriate prefix:
git checkout -b prefix-branch-name
Replace
prefix-with one of the prefixes listed above, andbranch-namewith a brief, descriptive name for your change.For example:
git checkout -b feat-add-policy
-
Make your changes on this new branch.
-
Push your branch to the remote repository:
git push -u origin prefix-branch-name
This naming convention helps our automated workflows identify the type of change and process it accordingly. It also makes it easier for team members to understand the purpose of each branch at a glance.
-
Make Changes and Push: Make your changes and push to GitHub.
-
Test in Sandbox: The
01 - terraform testing: sandboxworkflow will automatically run and perform terraform plans and linting upon each commit. -
Promote to Sandbox: After testing your changes in your feature branch, you can promote them to the Sandbox environment. This process involves creating a pull request to merge your feature branch into the
sandboxbranch. Here's how to do it:
-
Ensure all your changes are committed and pushed to your feature branch.
-
Go to your repository on GitHub.
-
Click on the "Pull requests" tab.
-
Click the "New pull request" button.
-
Set the base branch to
sandboxand the compare branch to your feature branch. -
Give your pull request a descriptive title and provide details about the changes in the description.
-
Click "Create pull request".
-
Request a review from your team members if required by your team's process.
-
Once the pull request is approved, merge it into the
sandboxbranch.
Important: The actual application of changes to the Sandbox environment is handled automatically by the "02 - terraform apply to: sandbox" workflow. This workflow is triggered when a pull request is merged into the sandbox branch.
After merging:
- The workflow will automatically start.
- It will apply the Terraform changes to the Sandbox environment.
- You can monitor the progress of this workflow in the "Actions" tab of your GitHub repository.
Remember: Always verify that the workflow completes successfully. If there are any issues, they will be reported in the workflow run logs.
By following this process, you ensure that your changes are properly promoted to the Sandbox environment and applied in a controlled, automated manner.
-
Promote to Staging: Now manually trigger the
02-release-and-plan-staging.ymlworkflow and approve the pull request to merge the release branch into thestagingbranch after change review. -
Apply to Staging:
This project uses an automated process for creating versions and preparing releases when promoting changes from the Sandbox environment to Staging. This process is implemented in the 03 - release and terraform plan to: staging workflow. Here's an overview of how it works:
The release process is initiated manually. To start this process:
- Go to the "Actions" tab in your GitHub repository.
- Find the "03 - release and terraform plan to: staging" workflow.
- Click "Run workflow".
- Select the
sandboxbranch as the base for the release. - Click "Run workflow" to start the process.
Once triggered, the workflow performs the following steps:
-
Version Creation:
- The workflow automatically determines the next version number based on semantic versioning principles.
- It creates a new tag with this version number.
- A new release is created in GitHub with this tag.
-
Branch Creation:
- A new branch is created with the name pattern
release-v{version}-to-staging. - This branch contains all the changes that were in the
sandboxbranch.
- A new branch is created with the name pattern
-
Terraform Plan:
- The workflow runs a Terraform plan against the Staging environment.
- This plan shows what changes will be applied to the Staging environment if this release is approved.
-
Pull Request Creation:
- A pull request is automatically created to merge the release branch into the
stagingbranch. - The pull request description includes:
- The new version number
- A summary of the Terraform plan (resources to be added, changed, or destroyed)
- A link to the full Terraform plan in Terraform Cloud
- A pull request is automatically created to merge the release branch into the
After the workflow completes:
- Review the pull request and the Terraform plan carefully.
- If everything looks correct, approve and merge the pull request.
- Merging the pull request will trigger the "04 - terraform apply to: staging" workflow, which will apply the changes to the Staging environment.
- Always review the Terraform plan before approving the release to Staging.
- The version number is automatically incremented. You don't need to manually manage version numbers.
- Each release creates a permanent tag in your repository's history, making it easy to track what changes were included in each release.
- If you need to make changes after creating a release but before applying to Staging, you can push additional commits to the release branch before merging the pull request.
This automated process ensures consistent versioning, provides a clear history of releases, and allows for a final review before applying changes to the Staging environment.
-
Promote to Production: Repeat the process for promoting to Production by manually triggering the
04-release-and-plan-production.ymlworkflow and approving the pull request to merge the release branch into theproductionbranch after change review. -
Apply to Production: After the pull request is merged, the
05-terraform-apply-production.ymlworkflow will automatically run to apply the changes to the Production environment.



