Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Terrraform resource management from ServiceNow

License

Notifications You must be signed in to change notification settings

Tech-Modernization/terrasnow-enterprise

Repository files navigation

TerraSnow Enterprise

Enables the deployment of terraform defined AWS resources from ServiceNow via Terraform Enterprise

Overview

This project contains a terraform template to deploy a Ngnix reverse proxied, Flask based endpoint that handles Gitlab Tag and Push events by creating a ServiceNow Terraform Module Catalog Item within your target ServieNow Catalog.

Additionally, this project enables ServiceNow to create a Terraform Enterprise workspace from the source terraform resource catalog item.

Requirements

  • Pre-configured AWS account
  • Latest version of terraform installed on your local machine
  • Pre-configured Gitlab instance
  • Pre-configured ServiceNow Instance
  • Pre-configured Terraform Enterprise Instance
  • Credentials of ServiceNow user with API access

How to Use

Deploy Terraform scripting instance

  1. Create a terraform.tfvars file in the scripting_host folder and add your environment variables.
  2. Deploy scripting host using terraform apply.
  3. Grab the ssh public key using the URL providded in the pub_deployment_key output, so it can be added to GitLab.
  4. Note the URL of the gitlab_webhook output.

Adding Terraform Modules to ServiceNow Catalog

Note: Module repositories must meet the same requirements as those outlined for addition to the Terraform Module Private Registry

  1. Create a Gitlab repo with the terraform-<PROVIDER>-<MODULE_NAME> name format
  2. Add the terraform scripting host (tfsh) url as a webhook under Repo > Settings > Integrations
    • Select Tag push events and Enable SSL verification
    • Click the Add Webhook button to complete
  3. Add the terraform scripting host public key to the repo
  4. Add a version tag to your project before commit that follows the PEP 440 standard (ex: 1.0.2)

Deploying Terraform Resources from ServiceNow

Setup

ServiceNow

  • ServiceNow instance REST api account credentials

Terraform Enterprise

Generate conf.ini

Create this file and upload it to an encrypted S3 bucket.

[SERVICENOW]
INSTANCE_NAME=
SN_API_USER_NAME=
SN_API_USER_PWD=

[TERRAFORM_ENTERPRISE]
INSTANCE_NAME=
ATLAS_TOKEN=

Scripting Host (Deploy it)

  1. Clone this repo
  2. Configure your local env to target the correct AWS account
  3. Navigate to the scripting_host folder and create a terraform.tfvars file specific to your target AWS env
  4. Run terraform apply

Gitlab

Workflow Overview

  1. A Gitlab project is created for the source terraform module and associated with the webhook listener on tag update
  2. When the webhook receives a tag update event it queries the target servicenow instance for a catalog item matching the project name and version number.
  • if a catalog item is not found it creates a new one
  • if a catalog item is found and the version is the same as the previous it takes no action

Documentation

For more information on installing and using TerraSnow Enterprise, go to https://terrasnow-enterprise.readthedocs.io