Skip to content

Instantly share code, notes, and snippets.

View kasunkv's full-sized avatar
💭
I may be slow to respond.

Kasun Kodagoda kasunkv

💭
I may be slow to respond.
View GitHub Profile
@kasunkv
kasunkv / create-policy.ps1
Created March 10, 2019 07:28
Create Azure Policy Assignment using Azure PowerShell
# Login to Azure Subscription
Login-AzureRmAccount
# Get a reference to the resource group
$rg = Get-AzureRmResourceGroup -Name "az-policy-rg"
# Get a referecen to the Azure Policy Definition
$policyDef = Get-AzureRmPolicyDefinition | Where-Object { $_.Properties.DisplayName -eq "Audit VMs that do not use managed disks" }
# Create the new Policy Assignment for the Resource Group
@kasunkv
kasunkv / create-rg.sh
Created March 6, 2019 15:49
Login and Create Resource Group on Azure.
# Login to Azure using the CLI
az login --use-device-code
# Create the resource group for the AKS cluster
az group create --name "aks-demo-rg" --location "southeastasia"
@kasunkv
kasunkv / install.sh
Created March 6, 2019 15:43
Install kubectl using Azure CLI
# Install kubectl using Azure CLI
az aks install-cli
@kasunkv
kasunkv / azure-pipelines.yml
Created March 5, 2019 17:33
azure-pipelines.yml
trigger:
branches:
include:
- master
- refs/tags/*
pr:
- master
pool:
vmImage: 'VS2017-Win2016'
@kasunkv
kasunkv / add-update-tags.sh
Created January 4, 2019 13:53
Add/Update tags using Azure CLI
result=$(az resource show --resource-group "Tags-PRD-Web" --name kvktagsprdweb --resource-type "Microsoft.Web/sites" --query tags)
tags=$(echo $result | tr -d '"{},' | sed 's/: /=/g')
az resource tag --tags $tags Owner="Kasun Kodagoda" --resource-group "Tags-PRD-Web" --name kvktagsprdweb --resource-type "Microsoft.Web/sites"
@kasunkv
kasunkv / tags-other-resource.ps1
Created January 4, 2019 12:32
Add Tags to Azure Resource using Azure CLI
# Add tag to any other supported Azure Resource
az resource tag --tags Owner="Kasun Kodagoda" --resource-group "Tags-PRD-Web" --name kvktagsprdweb --resource-type "Microsoft.Web/sites"
@kasunkv
kasunkv / add-tag.ps1
Last active January 4, 2019 12:32
Add Tags using Azure CLI
# Add tag to Azure Resource Group
az group update --name "Tags-PRD-Web" --set tags.Department=Operations
@kasunkv
kasunkv / add-update-tags.ps1
Created January 4, 2019 08:29
Add/Update Tags for Other Azure Resources
$res = Get-AzureRmResource -ResourceName "kvktagsweb" -ResourceGroupName "Tags-DEV-Web"
$res.Tags.Add("App", "WebApp") # This will only work if the resource already has tags.
Set-AzureRmResource -Tag $res.Tags -ResourceId $res.ResourceId -Force
@kasunkv
kasunkv / update-tags.ps1
Created January 4, 2019 06:08
Update/Add New Azure Resource Tags.
$tags = (Get-AzureRmResourceGroup -Name "Tags-DEV-Web").Tags
$tags.Add("Owner", "John Smith")
Set-AzureRmResourceGroup -Tag $tags -Name "Tags-DEV-Web"
@kasunkv
kasunkv / create-tag.ps1
Created January 4, 2019 06:02
Create Azure Resource Tag
Set-AzureRmResourceGroup -Name "Tags-DEV-Web" -Tag @{ Department = "Development" }