Skip to content

Instantly share code, notes, and snippets.

View audunsolemdal's full-sized avatar
In the clouds

Audun Solemdal audunsolemdal

In the clouds
View GitHub Profile
@audunsolemdal
audunsolemdal / terraform-module-mover.sh
Last active June 3, 2024 14:04
Terraform - move module contents to root module or to another nested module
#!/bin/bash
# Generates terraform "moved" blocks for files based on terraform state
export OLD_MODULE="old_module_name"
export NEW_MODULE="" #LEAVE EMPTY to move to root module or enter "module.new_module." if you want to move to another module
terraform state list |
grep module.${OLD_MODULE} | cut -d. -f 3- | sed 's/\"/\\\"/g' |
xargs -I {} sh -c 'echo "moved {" && echo " from = module.${OLD_MODULE}.{}" && echo " to = ${NEW_MODULE}{}" && echo "}"' | sed 's/\]/\"]/g' | sed 's/\[/\["/g' | tr -d '\r' > moved-blocks.tf
@audunsolemdal
audunsolemdal / helm_release_issue
Created August 11, 2023 14:05
helm provider issue
Terraform will perform the following actions:
# module.sentry[0].helm_release.sentry will be updated in-place
~ resource "helm_release" "sentry" {
id = "sentry"
~ metadata = [
- {
- app_version = "23.7.1"
- chart = "sentry"
- name = "sentry"
@audunsolemdal
audunsolemdal / Get-AzureUsageCost.ps1
Created February 17, 2022 08:59
PowerShell Script to retrieve Azure Usage and Cost/Pricing through the Usage Details API
# Licensed under the MIT license.
# Copyright (C) 2022 Helsedirektoratet
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
@audunsolemdal
audunsolemdal / KC0302.ps1
Created September 25, 2020 13:29
Evidence for KC0302
Get-Date
Connect-AzAccount -TenantId 3aa4a235-b6e2-48d5-9195-7fcf05b459b0
$appreg = Get-AzADApplication -ObjectId 2325bab4-1ebd-44b9-88fd-c299e97522fc
$appreg | Select-Object ApplicationId, AvailableToOtherTenants
$appreg | Select-Object ReplyUrls -ExpandProperty ReplyUrls
az account set --subscription "S105-Centuries-prod"
Get-Date
@audunsolemdal
audunsolemdal / Connect-AzVM.ps1
Last active May 23, 2020 13:42
Opens up JiT on a VM. You will need to change the -Name parameter for the NetworkAccessPolicy. Originally found as AzureRM module in a Microsoft Github repo I can't seem to find. Modified to my own needs.
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.