add deprovision workflow

This commit is contained in:
John Bowdre 2022-06-29 13:38:23 -05:00
parent 30927e8500
commit 60d78858a0
3 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,14 @@
# VM Deprovision workflow
Performs cleanup tasks upon deployment deletion (currently just removing the static DNS record).
![Schema](schema.png)
## Inputs/Outputs
| Name | Type | Direction | Description |
|:--- |:--- |:---|:---|
| `inputProperties` | Properties | Input | full request payload from vRA |
## Variables
| Name | Type | Value | Description |
|:--- |:--- |:--- |:--- |
| `dnsHost` | CompositeType(sshHost:string, sshUser:string, sshPass:SecureString, dnsServers:Array/string, supportedDomains:Array/string):dnsHost | `Endpoints: dnsHost` | object which stores endpoint and credential details for DNS operations |

View File

@ -0,0 +1,32 @@
/* JavaScript: delete dns record
Deletes records in Microsoft DNS by way of an SSH bastion host upon deployment deletion.
Inputs: inputProperties (Properties), dnsHost (CompositeType(sshHost:string,sshUser:string,sshPass:SecureString,dnsServers:Array/string,supportedDomains:Array/string):dnsHost)
Outputs: none
*/
var hostname = inputProperties.resourceNames[0];
var dnsDomain = inputProperties.customProperties.domain;
var deleted = false;
if (dnsHost_supportedDomains.indexOf(dnsDomain) >= 0) {
System.log("Attempting to remove DNS record for " + hostname + "...");
var sshSession = new SSHSession(dnsHost_sshHost, dnsHost_sshUser);
System.debug("Connecting to " + dnsHost_sshHost + "...");
sshSession.connectWithPassword(dnsHost_sshPass);
for each (var dnsServer in dnsHost_dnsServers) {
if (deleted == false) {
System.debug("Using DNS Server " + dnsServer + "...");
var sshCommand = 'Remove-DnsServerResourceRecord -ComputerName ' + dnsServer + ' -Name ' + hostname + ' -ZoneName ' + dnsDomain + ' -RRType A -Force';
System.debug("sshCommand: " + sshCommand);
sshSession.executeCommand(sshCommand, true);
if (sshSession.exitCode == 0) {
System.log("Successfully deleted DNS record.");
deleted = true;
}
}
}
sshSession.disconnect();
if (deleted == false) {
System.warn("Error! Unable to delete DNS record.");
}
} else {
System.log("No need to remove DNS records.");
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB