Enables the deployment of terraform defined AWS resources from ServiceNow via Terraform Enterprise
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.
- 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
- Create a
terraform.tfvars
file in the scripting_host folder and add your environment variables. - Deploy scripting host using
terraform apply
. - Grab the ssh public key using the URL providded in the
pub_deployment_key
output, so it can be added to GitLab. - Note the URL of the
gitlab_webhook
output.
Note: Module repositories must meet the same requirements as those outlined for addition to the Terraform Module Private Registry
- Create a Gitlab repo with the
terraform-<PROVIDER>-<MODULE_NAME>
name format - Add the terraform scripting host (tfsh) url as a webhook under Repo > Settings > Integrations
- Select
Tag push events
andEnable SSL verification
- Click the
Add Webhook
button to complete
- Select
- Add the terraform scripting host public key to the repo
- Add a version tag to your project before commit that follows the PEP 440 standard (ex: 1.0.2)
- ServiceNow instance REST api account credentials
- Generate a USER oauth token
- Add Gitlab as a VCS in your Terraform Enterprise organization
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=
- Clone this repo
- Configure your local env to target the correct AWS account
- Navigate to the
scripting_host
folder and create aterraform.tfvars
file specific to your target AWS env - Run
terraform apply
- Add the
Scripting Host
as an application in yourgitlab
account - Add the
Scripting Host
's public key (available at https://yourscriptinghost/pub-key/key.txt) as aDeploy Key
with read access
- A Gitlab project is created for the source terraform module and associated with the webhook listener on tag update
- 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
For more information on installing and using TerraSnow Enterprise, go to https://terrasnow-enterprise.readthedocs.io