Skip to content

Instantly share code, notes, and snippets.

View kszarek's full-sized avatar

Krzysztof Szarek kszarek

View GitHub Profile
@kszarek
kszarek / condition_iam_policy.tf
Created April 30, 2020 17:07
Data aws_iam_policy_document with conditions
data "aws_iam_policy_document" "manager" {
statement {
sid = "Cache"
actions = [
"s3:ListObjects*",
"s3:GetObject*",
"s3:DeleteObject*",
"s3:PutObject*"
]
resources = ["${module.s3_cache.arn}/*"]
@kszarek
kszarek / golangci-lint
Created January 20, 2020 18:08
golangci-lint
golangci-lint run --disable-all \
--enable=misspell \
--enable=golint \
--enable=govet \
--enable=deadcode \
--enable=goimports \
--enable=errcheck \
--enable=varcheck \
--enable=unparam \
--enable=ineffassign \
@kszarek
kszarek / config.yaml
Created March 28, 2019 12:14
Consul Sidecar
apiVersion: v1
kind: ConfigMap
metadata:
name: generic
data:
AWS_REGION: eu-west-1
ENVIRONMENT: staging
---
apiVersion: v1
kind: ConfigMap
@kszarek
kszarek / gcp-stats.sh
Last active February 18, 2021 03:09
Bash script to get VM count and disk volume sizes from GCP projects
#!/usr/bin/env bash
envs='airhelp-staging airhelp-production ah-test-174206'
get_vm_count(){
ENV_NAME="$1"
count=$(gcloud --project="$ENV_NAME" compute instances list|grep -v NAME -c)
echo "VM count for $ENV_NAME: $count"
}
@kszarek
kszarek / aws-stats.sh
Last active June 19, 2019 15:18
Bash script to get ec2 and ebs count from multiple AWS accounts
#!/usr/bin/env bash
AWS_REGION=eu-west-1
envs='staging development dt-staging dt-production qa accounting team-bravo'
aws() {
docker run --rm -it \
--mount type=bind,source="$HOME"/.aws,destination=/root/.aws,readonly \
--mount type=bind,source="$(pwd)",destination=/data,consistency=cached \
-e AWS_PROFILE \
@kszarek
kszarek / Dockerfile
Created November 8, 2018 16:53
Go application on docker scratch image
# This is the first stage, for building things that will be required by the
# final stage (notably the binary)
FROM golang
# Copy in just the go.mod and go.sum files, and download the dependencies. By
# doing this before copying in the other dependencies, the Docker build cache
# can skip these steps so long as neither of these two files change.
COPY go.mod go.sum ./
RUN go mod download
@kszarek
kszarek / graceful-shutdown-in-aws.tf
Created December 25, 2017 18:06
Terraform - graceful shutdown on AWS
resource "aws_sqs_queue" "graceful_termination_queue" {
name = "graceful_termination_queue"
}
resource "aws_iam_role" "autoscaling_role" {
name = "autoscaling_role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
@kszarek
kszarek / es-shard-allocate.py
Created November 24, 2017 15:35
ElasticSeach: force to allocate a primary shard
#!/usr/bin/env python3
# script will force to allocate unassigned shards in the cluster
# based on: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/cluster-reroute.html
import urllib.request
import json
host = 'http://es-main-master2-gew2-staging'
destination_host = 'es-main-data2-gew2-staging'
shards_uri = ':9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason&format=json'
@kszarek
kszarek / remove-es-node.sh
Created November 10, 2017 08:37
ElasticSearch: Removes all shards from given node's IP
#!/bin/bash
set -e
if [[ $# -ne 1 ]]
then
echo "Removes all shards from given node's IP."
echo
echo "$0 source_node_IP|NONE"
exit 1
fi
@kszarek
kszarek / main.go
Created October 25, 2017 14:02
Read TF comment
func readLines(path string) ([]string, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
var lines []string
scanner := bufio.NewScanner(file)
comment := false