Skip to content

Instantly share code, notes, and snippets.

View oliverlabs's full-sized avatar
💭
Focus.

Oliver Gulich oliverlabs

💭
Focus.
View GitHub Profile
@oliverlabs
oliverlabs / azure-pipelines.yml
Created October 13, 2022 15:21
Azure DevOps Bicep Deploy Starter Pipeline
trigger:
- main
name: Deploy Bicep files
variables:
vmImageName: 'ubuntu-latest'
azureServiceConnection: 'myServiceConnection'
resourceGroupName: 'Bicep'
@oliverlabs
oliverlabs / deploy.yml
Last active October 20, 2022 13:41
GitHub Actions Simple Bicep Azure Deploy Pipeline
on: [push]
name: Azure ARM
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# Checkout code
- uses: actions/checkout@main
# Log into Azure
@oliverlabs
oliverlabs / AzFeatureCheck.ps
Created November 24, 2022 17:09
Check if an Azure Feature is registered for a subscription
Write-Output "Verifying required Resource Providers Features are registered"
$featureName='EnableOIDCIssuerPreview'
$aksfeature = az feature list --query "[?contains(name, '$featureName')]" -o json
Write-Output "-- $featureName"
$feature = $aksfeature | Convertfrom-Json
$feature.properties.state
if ($feature.properties.state -ne 'Registered') {
Write-Output $feature
Write-Error "$featureName NOT registered"
}
@oliverlabs
oliverlabs / json-query.sh
Created November 25, 2022 15:20
Register an Azure Preview Feature Using Az CLI
#!/bin/bash
features=($(az feature list -o table | grep 'AKS-AzureDefender\|OIDC' | xargs -L1 bash -c 'echo $0' | cut -d '/' -f2))
for feature in "${features[@]}"; do
j=$(az feature show --name ${feature} --namespace 'microsoft.ContainerService' | jq)
echo $j | jq
done
@oliverlabs
oliverlabs / json-query-2
Created November 25, 2022 15:21
Register an Azure Subscription Preview Feature using jq and Azure CLI
#!/bin/bash
feature=`az feature list -o json | jq -c 'map(select(.name | contains("OIDC")))' | jq -r '.[].name'`
echo "$feature"
namespace=`echo $feature | cut -d'/' -f1`
name=`echo $feature | cut -d'/' -f2`
@oliverlabs
oliverlabs / sp.azcli
Last active March 10, 2023 09:25
Create a Service Principal in Bash using Azure CLI
# export MSYS_NO_PATHCONV=1
# Replace <subscription_id> with your Subscription ID.
# You can replace the <service-principal-name> with a custom name for your environment or omit the parameter entirely.
# If you omit the parameter, the service principal name is generated based on the current date and time.
# FOR AN OWNER ROLE:
# az ad sp create-for-rbac --scopes "/subscriptions/<subscription_id>" --role "Owner" --name <service_principal_name>
# FOR A CONTRIBUTOR ROLE:
az ad sp create-for-rbac --name <service_principal_name> --role Contributor --scopes /subscriptions/<subscription_id>
@oliverlabs
oliverlabs / main.bicep
Created December 14, 2022 11:56
Create an array of subnets on an existing VNet using Bicep
// var addressSpace = [
// '10.1.0.0/16'
// ]
var subnets = [
{
name: 'api'
subnetPrefix: '10.1.66.0/24'
}
{
@oliverlabs
oliverlabs / workflow.yml
Created December 14, 2022 17:06
Hello World GitHub Actions Workflow Pipeline
name: deploy-toy-website
on: [workflow_dispatch]
jobs:
say-hello:
runs-on: ubuntu-latest
steps:
- name: Say hello
run: echo "Hello, World!"
@oliverlabs
oliverlabs / aks-start-stop.ps1
Created February 15, 2023 10:44
AKS Start Stop PowerShell Script
Param
(
[Parameter (Mandatory=$true)]
[string]$AKSResourceGroup,
[Parameter (Mandatory=$true)]
[string]$AKSName,
[Parameter (Mandatory=$true)]
[string]$subscriptionID,
[Parameter (Mandatory=$true,HelpMessage="start or stop")]
[string]$Action
@oliverlabs
oliverlabs / RemoveOldAzModuleVersions.ps1
Created February 27, 2023 16:03
A tiny script to remove older versions of the Az module in PowerShell
foreach ($module in (Get-Module -ListAvailable Az*).Name |Get-Unique) {
if ((Get-Module -ListAvailable $module).Count -gt 1) {
$Latest_Version = (Get-Module -ListAvailable $module | select Version | Sort-Object Version)[-1]
write-host "The latest $module version is $Latest_Version"
Get-Module -ListAvailable $module | Where-Object {$_.Version -ne $Latest_Version.Version} | foreach {Uninstall-Module -Name $_.Name -RequiredVersion $_.Version -verbose}
}
else {
Write-Output "Only one module version exists for the $module"
}
}