Running vRealize Automation (VRA), I wanted to create a new catalog item in Service Broker that would basically self-destruct after a certain time. My intent is to allow our Windows engineers to quickly spin up a new machine in AWS with a lease applied to it.
I could find a catalog template setting that allowed me to configure this, so I found that I could do this via a REST call to the VRA. So I decided to work on creating an extensibility action using Powershell.
Note, once a lease is set, I don't think it's possible to remove the lease.
- Extensibility Actions on Prem integration server configured.
- VRA refresh token defined. This will be used in step 0.
- BlueprintID of a catalog template that will apply the lease to. We'll need this for step 2. The blueprint id can be captured easily from the URL when viewing it in the design menu. Copy everything after the %2F, for example (the bolded portion):
Step 0: setup Action Constant
- Inside VRA - Extensibility menu, select Actions on the sidebar.
- Select Action Constants and add a + New Action Constant
- Enter the name of "refreshToken" and paste the refresh token string into the value field and select toggle to enable the Encrypt the action contact value.
- Click SAVE.
Step 1: create the action
- Extensibility menu, Actions on sidebar and click + New Action
- Define the new action Name "SetDeploymentLease" and select the VRA Project that this will run against then click Next.
- On the top, change the dropdown from PYTHON to POWERSHELL.
- Copy the pastebin code below and paste it into the body of the action.
- Under Default Inputs, add two more input fields (for a total of 3). These fields will be used during the run-time of the action.
- Default - LeasePeriod - Positive integer for the number of days to define the lease.
- Default - deploymentId - can be anything, this will be sent to the action from the subscription event defined in step 2. I copied the deployment id off an existing 'test' deployment directly from the URL. (like prerequisites, it's everything after the %2F).
- Action Constant - refreshToken - this will pull the value from Step 0.
- SAVE the action
Step 2: create a subscription - The subscription will trigger after the blueprint is run.
- Extensibility menu, Subscriptions option on sidebar and click + NEW SUBSCRIPTION
- Give subscription name.
- For Event Topic select "Deployment Resource Completed"
- Enable the Condition and enter a (case matters) single value of:
event.data.blueprintId == "value from pre-requisites"
- Action/Workflow: select the new action you created in Step 1.
- Projects: Select the project you specified in step 1, item 2.
- Option: If valid values are entered in step 1 part 5, the test button on the Action will run.
- Option: Deploy a new machine using the catalog item defined in the prerequisites. Within a minute after the deployment completes the build, the lease should be applied via the subscription.
Post a Comment