Skip to content

Instantly share code, notes, and snippets.

View YakDriver's full-sized avatar
🕳️
🌑

Dirk Avery YakDriver

🕳️
🌑
View GitHub Profile
@YakDriver
YakDriver / am_i_admin.ps1
Created March 23, 2018 11:15
Is PowerShell script running as administrator? Find out from inside the script.
# Get the ID and security principal of the current user account
$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
# Get the security principal for the Administrator role
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
# Check to see if we are currently running "as Administrator"
if ($myWindowsPrincipal.IsInRole($adminRole))
{
2018-03-22T15:09:41.743Z [DEBUG] plugin.terraform: file-provisioner (internal) 2018/03/22 15:09:41 Uploading file to 'C:\scripts\check_build.ps1'
2018-03-22T15:09:42.378Z [DEBUG] plugin.terraform: remote-exec-provisioner (internal) 2018/03/22 15:09:42 connecting to remote shell using WinRM
2018-03-22T15:09:42.408Z [DEBUG] plugin.terraform: remote-exec-provisioner (internal) 2018/03/22 15:09:42 Uploading file to 'C:/Temp/terraform_1217694552.cmd'
2018-03-22T15:09:43.054Z [DEBUG] plugin.terraform: remote-exec-provisioner (internal) 2018/03/22 15:09:43 starting remote command: C:/Temp/terraform_1217694552.cmd
2018-03-22T15:10:52.390Z [DEBUG] plugin.terraform: remote-exec-provisioner (internal) 2018/03/22 15:10:52 Uploading file to 'C:/Temp/terraform_1217694552.cmd'
2018/03/22 15:10:53 [DEBUG] plugin: waiting for all plugin processes to complete...
2018-03-22T15:10:53.201Z [DEBUG] plugin.terraform: remote-exec-provisioner (internal) 2018/03/22 15:10:53 [ERR] plugin: plugin server: accept unix /tmp/plugin522209802
@YakDriver
YakDriver / userdata.ps1
Created March 16, 2018 13:27
Userdata PowerShell to set Admin Password
<powershell>
$Admin = [adsi]("WinNT://./Administrator, user")
$Admin.psbase.invoke("SetPassword", "<password>")
</powershell>
@YakDriver
YakDriver / running-terraform-providers-acceptance-test.txt
Last active March 7, 2018 00:13
Running acceptance tests for Terraform Providers in go
# Hashicorp documentation is a bit out of date so it took a minute to figure this out...
# 1. Install go
https://golang.org/dl/
# 2. Make a go workspace
$ mkdir ~/go # or wherever you want
$ export GOPATH=~/go # could add to .bash_profile
$ export PATH=$GOPATH:$PATH
@YakDriver
YakDriver / building.misc
Created March 2, 2018 02:59
adventures in RPM builds
pip install --index-url="https://pypi.org/simple" --upgrade virtualenv
sudo yum groupinstall -y development
sudo yum install -y zlib-dev openssl-devel sqlite-devel bzip2-devel
sudo yum install xz-libs
wget http://www.python.org/ftp/python/2.7.14/Python-2.7.14.tar.xz
xz -d Python-2.7.14.tar.xz
tar -xvf Python-2.7.14.tar
@YakDriver
YakDriver / nametag.sh
Created March 1, 2018 14:56
Set the name tag of an AWS instance from the AWS instance (e.g., in userdata)
# terraform locals (in a .tf file)
locals {
name_prefix = "terrafirm"
full_build_id = format("notcb:%s", uuid()) #128-bit rfc 4122 v4 UUID
build_id = "${substr(element(split(":",local.full_build_id),1), 0, 8)}${substr(element(split(":",local.full_build_id),1), 9, 4)}"
resource_name = "${local.name_prefix}-${local.build_id}"
}
# terraform template declaration (in a .tf file)
data "template_file" "lx_userdata" {
@YakDriver
YakDriver / utc.sh
Last active March 1, 2018 14:47
Linux/bash to display date in UTC format
#!/bin/bash
# Many things want UTC time as input, so here it is. As 14 days ago. Like for a query to AWS spot instance history:
# aws ec2 describe-spot-price-history --instance-types t2.micro --start-time $(date -v-14d -u '+%FT%TZ') --product-description "Linux/UNIX"
#
# Output (of command below, not the aws cli command):
# 2018-02-13T15:24:46Z
#
date -v-14d -u '+%FT%TZ'
@YakDriver
YakDriver / node_from_uuid.sh
Created February 22, 2018 21:55
Extract node portion of UUID, bash
$uuid = 'some-name-or-urn:8754258d-506d-e094-d51d-e0a0d891fe08' #16 octets, 10-15 are the node
$node = $(echo $uuid | cut -d':' -f 2 | cut -d'-' -f 5)
echo $node
@YakDriver
YakDriver / gen_key.sh
Last active February 22, 2018 18:59
Generate keys
#!/bin/bash
org=$1
name=${2:-$USER}
echo "Usage: $0 [organization] [name]"
create_date=$(date +'%Y%m%d')
if [ -n "${org}" ] ; then org="$org " ; fi
@YakDriver
YakDriver / sg.sh
Created February 22, 2018 14:19
Manage security groups (shell script) from AWS CLI
#!/bin/bash
# Errors are thrown if Terraform is given the name of an existing security group.
# One solution is to find the existing security group and delete it. (That will fail if any instances are associated.)
# This installs jq, finds security group id, deletes security group.
#
security_group_name=your_sg
# 1. Install jq
curl -L "https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64" -o jq.dms && chmod +x jq.dms