- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 05-27-2025 04:20 PM
Introduction
This article covers how to:
-
Register an Application Service in ServiceNow using theServiceNow CLI
-
Automatically link resources to Application Services using tags using Infrastructure-as-Code (IaC) tools
Step A: Install and Configure the ServiceNow CLI and Required Plugins
The ServiceNow CLI provides a powerful command-line interface to interact with your ServiceNow instance. The CMDB Application for APIs and CLI plugin is essential to enable capabilities required for Service Mapping.
Required Plugins
Ensure the following plugins are activated in your ServiceNow instance:
-
CLI Metadata
-
CMDB Application for APIs and CLI
Install the ServiceNow CLI
-
Download the installer bundle for your operating system (Mac, Windows, or Linux) from the ServiceNow Store.
-
Follow the CLI installation instructions provided in the ServiceNow product documentation.
Configure the CLI
Establish a secure connection between your CLI and ServiceNow instance:
snc configure profile set
Refer to the ServiceNow CLI available commands for detailed setup instructions.
Step B: Register and Populate the Application Service via CLI
This step defines your Application Service programmatically, including its metadata, relationships to business services, and a tag-based population method. This ensures that Configuration Items (CIs) with matching tags are automatically associated with the Application Service.
The primary CLI commands used here are:
- snc service-graph app-service register --data '{JSON}'
- snc service-graph app-service populate --data '{JSON}'
1. Construct a JSON Payload
Prepare a file named BookMyAppointment_App_Service.json
with your Application Service details:
{
"name":"BookMyAppointment Application Service",
"environment":"Development",
"version":"1.0",
"busines_criticality":"2 - somewhat critical",
"support_group":"0a52d3dcd7011200f2d224837e6103f2",
"short_description":"Application service for appointment scheduling",
"owned_by":"5137153cc611227c000bbd1bd8cd2005",
"install_status":"1",
"relationships":{
"business_application":[
{
"sys_id":"a18f54a833d56a106622a3134d5c7b01"
},
{
"number":"APM0001001"
},
{
"name":"BookMyAppointment"
}
],
"technical_service_offering":[
{
"sys_id":"a6c0e42c33d56a106622a3134d5c7b3e"
},
{
"number":"BSN0001004"
},
{
"name":"BookMyAppointment Technical Service Offering"
}
]
},
"tags":[
{
"key":"Application",
"value":"BookMyAppointment"
}
]
}
2. Register and Populate Application Service via CLI
Use the following shell script commands:
# Register Application Service using CLI command
registerData=$(cat BookMyAppointment_App_Service.json)
snc service-graph app-service register --data "$registerData" > register_service_result.json
result1=$(cat register_service_result.json)
number=$(echo "$result1" | sed -n 's/.*"number": *"\([^"]*\)".*/\1/p')
#The population_method is set to tag_list. This tag will be used in your cloud infrastructure to link resources back to this application service.
populate_data='{ "number":"'"$number"'", "population_method":{ "tags":[ { "key":"service_graph", "value":"'"$number"'" } ], "type":"tag_list" } }'
snc service-graph app-service populate --data "$populate_data" > populate_service_result.log
#Store the Service Graph Number in the variables file
service_graph_tags="
service_graph=\"${number}\"
"
echo "$service_graph_tags" > terraform.tfvars
Step C: Define and Tag Cloud Resources in Terraform
1. Define the Variable in Terraform
Add the following to your variables.tf file:
variable "service_graph" {
type = string
description = "The ServiceNow Application Service Number for tagging cloud resources."
}
2. Use the Variable in Your Terraform Configuration
resource "aws_vpc" "east2_vpc1" {
cidr_block = "10.1.0.0/20"
instance_tenancy = "default"
enable_dns_hostnames = "true"
enable_dns_support = "true"
assign_generated_ipv6_cidr_block = "true"
tags = {
Name = "BookMyAppointment "
Environment = "Development"
service_graph = var.service_graph
}
}
3. Plan and Apply Changes
Execute the following Terraform commands to provision or update cloud resources with the defined tags:
terraform plan -no-color -out apply.out
terraform apply "apply.out"
Step D : Verify the Service Map
1. Check your cloud provider’s console to confirm resources are correctly tagged.
2. Execute the AWS Service Graph Connector or Cloud Discovery to ingest the cloud resource data and verify the CIs are ingested into CMDB
3. Navigate to the Application Service in ServiceNow and validate that the Service Map is populated.
- 1,069 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @Shanay Shah
Looking for suggestion on how to handle cloud resources where we cannot map APM tags.
While it makes sense to create an Application (APM) and tag it in the Cloud Resources, how do we handle tagging for scenarios where subscriptions (and resources) are created for POCs, experimentations, etc.? E.g. I want to test xyz thing on the VM, hence raised the request and worked on it for 1 week. This needs to be reported as well because we are looking out for the IAAS VMs where vulnerability can occur. If we put this POC as an APM record, it will flood the table. What is the best way to report them as well as not save them in APM record? Shall we keep them Orphan CIs (from APM pov)?