Getting error while executing Terraform script in ServiceNow

Venkatesh S5
Kilo Contributor

Hello Team,

While we are trying to launch launch stack (Terraform code) in ServiceNow, it ends up with "  Failed to execute API - Please input value for credential field(s) -UserName, Password. (script_include:TerraformExecutor; line 56)".

Note: We have updated the credentials in Cloud admin portal already. 

Please feel free to share your thoughts for further analysis. 

1 ACCEPTED SOLUTION

Ram Devanathan1
ServiceNow Employee
ServiceNow Employee

you need to modify the terraform files to add empty vars like this into the vars.tf -

#File =vars.tf
variable "vsphere_user" {}
variable "vsphere_password" {}
variable "vsphere_server" {}

and reference these vars in your provider block -

#File =provider.tf
# Configure the VMware vSphere Provider
provider "vsphere" {
 user = var.vsphere_user
 password = var.vsphere_password
 vsphere_server = var.vsphere_server
 # if you have a self-signed cert
 allow_unverified_ssl = true
}

for azure and aws this can be different, just look at standard provider block documentation for each provider and setup vars like this.

Once this is done, CPG will ensure that the creds are passed at runtime into the vars to eventually be used by Terraform.

you can look for reference / examples here -

https://github.com/MasterChefCloudMgmt

View solution in original post

11 REPLIES 11

Hello Sir,

I have tried with your reference script (MasterChefCloudMgmt/azure-simple-vm) and it got success while executing through Visual Studio whereas it ends up with below error while executing through CPG.

 

"Version constraints inside provider configuration blocks are deprecated on Provider.tf line 11, in provider "azurerm": 11: version = "2.27.0" Terraform 0.13 and earlier allowed provider version constraints inside the provider configuration block, but that is now deprecated and will be removed in a future version of Terraform. To silence this warning, move the provider version constraint into the required_providers block. Warning: "address_prefix": [DEPRECATED] Use the `address_prefixes` property instead. with azurerm_subnet.internal, on main.tf line 13, in resource "azurerm_subnet" "internal": 13: resource "azurerm_subnet" "internal" { System.Management.Automation.RemoteException Error: "name" may only contain alphanumeric characters, dash, underscores, parentheses and periods System.Management.Automation.RemoteException with azurerm_resource_group.main, on main.tf line 1, in resource "azurerm_resource_group" "main": 1: resource "azurerm_resource_group" "main" { System.Management.Automation.RemoteException (script_include:TerraformExecutor; line 130)"

ok at least the terraform provisioning started now so that's progress 🙂 thanks for doing the necessary steps to format the template for using with CPG. this will ensure that the cloud credentials in servicenow is used.

this error is indicating that there's a problem with the way the name is getting a value.. is there a variable for this?

Error: "name" may only contain alphanumeric characters, dash, underscores, parentheses and periods System.Management.Automation.RemoteException with azurerm_resource_group.main, on main.tf line 1, in resource "azurerm_resource_group" "main": 1: resource "azurerm_resource_group" "main"

 

 

Yes. We have variables in the script.

Can you share your files?

Ram

Provider  version = "2.89.0"

After performing, terraform init upgrade , Though we are getting error in ServiceNow CPG, instance is getting deployed in Azure. 

Attached error screenshot which I got in CPG.

Note: We have updated Terraform version to 1.1.5

Thanks.