ServiceNow Terraform Integration Patterns for Infrastructure as Code and Service Catalog

Integrating Terraform with ServiceNow spans two distinct but complementary approaches: using Terraform to manage ServiceNow configuration directly through a provider, and using ServiceNow Service Catalog to expose self-service Terraform provisioning through HCP Terraform. Both patterns address the operational need to bridge infrastructure-as-code automation with IT service management processes for change control, CMDB accuracy, and approval workflows.

Provider Model for Managing ServiceNow Configuration

A Terraform provider for managing configuration in ServiceNow instances via the Table API exists with 63 resources and 49 data sources spanning users and groups, ACLs and roles, UI scripts and macros, business rules, scripted REST APIs, service catalog items, scheduled jobs, REST/JDBC/HTTP connections, system properties, transform maps, widgets, and more.

Prerequisites for use include Terraform >= 1.0, a ServiceNow instance and an account with permission to read/write the tables you intend to manage, and for local development only Go >= 1.25.

The provider uses HTTP Basic authentication against the ServiceNow Table API.

A minimal configuration is:

hcl terraform { required_providers { servicenow = { source = "tylerhatton/servicenow" version = "~> 0.10" } } } provider "servicenow" { instance_url = "https://dev00000.service-now.com/" username = var.servicenow_username password = var.servicenow_password } resource "servicenow_user" "jane" { user_name = "jane.doe" first_name = "Jane" last_name = "Doe" email = "[email protected]" active = true }

Full documentation for every resource and data source is published on the Terraform Registry.

Using the provider allows teams to treat ServiceNow configuration as code. Users and groups, ACLs and roles, UI scripts, business rules, scripted REST APIs, service catalog items, scheduled jobs, connections, system properties, transform maps, and widgets can be declared, versioned, and applied with Terraform workflows. The provider scope covers both read and write operations through the Table API, enabling consistent configuration drift detection for ServiceNow environments.

HCP Terraform ServiceNow Service Catalog Integration

Set up ServiceNow Service Catalog integration for HCP Terraform

Integration version: v2.9.0

Note: The ServiceNow Catalog integration is available in HCP Terraform Standard and Premium editions. Refer to HCP Terraform pricing for details.

The Terraform ServiceNow Service Catalog integration enables your end-users to provision self-serve infrastructure via ServiceNow. By connecting ServiceNow to HCP Terraform, this integration lets ServiceNow users order Service Items, create workspaces, and perform Terraform runs using prepared Terraform configurations hosted in VCS repositories or as no-code modules for self-service provisioning.

The integration relies on Terraform ServiceNow Catalog integration software installed within your ServiceNow instance. Installing and configuring this integration requires administration in both ServiceNow and HCP Terraform. Since administrators of these services within your organization are not necessarily the same person, this documentation refers to a ServiceNow Admin and a Terraform Admin.

First, the Terraform Admin configures your HCP Terraform organization with a dedicated team for the ServiceNow integration, and obtains a team API token for that team.

The Terraform Admin provides the following to your ServiceNow admin:

  • An Organization name
  • A team API token
  • The hostname of your HCP Terraform instance
  • Any available no-code modules or version control repositories containing Terraform configurations
  • Other required variables token, the hostname of your HCP Terraform instance, and details about no-code modules or version control repositories containing Terraform configurations and required variables to the ServiceNow Admin.

Next, the ServiceNow Admin will install the Terraform ServiceNow Catalog integration to your ServiceNow instance, and configure it using the team API token and hostname.

Finally, the ServiceNow Admin will create a Service Catalog within ServiceNow for the Terraform integration, and configure it using the version control repositories or no-code modules, and variable definitions provided by the Terraform Admin.

ServiceNow Admin responsibilities include:
- Prepare an organization for use with the ServiceNow Catalog.
- Create a team that can manage workspaces in that organization.
- Create a team API token so the integration can use that team's permissions.
- If using VCS repositories, retrieve the OAuth token IDs and repository identifiers that HCP Terraform uses to identify your VCS repositories. If using a no-code flow, create a no-code ready module in your organization's private registry.

Terraform Admin responsibilities include preparing the organization and team and supplying credentials.

Connecting ServiceNow to HCP Terraform

Search for the "Terraform" integration, published by "HashiCorp Inc".

ServiceNow Roles required: admin or xterraform.configuser

Once the integration is installed, the ServiceNow Admin can connect your ServiceNow instance to HCP Terraform. Before you begin, you will need the information described in the "Configure HCP Terraform" section from your Terraform Admin.

Once you have this information, connect ServiceNow to HCP Terraform with the following steps.

  • Navigate to your ServiceNow Service Management Screen.
  • Using the left-hand navigation, open the configuration table for the integration to manage the HCP Terraform connection.
  • Terraform > Configs
  • Click on "New" to create a new HCP Terraform connection.
  • Set Org Name to the HCP Terraform organization name.
  • Click on the "Lock" icon to set Hostname to the hostname of your Terraform Enterprise instance. If you are using the SaaS version of HCP Terraform, the hostname is https://app.terraform.io. Be sure to include "https://" before the hostname.
  • Set API Team Token to the HCP Terraform team API token.
  • Optional To use the MID Server, select the checkbox and type the name in the MID Server Name field.
  • Click "Submit".

Now that you have connected ServiceNow to HCP Terraform, you are ready to create a Service Catalog using the VCS repositories or no-code modules provided by the Terraform Admin.

Navigate to the Service Catalog documentation to begin.

Integration Points Between Terraform and ServiceNow

Enterprise organizations running Terraform often need to integrate with ServiceNow for change management, configuration management database CMDB updates, and approval workflows. This integration bridges the gap between infrastructure-as-code automation and traditional IT service management processes. When done well, it allows teams to maintain the speed of automated deployments while satisfying compliance and audit requirements.

This guide covers practical approaches to integrating Terraform with ServiceNow, from automatic change request creation to CMDB synchronization.

Understanding the Integration Points

Terraform and ServiceNow typically integrate at several points. Before applying changes, Terraform can create change requests in ServiceNow for approval. After applying changes, it can update the CMDB with new or modified configuration items. If something goes wrong, it can create incidents automatically. The integration happens through the ServiceNow REST API.

Creating Change Requests Before Apply

Use a CI/CD step, a local-exec provisioner, or a custom provider to create ServiceNow change requests as part of the plan-apply workflow.

Developer Reference for Variable Mapping and Workflows

The Terraform ServiceNow integration can be customized by ServiceNow developers using the information found in this document.

ServiceNow has the concept of a Variable Set which is a collection of ServiceNow Variables that can be referenced in a Flow from a Service Catalog item. The Terraform Integration codebase can create Terraform Variables and Terraform Environment Variables via the API using the tf_variable.createVariablesFromSet() function.

This function looks for variables following these conventions:

ServiceNow Variable Name HCP Terraform Variable
tfvarhclVARIABLENAME Terraform Variable: VARIABLE_NAME
tfenvENV_NAME Environment Variable: ENV_NAME
sensitivetfvarhclVARIABLE_NAME Sensitive Terraform Variable (Write Only): VARIABLE_NAME
sensitivetfenvENVNAME Sensitive Environment Variable (Write Only): ENV_NAME

This function takes the ServiceNow Variable Set and HCP Terraform workspace ID. It will loop through the given variable set collection and create any necessary Terraform variables or environment variables in the workspace.

The Terraform/ServiceNow Integration codebase includes ServiceNow Script Includes Classes that are used to interface with HCP Terraform.

The integration builds on top of a few generic constructs from ServiceNow's API.

  • Catalog: Catalogs are a top-level collection which provides an entry point for users to interact with the integration.
  • Variables and Variable Sets: Variables and by extension, Variable Sets are embedded within Forms and provide fields for users to enter data. This could be anything from collecting AWS IAM credentials to Workspace names.
  • Workflows: Workflows allow users to embed an ECMA5 script that can access variables from the invoking object. The two types of workflows utilized in this integration are scheduled on an interval and triggered manually. This allows users to interact with the Terraform API in the form of polling and implicitly.

Example End-to-End Flow

HashiCorp recently created a Terraform ServiceNow integration, which provides essential building blocks for integrating Terraform and ServiceNow.

The GIF above depicts the end result and functionally, the following actions.

  • Creating a Workspace with ServiceNow
  • Adding AWS Credentials and an instance_type in Terraform Cloud
  • Manually triggering a Terraform Run
  • Sentinel forces a policy override due to the Terraform plan having a monthly cost of more than $20/month
  • A manual approval request is created for Spa Ghetti in ServiceNow
  • We manually approve the request in ServiceNow
  • A REST request is made to the Terraform Policy Override API

This flow demonstrates self-service provisioning through Service Catalog, variable collection for credentials and instance type, policy enforcement via Sentinel, and approval gating through ServiceNow before Terraform policy override is granted.

Conclusion

ServiceNow Terraform integration serves two complementary objectives. The Terraform provider for ServiceNow enables configuration-as-code management of ServiceNow itself, covering 63 resources and 49 data sources with Table API access via HTTP Basic authentication. The HCP Terraform ServiceNow Service Catalog integration enables self-service infrastructure provisioning through ServiceNow, requiring coordinated setup by a Terraform Admin and a ServiceNow Admin, team API tokens, organization linkage, and variable set mapping via tf_variable.createVariablesFromSet() conventions.

Effective use depends on understanding the integration points: change request creation before apply, CMDB synchronization after apply, and incident creation on failure via ServiceNow REST API. Developer customization relies on Variable Sets, Catalogs, and Workflows within ServiceNow, with naming conventions that map ServiceNow variables to Terraform variables and environment variables, including sensitive variants.

Organizations should plan role separation, secure credential handling for team API tokens and ServiceNow instance access, and governance around no-code modules or VCS repositories exposed through Service Catalog. With both the provider model and the HCP integration in place, teams can maintain infrastructure velocity while satisfying IT service management controls.

Sources

  1. github.com/tylerhatton/terraform-provider-servicenow
  2. developer.hashicorp.com/terraform/cloud-docs/integrations/service-now/service-catalog-terraform
  3. oneuptime.com/blog/post/2026-02-23-how-to-integrate-terraform-with-servicenow/view
  4. developer.hashicorp.com/terraform/cloud-docs/integrations/service-now/service-catalog-terraform/developer-reference
  5. github.com/peytoncasper/terraform-servicenow-example

Related Posts