Skip to content

Instantly share code, notes, and snippets.

View hoo29's full-sized avatar

Huw McNamara hoo29

  • UK
View GitHub Profile
@hoo29
hoo29 / hcl-cdktf-equiv.tf
Created September 12, 2022 14:37
Equivalent HCL for the CDKTF example.
terraform {
backend "remote" {
organization = "org"
hostname = "hostname"
workspaces {
name = "hcl"
}
}
@hoo29
hoo29 / cdktf.ts
Last active September 12, 2022 14:33
Example CDKTF file
import { Construct } from "constructs";
import { App, RemoteBackend, TerraformStack, TerraformHclModule, TerraformOutput } from "cdktf";
import { AwsProvider } from "@cdktf/provider-aws";
// These variables are hardcoded here for brevity but the values could be stored and fetched from anywhere.
const DEPLOYMENT_TARGETS = {
// region : aws account id
"ap-northeast-1": "582318560864",
"ap-northeast-2": "600734575887",
"ap-south-1": "718504428378",
@hoo29
hoo29 / main.tf
Last active September 12, 2022 15:30
Terraform
# These variables are declared as locals here for brevity but could equally be terraform variables, a terraform http data source, output from another module etc.
locals {
deployment_targets = {
# region = aws account id
"eu-west-1" = "00000000000"
"eu-west-2" = "11111111111"
}
module_version = "1.2.3"
}
@hoo29
hoo29 / scalr_synth.sh
Created August 12, 2022 07:50
Scalr pre init hook for cdktf
#!/bin/bash
set -eo pipefail
# Scalr pre-init hook script to install nodejs lts in and synthesise the cdktf into terraform json.
# TODO: support custom runners on other ARCHs
ARCH="x64"
if test -f "cdk.tf.json"; then
echo "cdk.tf.json already exists, no re-synthing."
exit 0
@hoo29
hoo29 / transfer.sh
Last active August 8, 2022 08:35
Bash script to migrate Terraform workspcae state from Hashicorp Terraform Cloud to Scalr.
#!/bin/bash
# This script was used to migrate Terraform workspace state from Hashicorp Terraform Cloud (TFC) to Scalr.
# It loops through all projects in a given directory, extracts the workspace id, downloads the state from TFC, and then uploads it to Scalr.
# It was made for the Ably Terraform projects directory structure and so will unlikely work as-is. It can easily be tweaked to support other folder structures.
# The workspaces in Scalr need to already exist.
set -e
set -o pipefail