In the final exercise, we are going to use some DSC + Octopus magic to Automatically Deploy to our transient infrastructure.
- Learn how we can automatically deploy our software along with our infrastructure
-
Open .\Exercise5\Parameters.ps1. Update the ResourcePrefix parameter to your initials, and take note of the other parameters provided
-
Open up .\Exercise5\Deploy.ps1
-
With PowerShell, write a file to scriptPath\Scripts\Variables.ps1 containing a HashTable named $BootstrapParameters that contains the values of the following parameters
- OctopusServerUrl
- OctopusApiKey
- OctopusRole
- Octopus.Environment.Name as 'Environment'
-
The astute observer would notice that this file will be scooped up into our scripts zip that we then download onto our instances during cfn-init
-
Navigate to .\Exercise5\PowerShellModules\cOctopus\DSCResources\cTentacleAgent\cTentacleAgent.psm1 and open it up in PowerShell ISE
-
Follow through Set-TargetResource and see how it does its thing
-
Go to Octopus, open the CloudFormawesome project, and navigate to its Triggers. Take a look at the trigger that will deploy our software when our transient infrastructure enters our environment.
-
Open up .\Exercise5\Scripts\ConfigureWebserver.ps1
-
At the top of the file, determine the execution location using
-
This will give us the root execution location - c:\cfn. Now we can dot-source our variables.ps1 file that will be downloaded onto the machine
-
Now that we have our $BootstrapParameters collection in scope, we can use the values in it to add a cTentacleAgent resource to the end of our DSC configuration
-
Return to .\Exercise5\Deploy.ps1 and F5!
-
Monitor your stack's creation, and once your instances are available, remote in and take a look in the cfn-init log along with the DSC logs and ensure the operation was successful
-
If all went well, your machines should pop up in Octopus, and have a deployment triggered for themselves (one deployment per machine)
-
Hit your load balancer URL returned by the script! Wow! Such automated. Much website