Skip to content

Instantly share code, notes, and snippets.

@EvanBoyle
EvanBoyle / reset.go
Last active March 2, 2022 16:31
Code snippet to refresh a stack in a stuck state using Automation API
package main
import (
"context"
"fmt"
"os"
"path/filepath"
"github.com/pulumi/pulumi/sdk/v3/go/auto"
"github.com/pulumi/pulumi/sdk/v3/go/auto/optrefresh"
This file has been truncated, but you can view the full file.
import * as pulumi from "@pulumi/pulumi";
const value = `
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghij
@EvanBoyle
EvanBoyle / index.ts
Created March 29, 2021 20:23
4k dynamic resources leads to resource exhaustion
import * as pulumi from "@pulumi/pulumi";
function timeout(ms: any) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function sleep(fn: any, ...args: any) {
await timeout(1);
return fn(...args);
}
func reset(ctx context.Context, s auto.Stack){
args.Output.Write([]byte("canceling any active updates...\n"))
// we ignore the error on a cancel as it errors if there is no update running...
_ = s.Cancel(ctx)
args.Output.Write([]byte("removing any pending operations...\n"))
exp, err := s.Workspace().ExportStack(ctx, s.Name())
if err != nil {
return errors.Wrap(err, "failed to reset stack, could not export stack")
}
@EvanBoyle
EvanBoyle / config.d.ts
Last active September 25, 2020 15:52
NodeJS Automation API Shape
export declare type ConfigValue = {
value: string;
secret?: boolean;
};
export declare type ConfigMap = {
[key: string]: ConfigValue;
};
import * as aws from "@pulumi/aws";
import * as AWS from "aws-sdk";
import * as pulumijs from "./pulumijs";
async function main() {
// Set up our stack information.
let region = "us-west-2";
let stack = new pulumijs.Stack("joeduffy/testapp/dev", {
"aws:region": region,
});
console.log(`Application stack ${stack.fullName} in AWS region ${region}`);
import * as child_process from "child-process-promise";
import * as process from "process";
import * as readline from "readline";
import * as request from "request-promise";
import * as pulumirt from "@pulumi/pulumi/runtime";
const resrpc = require("@pulumi/pulumi/proto/resource_grpc_pb.js")
const grpc = require("@pulumi/pulumi/node_modules/grpc"); // HACK: ensure grpc globals match.
// TODO(joe): make this configurable.
const pulumiApi = "https://api.pulumi.com/api";
const pulumiTokenKey = "pulumi:token";
package main
import (
"fmt"
"os"
"time"
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
"github.com/pulumi/pulumi/x/automation"
)
reduntant type declarations in arrays:
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws"
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)
func main() {
This file has been truncated, but you can view the full file.
cd provider && go install -ldflags "-X github.com/pulumi/pulumi-aws/provider/v2/pkg/version.Version=v2.10.1+dirty" github.com/pulumi/pulumi-aws/provider/v2/cmd/pulumi-tfgen-aws
pulumi-tfgen-aws schema --out ./provider/cmd/pulumi-resource-aws --logtostderr -v=9
# go
resource "aws_lambda_function" "example" {
filename = "example.zip"
function_name = "Example"
role = "${aws_iam_role.example.arn}"
handler = "index.handler"
runtime = "nodejs10.x"
}