Skip to content

Instantly share code, notes, and snippets.

@machv
machv / site-to-site.tf
Last active June 24, 2020 15:33
Terraform script to deploy Site-to-site IPSec demo in Azure
locals {
ike_secret = "tajneheslo"
# Azure site
ip_azure_range = "10.10.0.0/16"
ip_azure_subnet_main = "10.10.0.0/24"
ip_azure_subnet_gw = "10.10.255.240/28"
asn_azure = "65010"
# On-premises site
@machv
machv / README.md
Last active February 23, 2022 15:40
Packer for Debian with Hyper-V "SSH Direct" fixes

Packer template for Debian with "SSH Direct" on Hyper-V

Output of this Packer template is Hyper-V Gen2 VM with Debian 10 that supports direct connection via vsock thus no internet connectivity is needed.

How to build

$key = "$env:USERPROFILE\.ssh\lab01_rsa"
$publicKey = Get-Content "$($key).pub"
function Invoke-AzVMDiskSnapshot {
param(
[Parameter(Mandatory = $true)]
[string]$VMResourceGroupName,
[Parameter(Mandatory = $true)]
[string]$VMName,
[string]$SnapshotsResourceGroupName = $null
[bool]$Shutdown = $true
)

Install

New-AzRoleDefinition -InputFile rbac.json

Root management group

If you want to link Custom role to the top most root management group (that is always available), use an ID that corresponds with AAD Tenant ID GUID.

FYI

@machv
machv / README.md
Last active January 19, 2021 16:53

Azure Automation Account / Monthly deployment schedules

Configuration options

To set how far in the future (in months) to prepare deployment rings set variable $monthsToProvision

To set deployment rings populate tags to $deploymentRings hash table in format

<TagName> = <Time-Span for delayed deployment>

@machv
machv / README.md
Last active July 31, 2020 13:35
Synchronize Private DNS Zones in Azure between each other

Synchronize Azure Private DNS Zone records

Prerequisities

Make sure that in addition to Az PowerShell module you also have Az.PrivateDns module installed.

About

Function Sync-DnsZone synchronizes resource records from source DNS zone to destination DNS zone, if you want to achive two-way sync you need to execute the same function twice with switched source and destination.

Customization

@machv
machv / temp.ps1
Last active August 6, 2020 09:18
temp
#region Functions
function ConvertFrom-Timestamp {
param(
[Parameter(Mandatory = $true)]
[int]$Timestamp
)
$utc = (Get-Date 01.01.1970) + ([System.TimeSpan]::fromseconds($Timestamp))
$datetime = [datetime]::SpecifyKind($utc, 'Utc').ToLocalTime()
@machv
machv / example.gif
Last active August 24, 2020 15:27
Remove App permission to Azure AD Enterprise Application
example.gif
@machv
machv / sync.ps1
Created September 1, 2020 15:09
Synchronize Routing Table with Azure Service Tag Listing
#region Azure Automation bootstrap
try
{
$servicePrincipalConnection = Get-AutomationConnection -Name "AzureRunAsConnection"
"Logging in to Azure..."
Connect-AzAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
@machv
machv / Sync-RouteTableDns.ps1
Created September 3, 2020 17:30
Azure Automation to Sync DNS resolution to Route Table
Param(
[Parameter (Mandatory = $true)]
[sring]$DnsName,
[string]$RouteName
)
if($RouteName -eq "") {
$RouteName = $DnsName
}