Skip to content

Instantly share code, notes, and snippets.

View ehrnst's full-sized avatar

Martin Ehrnst ehrnst

View GitHub Profile
@ehrnst
ehrnst / canary-deployment.yaml
Created January 28, 2025 18:59
Kubernetes canary deployments with NGINX. No Flagger or Argo
apiVersion: apps/v1
kind: Deployment
metadata:
name: echo-canary
spec:
replicas: 1
selector:
matchLabels:
app: echo
version: canary
@ehrnst
ehrnst / prometheusRecordingRules.bicep
Created November 4, 2024 15:42
Prometheus recording rules for Azure managed Prometheus
param devPrometheusWorkspaceId string
param prodPrometheusWorkspaceId string
param resourceLocation string = resourceGroup().location
param tags object
var nodeRecordingRuleGroupDescription = 'Node Exporter recording rules for Prometheus '
var version = '1.0'
resource nodeRecordingRuleGroupDev 'Microsoft.AlertsManagement/prometheusRuleGroups@2023-03-01' = {
name: 'NodeRecordingRulesRuleGroup-linux-dev'
@ehrnst
ehrnst / migrate-devops-repo.ps1
Created February 16, 2024 10:57
PowerShell script using GH CLI to migrate Azure DevOps repositories to GitHub
param(
[Parameter(HelpMessage="The Azure DevOps organization.")]
[string]$adoOrg = "Adatum",
[Parameter(Mandatory=$true, HelpMessage="The Azure DevOps team project.")]
[string]$adoTeamProject,
[Parameter(Mandatory=$true, HelpMessage="The Azure DevOps repository.")]
[string]$adoRepo,
@ehrnst
ehrnst / appRegistrationSignIns.ps1
Last active October 8, 2024 07:54
Get sign in information for app registrations and service principals through EntraID/Log Analytics
<#
.SYNOPSIS
This script retrieves Azure Active Directory (AD) applications with expired secrets and checks their sign-in logs.
.DESCRIPTION
The script first retrieves all Azure AD applications using the Get-AzADApplication cmdlet. It then filters these applications to only include those where the password credential has expired more than 30 days ago and where there is only one password credential.
For each of these applications, the script retrieves the AppId and constructs three queries to check the sign-in logs for the last 30 days. The queries are for service principal sign-ins, non-interactive user sign-ins, and interactive sign-ins.
The script then executes these queries using the Invoke-AzOperationalInsightsQuery cmdlet and stores the results in three separate variables: $servicePrincipalSignins, $nonInteractiveSignins, and $interactiveSignins.
Finally, the script outputs the results of these queries.
@ehrnst
ehrnst / azopenai-slack.ps1
Last active April 24, 2023 12:36
Azure OpenAI Slack summary using PowerShell
# slack test
$slackKey = Get-AzKeyVaultsecret -VaultName "" -Name "" -AsPlainText
$azOpenAiKey = Get-AzKeyVaultsecret -VaultName "" -Name "" -AsPlainText
$slackChannelId = ""
$slackThreadId = ""
$openAiUrl = ""
$slackUrl = "https://slack.com/api/conversations.replies?channel=$slackChannelId&ts=$slackThreadId&pretty=1"
$slackHeaders= @{
"Authorization" = "Bearer $slackKey"
@ehrnst
ehrnst / create-adappgithub.ps1
Created August 24, 2022 11:58
Adding Azure AD and github federated credentials
# creates an appregistration in Azure AD and connects it with a github repo
# use as an example only
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]
$gitHubRepoName,
[Parameter(Mandatory)]
[string]
@ehrnst
ehrnst / containertest.bicep
Created June 16, 2022 07:02
bicep alter params to sub modules
param storageAccountName string
resource container 'Microsoft.Storage/storageAccounts/blobServices/containers@2021-09-01' = {
name: '${storageAccountName}/default/mycontainer'
}
@ehrnst
ehrnst / get-resource-changes-from-rg-with-tag.kql
Created March 14, 2022 14:19
Azure resource graph resource changes
// get latest resource changes based on resource group tag
resourcechanges
| join kind= inner (
resourcecontainers
| where type =~ 'microsoft.resources/subscriptions/resourcegroups'
| where isnotempty(tags)
| where tags['key'] =~ 'value'
| project subscriptionId, resourceGroup)
on subscriptionId, resourceGroup
| extend changeTime = todatetime(properties.changeAttributes.timestamp),
@ehrnst
ehrnst / diff.ps1
Created February 7, 2022 09:00
azure pipeline with bicep files push to acr. uses git diff to only push modified modules
$version = get-date -Format yyyy-MM-dd
$commit = "$ENV:BUILD_SOURCEVERSION"
# get the latest files changed
$files = $(git diff HEAD HEAD~ --name-only -- *.bicep modules/)
if ($files.count -ge 1) {
# copy files to staging
copy-item $files -Destination $ENV:BUILD_ARTIFACTSTAGINGDIRECTORY
# set a variable and build number
@ehrnst
ehrnst / azcopy-move.ps1
Created January 25, 2022 15:03
AzCopy to move files in directory structure in Azure blob storage
## connect to storage using SAS
$storageName = ""
$sasToken = ""
$container = ""
$ctx = New-AzureStorageContext -StorageAccountName $storageName -SasToken $sasToken
# get all the blobs
$blobs = Get-AzureStorageBlob -Container $container -Context $ctx