Skip to content

Instantly share code, notes, and snippets.

View lukehoban's full-sized avatar

Luke Hoban lukehoban

View GitHub Profile
@lukehoban
lukehoban / index.ts
Created May 19, 2023 06:42
Pulumi Self-Hosted Cloud - Simple Kubernetes Deployment
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";
import * as command from "@pulumi/command";
class ServiceDeployment extends pulumi.ComponentResource {
internalEndpoint: pulumi.Output<string>;
externalEndpoint?: pulumi.Output<string>;
service: k8s.core.v1.Service;
constructor(name: string, args: { name: string, image: string, replicas?: number, env?: Record<string, pulumi.Input<string>>, ports?: { port: number }[], loadBalancer?: boolean, volumes?: { name: string, mountPath: string, secret: k8s.core.v1.Secret }[] }, opts?: pulumi.ComponentResourceOptions) {
super("selfhosted:ServiceDeployment", name, {}, opts);
@lukehoban
lukehoban / __main__.py
Last active May 19, 2023 05:31
Pulumi without variables
import pulumi
import pulumi_aws as aws
from typing import Optional, Dict, Tuple
import asyncio
all_resources: Dict[Tuple[str, str], pulumi.Resource] = {}
def transform(args: pulumi.ResourceTransformationArgs) -> Optional[pulumi.ResourceTransformationResult]:
all_resources[(args.name, args.type_)] = args.resource
return None # do not actually modify the resource
@lukehoban
lukehoban / lambda_test.go
Created February 25, 2020 06:19
Untyped Lambda Calculus, Chruch Numerals, Y Combinator in Golang
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
type V func(v V) V
@lukehoban
lukehoban / waitForJob.ts
Last active May 17, 2024 16:23
Pulumi program which waits on Jobs during a Kubernetes deployment
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";
import * as k8sOutput from "@pulumi/kubernetes/types/output";
import * as k8sapi from 'kubernetes-client';
const job = new k8s.batch.v1.Job("job", {
spec: {
template: {
spec: {
containers: [{
@lukehoban
lukehoban / index.ts
Created June 20, 2019 00:25
Passing credentials to a Pulumi dynamic provider
import * as splunk from "./splunk"
async function getSecretValue(): Promise<string> {
return "abcd"
}
getSecretValue().then(secret => {
splunk.setAuth(secret);
new splunk.SavedSearch("foo", {});
});
@lukehoban
lukehoban / index.ts
Last active February 24, 2023 15:31
Simple Aurora Serverless + Lambda VPC example with Pulumi
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";
import * as random from "@pulumi/random";
// Construct a VPC
const vpc = new awsx.ec2.Vpc("vpc");
// Create an Aurora Serverless MySQL database
const dbsubnet = new aws.rds.SubnetGroup("dbsubnet", {
import * as awsx from "@pulumi/awsx";
import * as eks from "@pulumi/eks";
import * as k8s from "@pulumi/kubernetes";
// Create an AWS VPC and EKS cluster
const vpc = new awsx.Vpc("vpc", { usePrivateSubnets: false });
const cluster = new eks.Cluster("cluster", {
vpcId: vpc.vpcId,
subnetIds: vpc.subnetIds,
});
@lukehoban
lukehoban / apigatewaydomain.ts
Last active September 25, 2023 07:41
API Gateway Domain Mapping in Pulumi
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// The services we want to host on our domain...
const api1 = new aws.apigateway.x.API("api1", {
routes: [
{method: "GET", path: "/", eventHandler: async(ev) => {
return {
statusCode: 200,
body: JSON.stringify({hello: "world"}),
@lukehoban
lukehoban / thumbnailer.js
Created June 18, 2018 05:40
Serverless + Containers with Pulumi
const cloud = require("@pulumi/cloud-aws");
const aws = require("@pulumi/aws");
// A bucket to store videos and thumbnails.
const bucket = new cloud.Bucket("bucket");
const bucketName = bucket.bucket.id;
// A task which runs a containerized FFMPEG job to extract a thumbnail image.
const ffmpegThumbnailTask = new cloud.Task("ffmpegThumbTask", {
build: "./docker-ffmpeg-thumb",
@lukehoban
lukehoban / helloworld.js
Created June 18, 2018 04:43
A simple Pulumi program
const cloud = require("@pulumi/cloud-aws");
const endpoint = new cloud.API("hello");
endpoint.static("/", "www");
endpoint.get("/source", (req, res) => res.json({name: "AWS"}));
exports.url = endpoint.publish().url;