Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
195 commits
Select commit Hold shift + click to select a range
c879d34
restructure the main readme and getting started
andregeuze Mar 1, 2018
eaa5368
add first version of new labs
andregeuze Mar 2, 2018
c0df00c
remove old content
andregeuze Mar 5, 2018
022bd9b
add links to labs
andregeuze Mar 5, 2018
19015d3
update link to getting started
andregeuze Mar 5, 2018
617f4fa
add example unit test code
andregeuze Mar 5, 2018
917bf63
update lab 1
andregeuze Mar 6, 2018
7265764
updated steps on lab 1
andregeuze Mar 7, 2018
03a4539
add stretch goals to lab 1
andregeuze Mar 7, 2018
602238e
add tutorial source, change order of approvals/gates
andregeuze Mar 7, 2018
73588b7
updated introduction with link to tutorial
andregeuze Mar 7, 2018
6dfd771
lab 3 update
andregeuze Mar 7, 2018
128aa26
lab 3 and 4 updated
andregeuze Mar 9, 2018
effdbfb
renamed getting started, processed feedback on lab 1-2-3
andregeuze Mar 12, 2018
478a619
add (stretch) lab-7
andregeuze Mar 12, 2018
05209bc
update lab 3 with stretch goals
andregeuze Mar 12, 2018
31c0e9f
add code examples to lab 4, add local test steps
andregeuze Mar 13, 2018
b3a489f
lab 5 update
andregeuze Mar 15, 2018
fd867c4
Added SonarLint as stretch
ALTrijssenaar Mar 16, 2018
e3dbd89
Merge pull request #1 from ALTrijssenaar/master
andregeuze Mar 16, 2018
6bfcf90
added code coverage as stretch for lab 1
Mar 19, 2018
137b132
Updated order of stretch goals for lab3
Mar 19, 2018
e2d0438
location change and comment
tomdebas Mar 20, 2018
bb21c3f
Personal AD required
tomdebas Mar 20, 2018
8dd6e97
reorder some tasks for lab 1, based on feedback
andregeuze Mar 23, 2018
ccc00c6
lab 4 update; startup code cleanup
andregeuze Mar 23, 2018
693d9f3
lab 5 updated with working UI test steps
andregeuze Mar 23, 2018
8b7c87c
minor text fix on lab 1 and 5
andregeuze Mar 23, 2018
3956885
add framework 4.7.1 requirement
andregeuze Mar 23, 2018
23adf01
update lab 5 steps
andregeuze Mar 23, 2018
70f96d5
lab 5 work completed
andregeuze Mar 23, 2018
d3a5eae
typo fix in lab 5
andregeuze Mar 23, 2018
0476f43
add final step to lab 5
andregeuze Mar 23, 2018
ae2b608
lab 6 update finished
andregeuze Mar 24, 2018
a4ed8e5
Merge pull request #2 from andregeuze/Review
andregeuze Mar 24, 2018
9e3797e
Fix typos and rewrite some instructions
andregeuze Mar 24, 2018
e6d440d
minor text changes
andregeuze Mar 24, 2018
84516e1
Merge branch 'master' of https://github.com/andregeuze/DevOpsHOL
andregeuze Mar 24, 2018
21dcf27
fix typo
andregeuze Mar 24, 2018
03852ae
change some texts in lab 1
andregeuze Mar 26, 2018
b5e8084
change Unit Test MSTest Test project
andregeuze Mar 26, 2018
19811ab
little rewrite
andregeuze Mar 26, 2018
a259373
change text on lab 1 and 2
andregeuze Mar 26, 2018
7a3170e
add image for clarification
andregeuze Mar 26, 2018
2d6a776
updated lab 3 with image and better description
andregeuze Mar 26, 2018
fd4acde
lab 4 text update
andregeuze Mar 26, 2018
903558b
add demos folder with devtestlabs scripts
andregeuze Mar 26, 2018
43278b6
update lab 4, removed namespaces in code examples
andregeuze Mar 26, 2018
17db06c
prerequisites updated to use devtestlabs
andregeuze Mar 26, 2018
32da4df
updated prerequisites
andregeuze Mar 27, 2018
916f57e
text change on prereqs
andregeuze Mar 27, 2018
6960e93
add prereq
andregeuze Mar 27, 2018
a0aaa9c
update lab 3 task name, update arm scripts
andregeuze Mar 27, 2018
cf86d90
add java requirement for vsts agents
andregeuze Mar 27, 2018
4d66180
textual change for lab 3
andregeuze Mar 27, 2018
a90fcca
lab 4 text update
andregeuze Mar 27, 2018
4f7580f
Few text fixes for lab 5
andregeuze Mar 27, 2018
9c23eb7
Add link to sonarqube extension docs in lab 3
andregeuze Mar 27, 2018
8dba2dc
add lab table with effort
andregeuze Mar 27, 2018
e7f6e95
update readme text
andregeuze Mar 27, 2018
8ea0f5c
lab 5 added instructions on where to add new files
andregeuze Mar 27, 2018
7684185
add filter to build
andregeuze Mar 27, 2018
b526bf7
replace subscription name with non-existing value
andregeuze Mar 27, 2018
7f0bafb
pre reqs updated, finished devtestlabs template with vsts agent vm
andregeuze Apr 2, 2018
b2beb41
labs 6 update
andregeuze Apr 2, 2018
9161bbe
lab 7 update
andregeuze Apr 2, 2018
903a72a
Add prereqs for trainers, updated trainee prereqs
andregeuze Apr 3, 2018
1f1081d
matt-byrne Nov 25, 2018
11b38e2
prerequisites updated
jebaSat Mar 13, 2019
ac92222
Updated Prerequisites
jebaSat Mar 13, 2019
b135093
updaed the code formatting
jebaSat Mar 14, 2019
44917d6
Merge pull request #4 from jebaSat/prerequisites-update
andregeuze Mar 14, 2019
37d044f
Merge pull request #3 from matt-byrne/master
andregeuze Mar 14, 2019
52f90f8
Avanade master (#6)
andregeuze Apr 5, 2019
c5638e9
update steps for creating an Azure Devops Project
andregeuze Apr 5, 2019
c72cb4d
fixes for lab 1
andregeuze Apr 5, 2019
fbf0c99
upgrade web app to dotnetcore 2.1
andregeuze Apr 5, 2019
1d53707
add fix for webapp runtime
andregeuze Apr 5, 2019
4438dab
tested labs 1 and 2, some fixes
andregeuze Apr 5, 2019
fad7fb9
update feature flag lab
andregeuze Apr 8, 2019
23716b3
update main introduction
janwkroes Apr 10, 2019
5f0989f
update prerequisites lab
janwkroes Apr 10, 2019
8417d86
update prerequisites formatting
janwkroes Apr 10, 2019
8fa4eb5
rename labs, update ui tests
andregeuze Apr 10, 2019
9b5bd67
moved some uitesting steps to lab 1
andregeuze Apr 10, 2019
7315c9f
undo master deletes
janwkroes Apr 10, 2019
7dbe026
resolve conflict
janwkroes Apr 10, 2019
0def0a3
attempt resolve conflict
janwkroes Apr 10, 2019
c711d0e
attempt resolve conflict
janwkroes Apr 10, 2019
272159e
Merge pull request #1 from andregeuze/master
janwkroes Apr 10, 2019
cb2ec9f
update pipeline lab (move functional tests to ui testing lab)
janwkroes Apr 10, 2019
5e0857b
reset pull request
janwkroes Apr 10, 2019
0261583
revert to geuze master
janwkroes Apr 10, 2019
1ad198c
revert to geuze master
janwkroes Apr 10, 2019
e5b3a3f
revert to geuze master
janwkroes Apr 10, 2019
47c23fb
update main instructions
janwkroes Apr 10, 2019
8fb9381
update main instructions
janwkroes Apr 10, 2019
c406650
add demo scripts for automation and dsc
andregeuze Apr 10, 2019
fd269b7
update prerequisites to azure portal instructions
janwkroes Apr 10, 2019
2581412
add vs gitignore
janwkroes Apr 10, 2019
94ef382
Merge branch 'master' into feature/lab-prerequisites
janwkroes Apr 10, 2019
be4e771
Merge branch 'master' into feature/feedback-main
janwkroes Apr 10, 2019
62e2da8
update gitignore
janwkroes Apr 10, 2019
29729fd
Merge branch 'master' into feature/feedback-main
janwkroes Apr 10, 2019
a0af837
remove obsolete
janwkroes Apr 10, 2019
f021d18
update prerequisites to azure portal instructions
janwkroes Apr 10, 2019
3da584e
Merge branch 'master' into feature/lab-devops-project
janwkroes Apr 10, 2019
70e54c5
update main instructions
janwkroes Apr 10, 2019
c2ffc49
update prerequisites to azure portal instructions
janwkroes Apr 10, 2019
bddf61f
remove gitignore
janwkroes Apr 10, 2019
29bac66
remove gitignore
janwkroes Apr 10, 2019
8e62bbe
remove gitignore
janwkroes Apr 10, 2019
136ae4f
remove gitignore
janwkroes Apr 10, 2019
8cc7157
move devops-project lab functional tests to ui testing lab
janwkroes Apr 10, 2019
3d6be9c
update main instructions (#8)
janwkroes Apr 10, 2019
d6d005c
revert prereqs to geuze master
janwkroes Apr 10, 2019
c9a5f15
revert to geuze master
janwkroes Apr 10, 2019
bf392c5
update prerequisites to azure portal instructions
janwkroes Apr 10, 2019
d24fefc
move devops-project lab functional tests to ui testing lab (#9)
janwkroes Apr 10, 2019
c120571
Merge branch 'feature/feedback-main'
janwkroes Apr 10, 2019
9776c4d
Merge branch 'feature/lab-devops-project'
janwkroes Apr 10, 2019
3d11dcb
Merge branch 'feature/lab-prerequisites'
janwkroes Apr 10, 2019
641040c
update prerequisites to azure portal instructions (#10)
janwkroes Apr 10, 2019
1bccd6c
update ui testing to work with visual studio test task
janwkroes Apr 11, 2019
7ec3517
fix formatting
janwkroes Apr 11, 2019
00078db
fix formatting
janwkroes Apr 11, 2019
69c675c
fix formatting
janwkroes Apr 11, 2019
4c24cc3
Merge branch 'master' into feature/lab-ui-testing
janwkroes Apr 11, 2019
cb3e8eb
update intro and prereqs
janwkroes Apr 11, 2019
901324c
Merge pull request #11 from janwkroes/feature/lab-ui-testing
andregeuze Apr 11, 2019
ea0b6c2
update sonarqube instructions to container instance
janwkroes Apr 11, 2019
000b5e6
fix formatting
janwkroes Apr 11, 2019
cab6953
fix formatting
janwkroes Apr 11, 2019
cb8a456
formatting
janwkroes Apr 11, 2019
1d2dcbb
Merge pull request #12 from janwkroes/feature/lab-sonarqube
andregeuze Apr 11, 2019
a8d1f5b
Merge branch 'master' of https://github.com/andregeuze/DevOpsHOL
andregeuze Apr 11, 2019
0b5e38c
Merge pull request #13 from andregeuze/changes
andregeuze Apr 11, 2019
8767278
update feature toggle instructions
janwkroes Apr 11, 2019
d1e3bd8
formatting
janwkroes Apr 11, 2019
a3f324c
formatting
janwkroes Apr 11, 2019
7c6c745
formatting
janwkroes Apr 11, 2019
ba76bf4
fix release variables
janwkroes Apr 11, 2019
36c8f73
fix feature toggle environment settings
janwkroes Apr 11, 2019
ef260c6
update smoke testing lab instructions
janwkroes Apr 11, 2019
efd5119
Merge pull request #14 from andregeuze/feature/lab-feature-toggles
andregeuze Apr 11, 2019
6448f84
Merge pull request #15 from andregeuze/feature/lab-smoke-testing
andregeuze Apr 11, 2019
94571e1
update lab order
janwkroes Apr 11, 2019
1dc34e7
Merge pull request #16 from andregeuze/feature/main-instructions
andregeuze Apr 11, 2019
fd3a636
fix smoke testing lab instructions
janwkroes Apr 12, 2019
d702ea1
fix ui testing instructions
janwkroes Apr 12, 2019
79565f5
add optional lab feature-branching
janwkroes Apr 12, 2019
2e2a222
Merge pull request #17 from andregeuze/fix/lab-smoketest
andregeuze Apr 12, 2019
07682e0
Merge pull request #18 from andregeuze/feature/lab-branch-protection
andregeuze Apr 12, 2019
3e5ed7f
fix formatting
janwkroes Apr 12, 2019
5760c6a
Merge pull request #19 from andregeuze/janwkroes-patch-1
andregeuze Apr 13, 2019
7569ef0
update prereqs to use microsoft edge
andregeuze Dec 10, 2019
76a6f17
update vm size
andregeuze Dec 10, 2019
7a253cd
update on CI
andregeuze Dec 22, 2019
12585b9
updates
andregeuze Dec 22, 2019
1523991
add authorize issue
andregeuze Dec 22, 2019
f132143
remove deploy from lab 1
andregeuze Dec 22, 2019
e35d761
first draft on new CD lab
andregeuze Dec 22, 2019
064a35b
deployments lab update
andregeuze Dec 22, 2019
43355c9
Initial version of new labs: Secure DevOps Kit and Terraform
Jan 5, 2020
8040349
Added Log Analytics workspace for Secure DevOps Kit
Jan 5, 2020
4f0cbc5
Added exercises for Log Analytics Workspace, AzSK Monitoring Solution…
Jan 5, 2020
bf95831
Minor tweaks to secure-devops-kit lab
Jan 5, 2020
128065a
Trying to outline the image inside secure-devops-kit
Jan 5, 2020
7d7d47f
Initial version of the Terraform lab + potential stretch goal for sec…
Jan 5, 2020
b23f21a
changed image from jpg to png
Jan 5, 2020
17ec413
Modified Lab1 to integrate K8s and Terraform
Feb 2, 2020
5c432f1
Modified lab1 and lab2
Feb 3, 2020
55972ee
Course lab changed first version uitesting
Feb 5, 2020
24df3da
Removed based-on-text
Feb 5, 2020
dd2dcff
Made Azure Pipelines Selenium YML proof
Feb 5, 2020
48bba11
Changed prerequisites UI testing lab
Feb 5, 2020
3095300
Changed content for SonarQube lab
Feb 6, 2020
caf3018
Updated prerequisites
Feb 6, 2020
4b1ab0e
Modified Smoke Tests to new solution
Feb 9, 2020
18cde2a
Added the new Secure DevOps kit lab
Feb 9, 2020
101b733
Removed not working component AzSK
Feb 9, 2020
5ff439b
Modified AzSK lab
Feb 9, 2020
4ce2f9d
Changed description AzSK in the index
Feb 9, 2020
3eb1844
Changed prerequisites for master
Feb 10, 2020
3a0f3d3
Edited the prerequisites file
Feb 10, 2020
47c4c08
Changed order of lab 5 and lab 6
Feb 11, 2020
052e320
Edited feature flags to support new solution
Feb 11, 2020
7ea75e4
adjust chapter 2 feature toggles
Feb 11, 2020
5581f0c
Updated UI-testing lab
Feb 12, 2020
0c9d272
Last fixes for lab 3 SonarQube
Feb 12, 2020
ec4f28f
Fixed markup lab 3
Feb 12, 2020
079f7fa
fix md lab 3
Feb 12, 2020
4a7e6d2
Merge branch 'master' into fix/refresh-2020
Dec 28, 2020
20e61c7
Added gitignore for local vs stuff
Dec 28, 2020
dd8e637
Added new ADO security scanner lab
Jan 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
################################################################################
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
################################################################################

/.vs/slnx.sqlite
80 changes: 16 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,16 @@
# Avanade DevOps HOL
These are the hands on labs associated with the Avanade DevOps Practitioners course. This is based to a large part on the [PartsUnlimitedHOL](https://microsoft.github.io/PartsUnlimited/basic/GettingStarted.html) but simplified to use the Visual Studio MVC sample application.

You can accomplish these labs using Visual Studio 2017 on your local computer, but you may want to consider doing the labs using an Azure VM as the development machine. This not only keeps you from having to make changes to your local environment, but it gives you additional experience using Azure. You can either configure an Azure development environment on your own or an easy way to do this is to use PowerShell ISE and execute the following commands. This will create a new Azure resource group and then configure an Azure VM with Windows 10 and Visual Studio 2017 Community edition. It will also use Chocolatey to install a collection of other tools and applications. **Review and modify the script to suit your own needs before executing such as changing to VS Enterprise and Window Server 2016 (VS-2017-Ent-Latest-WS2016)**

>**Note:** Sometimes this all works great but other times, the Chocolatey packages do not install when the VM is first created so you may need to run choco install for the individual packages to complete the environment setup.

>**Note:** Run PowerShell as an administrator.

```PowerShell
Login-AzureRmAccount
Select-AzureRmSubscription -SubscriptionName andrewmo
$VmName = "DevOpsHOL"
$DnsLabelPrefix = "<uniqueDNSName>"
$VmIPName = $VmName+"-ip"
$VmAdminUserName = "<VmAdminUserName>"
$VmAdminPassword ="<TopSecretPassword>"
$ResourceGroupName = "DevOpsHOL"
$ResourceGroupLocation = "East US 2"
$SecureStringPwd = ConvertTo-SecureString $VmAdminPassword -AsPlainText -Force
New-AzureRmResourceGroup -Name $ResourceGroupName -Location $ResourceGroupLocation -Verbose -Force
New-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupName `
-TemplateUri "https://raw.githubusercontent.com/nagroma/DevOpsHOL/master/azure-rm/azuredeploy.json" `
-VmName $VmName `
-VmSize "Standard_D2s_v3" `
-VmVisualStudioVersion "VS-2017-Comm-Latest-Win10-N" `
-VmAdminUserName $VmAdminUserName `
-VmAdminPassword $SecureStringPwd `
-DnsLabelPrefix $DnsLabelPrefix `
-ChocoPackages 'visualstudiocode;notepadplusplus;googlechrome' `
-Force -Verbose
```

Once the script above completes, you can use the following to start the VM and check to see that everything was installed correctly.

```PowerShell
Start-AzureRmVM -ResourceGroupName $ResourceGroupName -Name $VmName
while((Get-AzureRmVM -ResourceGroupName $ResourceGroupName -Name $VmName -Status | `
select -ExpandProperty Statuses | `
?{ $_.Code -match "PowerState" } | `
select -ExpandProperty DisplayStatus) -ne "VM running")
{
Start-Sleep -s 2
}
Start-Sleep -s 5 ## Give the VM time to come up so it can accept remote requests
$vmip = Get-AzureRmPublicIpAddress -Name $VmIPName -ResourceGroupName $ResourceGroupName
$hostdns = $vmip.IpAddress.ToString() ## $vmip.DnsSettings.Fqdn
cmdkey /generic:TERMSRV/$hostdns /user:"$VmName\$VmAdminUserName" /pass:$VmAdminPassword
Start-Process "mstsc" -ArgumentList "/V:$hostdns /f" ## use /span to use both monitors
```

Finally, when you are done, you can use the following scripts to
1. Shut down the VM to minimize Azure charges
```PowerShell
Stop-AzureRmVM -ResourceGroupName $ResourceGroupName -Name $VmName -Force
```
2. Delete the entire resource group when done with the labs or to start fresh.
```PowerShell
Remove-AzureRmResourceGroup -Name $ResourceGroupName
```


Once you have a development environment set up, dive right in to the first [Getting Started](getting-started/README.md) lab.

# Avanade DevOps Hands-On Labs
The labs can be completed using an Azure Virtual Machine as development environment. This not only keeps you from having to make changes to your local environment, but it gives you additional experience using Azure and PowerShell. The [Prerequisites](azure-rm/README.md) instructions help you to set up this environment.

## Course Labs
The course contains the following labs:

| Lab | Effort |
| :-------- |:--------------------------:|
| [Prerequisites - Set up development environment](azure-rm/README.md) | 30 min |
| [Lab 1 - Pipelines as code with K8s and Terraform](https://dev.azure.com/thx1139/_git/workshop1?path=%2FREADME.md) | 60 min |
| [Lab 2 - UI Testing with Selenium and Azure DevOps](ui-testing/README.md) | 45 min |
| [Lab 3 - Static code analysis with SonarQube](sonarqube/README.md) | 45 min |
| [Lab 4 - Feature Toggles](feature-flag/README.md) | 45 min |
| [Lab 5 - Working with Azure Security Scanner](secure-devops-kit-adoscanner/README.md) | 45 min |
| [Lab 6 - Validating the release with automated Smoke Testing](smoke-testing/README.md) | 45 min |
| [Lab 7 - *(Optional)* - Feature branching and branch protection](feature-branching/README.md) | 45 min |
266 changes: 266 additions & 0 deletions azure-devops-project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
# Continuous Integration with Azure DevOps

In this lab, we setup our DevOps Project in Azure to create our CI/CD pipeline. This will provide us with a standard code base to work with. We will also generate a YAML file from the existing pipeline, so we can work with Pipeline as Code in future labs. We will use the existing Build steps as a template and expand the coded pipeline with a Deploy stage.

Based on the following tutorials:
- [Azure Devops Project ASP.NET Core](https://docs.microsoft.com/en-us/azure/devops-project/azure-devops-project-aspnet-core)
- [Adding Continuous Delivery to the YAML definition](https://www.azuredevopslabs.com/labs/azuredevops/yaml/#task-4-adding-continuous-delivery-to-the-yaml-definition)

## Prerequisites

- Complete the [Prerequisites](prerequisites.md) lab.

## Tasks

### Setting up the code repository on your development machine and Create Azure Storage Account.

1. Go to your Azure Portal and create a new DevOps Project. Make sure it meets the following demands:
- .NET Runtime
- ASP.NET Core application
- Kubernetes Service
- Linked to your existing Azure DevOps account

1. When the Azure resources are created, clone your code repository to your development environment using:
- Open file explorer and go to a folder where you want to store the project files. In the address bar type PowerShell and press enter. A new PowerShell window will open with his location inside the folder of your choice.
- Run the next PowerShell command to clone the repository locally:
`git clone <url.to.your.project>`

1. Create an Azure Storage account which will be used to store the Terraform state.
- In your browser, go to your Azure Portal and create a new Storage Account. Make sure it meets the following demands:
- Resource group: `<Name of the resource group that you just created with the Azure DevOps project>`
- Storage account name: `devopsholstorage`
- Location: (Europe) West Europe
- Leave everything else by default settings

1. Create an Azure Container in the just created Azure Storage Account meeting the following demands:
- Name: `terraform-state`
- Public access level: `Private (no anonymous acces)`

### Add Terraform templates to your repository
1. In the root folder of your repository, create a new folder called `TerraformTemplates`. Because you can't add an empty folder to git, you also need to create a new file. Name this file `main.tf`.
- Make sure that the file `main.tf` contains the following content:
```
provider "azurerm" {
version = "~>1.5"
}

terraform {
backend "azurerm" {}
}
```
- Create a new file `k8s.tf` and add the following content:
```
resource "azurerm_resource_group" "k8s" {
name = var.resource_group_name
location = var.location
}

resource "random_id" "log_analytics_workspace_name_suffix" {
byte_length = 8
}

resource "azurerm_log_analytics_workspace" "test" {
# The WorkSpace name has to be unique across the whole of azure, not just the current subscription/tenant.
name = "${var.log_analytics_workspace_name}-${random_id.log_analytics_workspace_name_suffix.dec}"
location = var.log_analytics_workspace_location
resource_group_name = azurerm_resource_group.k8s.name
sku = var.log_analytics_workspace_sku
}

resource "azurerm_log_analytics_solution" "test" {
solution_name = "ContainerInsights"
location = azurerm_log_analytics_workspace.test.location
resource_group_name = azurerm_resource_group.k8s.name
workspace_resource_id = azurerm_log_analytics_workspace.test.id
workspace_name = azurerm_log_analytics_workspace.test.name

plan {
publisher = "Microsoft"
product = "OMSGallery/ContainerInsights"
}
}

resource "azurerm_kubernetes_cluster" "k8s" {
name = var.cluster_name
location = azurerm_resource_group.k8s.location
resource_group_name = azurerm_resource_group.k8s.name
dns_prefix = var.dns_prefix

linux_profile {
admin_username = "azureuser"

ssh_key {
key_data = var.ssh_public_key
}
}

default_node_pool {
name = "agentpool"
node_count = var.agent_count
vm_size = "Standard_DS1_v2"
}

service_principal {
client_id = var.client_id
client_secret = var.client_secret
}

addon_profile {
oms_agent {
enabled = true
log_analytics_workspace_id = azurerm_log_analytics_workspace.test.id
}
}

tags = {
Environment = "Development"
}
}
```
- Create a new file `variables.tf` and add the following content:
```
variable "client_id" {}
variable "client_secret" {}

variable "agent_count" {
default = 1
}

variable "ssh_public_key" {
default = "~/.ssh/id_rsa.pub"
}

variable "dns_prefix" {
default = "devopsholk8s"
}

variable cluster_name {
default = "devopsholk8s"
}

variable resource_group_name {
default = "devopsholk8s-rg"
}

variable location {
default = "West Europe"
}

variable log_analytics_workspace_name {
default = "testLogAnalyticsWorkspaceName"
}

variable log_analytics_workspace_location {
default = "westeurope"
}

variable log_analytics_workspace_sku {
default = "PerGB2018"
}
```
**!Be aware!** Change the value of the variable `resource_group_name` to the name of your Resource Group.

- Create a new file `output.tf` and add the following content:
```
output "client_key" {
value = azurerm_kubernetes_cluster.k8s.kube_config.0.client_key
}

output "client_certificate" {
value = azurerm_kubernetes_cluster.k8s.kube_config.0.client_certificate
}

output "cluster_ca_certificate" {
value = azurerm_kubernetes_cluster.k8s.kube_config.0.cluster_ca_certificate
}

output "cluster_username" {
value = azurerm_kubernetes_cluster.k8s.kube_config.0.username
}

output "cluster_password" {
value = azurerm_kubernetes_cluster.k8s.kube_config.0.password
}

output "kube_config" {
value = azurerm_kubernetes_cluster.k8s.kube_config_raw
}

output "host" {
value = azurerm_kubernetes_cluster.k8s.kube_config.0.host
}
```

- Save all changes, commit and push them to your repository.


### Set up the Pipeline as Code

1. In the root folder of your repository, create a new file called `azure-pipelines.yaml`

1. In your browser, go to Azure DevOps Pipelines, Open the Build pipelines and Edit the existing build pipeline:
- Add Terraform Init step by clicking on the **+** sign you see behind Agent job 1. Here you can search for Terraform.
- Terraform is by default not installed in your DevOps project. So you should click on Add Terraform, you will be redirected to the Market Place. Follow the steps to install Terraform and when you are finished you can close the window.

- After installing Terraform, you should see the following search results:
![](../images/pipelines-terraform-install.png)

- Add a Terraform step between `helm package` and `Publish Artifacts: drop` with the following configuration:
- Name: `Terraform: init`
- Command: `init`
- Configuration directory: `TerraformTemplates`
- Azure subscription: `<your azure subscription>`
- Resource group: `<the resource group create by the DevOps project>`
- Storage account: `devopsholstorage`
- Container: `terraform-state`
- Key: `<Can be found in the Azure Storage Account --> Settings --> Access keys>`

- Add a Terraform step after the previous created Terraform step with the following configuration:
- Name: `Terraform: validate`
- Command: `validate`
- Configuration directory: `TerraformTemplates`

- Modify the copy ARM templates step, because we are going to work with Terraform. Make the properties has the followings values:
- Display name: `Copy Terraform templates`
- Source Folder: `TerraformTemplates`
- Contents: `*.tf`
- Target Folder: `$(Build.ArtifactStagingDirectory)/TerraformTemplates`

- Go to Triggers and disable continuous integration:
![](../images/pipelines-disable-ci.png)

- Save the pipeline changes, do not queue

- Select the Agent Job and click 'View YAML':
![](../images/pipelines-view-yaml.png)

- Select all text from the YAML view and copy it

1. Paste all the contents into your `azure-pipelines.yaml` file

1. Save all changes and commit + push them to your repository

### Set up a pipeline in Azure Devops using the YAML file

1. Go to Azure DevOps Pipelines and click 'New Pipeline'

1. Create the new pipeline with the following settings:
- Azure Repos Git (YAML)
- Choose your git repository
- Existing Azure Pipelines YAML file
- Choose the YAML file from your repository

1. Add a new variable BuildConfiguration
- By adding the following yaml code on top:
```
variables:
configuration: release
```

1. Click Run to finalize the setup and wait for the build to complete

## Next steps
Return to [the lab index](../README.md) and continue with the next lab.

##TODO:
- secrets uit de variables halen en als variabelen in pipeline
Loading