Prereq - CI/CD and SVC
If these terms are alien to you, this would be a good time to take a pause, grab your favourite beverage and have a read of the follow documentation
With that out of the way, the first thing we’ll need to get setup for the labs is a pipeline as all your code would need to run somewhere.
While we can execute our terraform code manually, as explained in the next section and mainly in lab environments or personal cloud accounts, we advice that you stick to having your code in a git repo in your live environments.
This section will introduce you to our Git repo and Azure DevOps pipelines, we know you will need to visit Git and Azure pipelines like everyday so we might as well get started with that.
Lab Git Repo
Platform Operations uses Git for it’s source control. To create a repo for your lab, follow the steps below
- Navigate to the HMCTS git organisations page. If you dont already have access you can double check the Onboarding Checklist to make sure you have the right access. You can also speak to a team member to assist if needed. #platform-operations
Create a new git repo. Call this repo
lab-yourname-goldenpath
. You can follow this convention in other sections of this exercise as this makes it easier to when cleaning up resources after the labs.Create new Git repo
๐ In a production environment you will need to update your new repository’s settings to allow merging to master
| main
only from a branch PR and also to require at least 1 reviewer for PR’s created. You can
learn more about this in the Managing your repositoryโs settings and features documentation.
- Clone your new repo to your local machine as you will need this later.
Lab Pipeline
You will also need a devops pipeline to run your code. To create a pipeline, follow the steps below
Create a pipeline in Azure Devops. In Azure DevOps, navigate to the HMCTS Platform Operations organisation. On the
Pipelines
menu, click onPipelines
HMCTS DevOps Organisation
Create new DevOps project
Specify where you code repository is, in our case this would be Git
Specify Git repository
Follow the relevant screens and prompts, select your lab repository in Git which would be an item in the repos listed after authentication is complete. You may see screens similar to the once below
Create new pipeline
Select new pipeline repo
Authorise Azure DevOps
Build your resources
To get your resources provisioned, follow the steps below
- In the lab-azure-resource folder copy all the files into your repo root folder.
Your repo folder on your local machine should now look like this
.
โโโ .gitignore
โโโ azure-pipelines.yaml
โโโ components
โโโ README.md
โโโ lab
โโโ main.tf
โโโ provider.tf
โโโ variables.tf
๐ฃ NOTE: You may want to modify prefix in your resource names defined in main.tf. This will make them easier to identify, especially when there are multiple people doing labs at the same time. Ensure that the total resource name lengths do not exceed Azure limits, example:
prefix = "xy-${formatdate("YYMMDDhhmm", timestamp())}"
- Commit and push to your repo. This will trigger a devops pipeline run.
What did i just create?
A lot has happened and is a good place to walk you through what’s taken place so far
- If you have a look into the pipeline
yaml
file you will notice the following piece of config
resources:
repositories:
- repository: cnp-azuredevops-libraries
type: github
ref: refs/heads/master
name: hmcts/cnp-azuredevops-libraries
endpoint: 'hmcts'
This loads a central template resource that used in all our repos to provide base or required functionality that most pipelines need, you don’t have to configure certain functionality from scratch, you simply reuse.
Have a look at the cnp-azuredevops-libraries repo to findout what capabilities this can give you in your other projects.
You have all the terraform resource configuration that will spin up your lab resources
You dont need to manually run or define
plan
orapply
stages why?… yes, you guessed right, because it’s already configured in thecnp-azuredevops-libraries
‘s terraform step.
This is done by using the functionality as below
- stage: deploy
jobs:
- job: PlanAndApply
steps:
- template: steps/terraform.yaml@cnp-azuredevops-libraries
parameters:
...
and pass in the required parameters
- Thank us later ๐, you now have a default template that you can always use as a starting point on most repo’s you will create in the real world ๐.