Skip to content

Instantly share code, notes, and snippets.

@orlandothoeny
orlandothoeny / migrate-terraform-module-state.sh
Last active March 26, 2024 14:03
Script that moves the Terraform remote state of a root module as a child module into another root module. Blog Post: https://thoeny.dev/how-to-move-terraform-root-module-state-inside-other-root-module
#!/usr/bin/env bash
set -euo pipefail
# Support aborting via SIGINT, without this bash will not exit the for loop until it's finished
trap 'exit 0' INT
# Usage example:
# bash migrate-state.sh '/home/myuser/terraform/destination-module' '/home/myuser/terraform/source-module' 'module.source' 'config/dev_backend.tfvars' 'config/dev_backend.tfvars'
# Arguments:
# $1 - destinationModuleDirectory: The directory in which the module resides where state should be moved to
@dan2k3k4
dan2k3k4 / docker-compose.yml
Last active July 27, 2022 21:38 — forked from seanhandley/docker-compose.yml
Docker For macOS Catalina with Native NFS. You need to ensure `env_vars.sh` is run for your project and to update `/myapp` and `me` to be related to your app and macOS username.
version: '2'
services:
api:
volumes:
- "nfsmount:${CONTAINER_DIR}"
volumes:
nfsmount:
driver: local
driver_opts:
@daggerhart
daggerhart / MODULENAME.install.php
Last active September 5, 2020 05:23
Drupal 8 file field to media entities simple migration. Does not move files in filesystem, just creates new media entities.
<?php
/**
* Create media entities from existing file fields.
*
* @link https://chromatichq.com/blog/migrating-drupal-file-fields-media-entities-without-migrate-module
*/
function MODULENAME_update_8001() {
// Nodes types that will get media migrated.
$node_types = ['article','event','page','session','sponsor'];
// Map old file fields => new media fields.
@PGBI
PGBI / .profile
Last active November 25, 2020 20:43
`vagrant halt all` command to halt all running vagrant VMs
# To be pasted in ~/.profile
vagrant() {
if [[ $@ == "halt all" ]]; then
command vagrant global-status | grep running | colrm 8 | xargs -L 1 -t vagrant halt
else
command vagrant "$@"
fi
}
@pkuczynski
pkuczynski / parse_yaml.sh
Last active April 9, 2024 18:36
Read YAML file from Bash script
#!/bin/sh
parse_yaml() {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}