Terraform Connector - Cloud Provisioning and Governance
hi everyone my name is Gavin Whitlock and I'm an itom solution consultant with servicenow today we'll be going over the terraform connector which is part of the cloud provisioning and governance module within the itom suite of applications for our agenda we'll cover the configuration provider setup we'll talk about Cloud catalog item setup and then of course resource provisioning indeed provisioning let's get started so the first thing you'll want to do is navigate to the cloud admin portal from the cloud admin portal on the left-hand toolbar select manage and then config management and from here we'll build out our config provider so if I click new I'll see a form that allows me to fill out my config provider name the provider itself which in this case will be terraform environment that's because we're using an open source version of terraform and it's on a Linux server I'll then pre-fill the URL for my Linux server and then the base directory under which I have saved my terraform templates I'll select a credential and I just pre-built SSH credentials so that when we run Discovery or execute any terraform commands it has the ability to log into that Linux server or sshn go ahead and hit submit and then I'll select the config provider that we just built and then I will kick off a discovery run to go out and grab those terraform templates as you can see the templates were already discovered so I'll click on them just to ensure that they were discovered appropriately I can see the two terraform templates that I built were discovered so if I click in the main I can view the content of that template and go back and click into the variables template and what I want to point out here is this configuration variable so this is just a complex variable within terraform and this is what we'll use to construct the details of the resources that we want to provision in AWS via terraform okay next thing we need to do is start to build out our Cloud catalog items so if I click on design on the left hand toolbar click on cloud catalog items and then click on create Cloud catalog item so I'll go ahead and start to fill out the details within this form you know first the name of the catalog item itself I will then update the catalogs under which this catalog item will appear adding in the surface catalog this just makes it accessible via the employee Center I'll then update the source for config management template select terraform environment and select the provider that we just built foreign I'll go ahead and hit save and then we'll see the related links populate down below what we need to do next is add in the cloud templates that we recently discovered on our Linux server so if I click new under the configuration installable drop down I'll just type in the name of the terraform templates that we discovered which in this case is just templates I'll hit save um and then I can see the details of those templates just concatenated in one single View and then after this view making sure everything looks correct I'll go ahead and activate this Cloud template now the next thing we need to do is build out our variable set our variable set will give us the ability to define the different details of the resources that we want to build within AWS so if I click variable set tab click new um one thing I want to point out here is the type is usually a read-only option if I right click and hit configure dictionary on that field value I'll be able to uncheck that read-only checkbox as you can see I've already done this so I'll just go ahead and go back so I'll start to fill out this form entering the name of the variable set in this case just request items I'll then select the type which will be multi-row and then the layout which will be two columns alternating sides really depends on how you want this to look on the end user side I'll hit save and then I'll start to add the variables to this variable set so in all I'll add eight variables but this is a fully configurable section based on what resources you want to add and what details you want to add to those resources I am just going to be creating an ec2 instance so I'll be adding a couple tags I'll be adding Ami I'll be adding Security Group subnet instance type um and a field for a number of instances and you can use any type variable types that you'd like whether it's a reference field as you can see here I'm pulling pulling in the business application um because I want that to be a tag attached to the ec2 I'll add a few others I'll also you'll also see me adding in some default values here things like default instant type will be T2 micro and a default value for the Ami what I want to point out here is notice that the question is different from the name and that's because you want the name to correspond to the variable that is listed in the terraform template so four vpcs it's our security groups are there's its VPC underscore security underscore groups underscore IDs all right so that completes all the variables the next thing I want to do is add a catalog client script and what this will allow us to do is take all the details that we entered in that newly created variable set and throw it into a Json object to then be placed into our terraform template um and this is going to be triggered uh via on submit so when we submit this catalog item it'll jsonify everything and put it in the appropriate place and as you can see here I'll just quickly copy and paste a function that I already have written out and what I want to point out at the bottom here is under that set Value method the point where I'm placing it has to match the catalog item so it's just a catalog item name underscore configuration because that's the name of the variable where that Json object needs to go the next thing I want to do is actually under the provision variable set and the that variable that I was just talking about where the Json goes I want to make this not mandatory that is just because when I go to submit if it's mandatory it'll technically be blank so we just got to make sure it's not mandatory all right the one of the last things we want to do here is update the connected content and so this is essentially just adding in a category where this catalog item will live within the employee Center so I'll just choose i t for it next thing I want to do is actually go to the employee Center and request this catalog item so if I click the catalog item that we just built I'll go ahead and complete all the details within the form itself choosing the appropriate AWS account choosing the appropriate region naming the stack selecting the user group of course the user group is the one that handles all the change requests all the tasks associated with this catalog item you know cost center or business service then I can go down to the variables so that we just created hit add and start to add in rows to this table to generate resources that will be provisioned in AWS so I'll just use a pretty much all the defaults here but I'll create two instances hit add and then I'll go ahead and hit order now and you can see here the Json that populated as a result of us filling out that variable set and here are all the steps that need to be taken so approval go through if it's already approved hit refresh again and then we'll see that deployment was successful jumping over to the AWS console I just want to show you that these two instances were created see all the details we can see the tags that were applied so obviously a successful deployment going back into the servicenow instance I'm going to navigate to the cloud user portal and from here I'll click on view activities um look at the the stack that was just created and view stack details I can then see all the resources that were created if I click on the resources option itself and click on one of those resources I can actually take individual actions on those resources so in this case I'll just hit stop to stop that one ec2 instance and then from here I'll jump over back into the AWS console just to show you that that individual ec2 instance actually is stopped so I just need to remove the running filter and then we can see that email one instance is stopping but I can also take actions on the entire stack itself in this case I wanted to deep provision the entire stack so tear down both those ec2 instances that we created so if I go over to the stack details similar to the operations that we took on the individual resource I can take active actions on the stack itself so I'll select the provision it'll go through some steps and eventually it'll show that this stack is terminated within our servicenow instance and then if we jump back over to the AWS console and refresh we can see that those two ec2 instances have been terminated the last thing I want to do is just show how this populates within the cmdb the VM instances table so you can see those two VM instances populate here but now they had their state is terminated thank you and I hope this is helpful
https://www.youtube.com/watch?v=AteTNgnnc58