Skip to content

Instantly share code, notes, and snippets.

from hashlib import sha1
import json
def generate_cache_key(start_url, role_name, account_id):
args = {
'startUrl': start_url,
'roleName': role_name,
'accountId': account_id,
}
# Lots of other resources are created and all of that stuff works so I'm just skipping the not-so-relevant parts.
resource "aws_route_table" "private" {
for_each = toset(var.public_subnets)
vpc_id = aws_vpc.main.id
route {
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.natgw[each.key].id #this ressource exists andd is based on a foreach of the public_subnets variable, I just omitted it from the example here.
}
# Change line 138/139 from
# except AuthenticationError:
# raise AnsibleError('Invalid credentials provided.')
#to:
except AuthenticationError as e:
raise AnsibleError(str(e))
#This will surface the actual exception from azure, instead of just printing a generic one.
#It might be possible to use `(e)` instead of `(str(e))` depending on what param AnsibleError takes. It might provide more info
@trondhindenes
trondhindenes / doit.py
Last active March 29, 2019 19:43
testing out the aws-cdk for Python
#Install pips:
#aws-cdk-cdk
#aws-cdk-aws-ec2
import json
from aws_cdk import cdk
from aws_cdk import aws_ec2
app = cdk.App()
stack = cdk.Stack(app, 'MyStack')
@trondhindenes
trondhindenes / .gitlab-ci.yml
Last active April 17, 2024 10:07
Run KinD (Kubernetes in Docker) as part of Gitlab CI job
#Spin up Kubernetes control plane as part of before_script, and destroys it using after_script
#Some custom logic to get to the right ip address
#Requres the gitlab docker runner, with "pass-thru" to the host docker socket.
stages:
- test
image: python:3.6.6 #the docker image you run in needs Docker installed, and access to the host docker socket.
test_integration_k8s:
tags:
@trondhindenes
trondhindenes / main.py
Created December 28, 2018 19:58
Flask-Injector example
import boto3
from bloop import BaseModel, Column, String, Engine
from flask import Flask
from flask_injector import FlaskInjector, singleton
from flask_restful import Api, Resource
from injector import inject, provider
import random
import string
from bloop_local import patched_local_bloop_engine
- name: Replay GETs against staging #arbitrary name
methods: #only replay these requests
- get
paths: #replay these paths (use wildcard-notation because I suck at regex)
- "/api/1/*"
host_names: #The hostnames to match on
- api.domain.com
strip_headers: #remove these headers before replaying the request (list of strings). You can use wildcards such as
- "X-*" #strip away all X-type headers
- "User-Agent" #Strip away this and add a new one down below
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: config-ansiblejobservicefrontend-v{{ major_version }}-{{ environment }}-{{ environmentid }}-httpsecure
namespace: sre
annotations:
traefik.frontend.passHostHeader: "true"
labels:
expose: internal-httpsecure
@trondhindenes
trondhindenes / traefik_daemonset.yml
Created April 29, 2018 10:00
traefik_daemonset_example
---
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: traefik-ingress-controller-internal-httpsecure-{{ environment }}
namespace: networking
labels:
app: traefik-ingress-lb-internal-httpsecure
environment: "{{ environment }}"
environmentid: "{{ environmentid }}"
Traceback (most recent call last):
File "/home/trond/apps/pycharm-community-2018.1.1/helpers/pydev/pydevd.py", line 1664, in <module>
main()
File "/home/trond/apps/pycharm-community-2018.1.1/helpers/pydev/pydevd.py", line 1658, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/home/trond/apps/pycharm-community-2018.1.1/helpers/pydev/pydevd.py", line 1068, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/home/trond/apps/pycharm-community-2018.1.1/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/trond/Documents/projects-rikstv/SRE/RiksTV.Utils.ServiceOwnership/runserver.py", line 1, in <module>