Skip to content

Instantly share code, notes, and snippets.

@alanplatt
alanplatt / .terraform-docs.yml
Created June 29, 2023 12:22
terraform-docs config
---
formatter: "markdown table"
version: ">= 0.13"
header-from: "README.header.md"
content: ""
output:
@alanplatt
alanplatt / docker-compose.yaml
Last active March 22, 2023 17:53
Docker compose terraform, gitlab backend, aws
---
services:
terraform:
image: hashicorp/terraform:1.4.0
working_dir: ${PWD}
entrypoint: ../tf.sh
volumes:
- ${PWD}:/${PWD}
- /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem:/etc/ssl/certs/ca-certificates.crt
environment:
@alanplatt
alanplatt / terraform.tf
Last active February 23, 2023 09:51
gitlab provider setup
provider "gitlab" {
token = var.gitlab_token
base_url = var.gitlab_url
}
@alanplatt
alanplatt / environment
Last active February 23, 2023 09:50
gitlab terraform backend setup
TF_HTTP_ADDRESS=https://gitlab.com/api/v4/projects/4480/terraform/state/${TF_VAR_foo}
TF_HTTP_LOCK_METHOD=POST
TF_HTTP_LOCK_ADDRESS=https://gitlab.com/api/v4/projects/4480/terraform/state/${TF_VAR_foo}/lock
TF_HTTP_UNLOCK_ADDRESS=https://gitlab.com/api/v4/projects/4480/terraform/state/${TF_VAR_foo}/lock
TF_HTTP_UNLOCK_METHOD=DELETE
@alanplatt
alanplatt / gist:93db87434fd6c83aea9e363d1f46d3fe
Created February 13, 2023 15:45
Run commands from a container.
# Mount the current directory as the working directory in the contianer (great for linting etc)
alias docker-run='docker run -it --workdir ${PWD} -v ${PWD}:${PWD}'
# Generate a Dockerfile from an image
alias dfimage="docker-run -v /var/run/docker.sock:/var/run/docker.sock --rm alpine/dfimage"
# Python linting
alias flake8="docker-run python:3-alpine flake8"
@alanplatt
alanplatt / gist:1b78f0623fb5c3128700d7bc177840ca
Last active February 13, 2023 15:40
Git function to delete all branches merged to default branch
_gbclean () {
default_branch=$( git remote show origin | sed -n '/HEAD branch/s/.*: //p')
git checkout "${default_branch}" && git pull && \
for branch in $(git branch -l | grep -v -e "${default_branch}" ); do
git branch -d $branch
done
}
alias gbclean='_gbclean'
#!/usr/bin/env python
# This is a trick, to output the bash commands we need to run in shell, and just execute this script inside an eval within our shell, so it imports what we need
# Possibly tie this in with https://gist.github.com/mbainter/b38a4cb411c0b5c1bae6 for MFA support
# Will need to durably store MFA access tokens, possibly in some other env vars
# Could also store all different keys/info in different vars, to reuse as needed (lots of env vars though, file may be better)
import os
import sys
import getpass