Quickstart
This quickstart for Extensions builds one that keeps your Postgres cluster's backups for 30 days instead of the 7 Alien sets. You test it, see the change in the CloudFormation template, and ship it in a release.
alien init extensions/postgres-backup-retention backupsYou need a stack with a frozen alien.Postgres on AWS, and the Rust target the hooks build for:
rustup target add wasm32-wasip1Create the extension
alien init extensions/postgres-backup-retention backupsIt creates a Cargo workspace in ./backups with one crate, hooks:
backups/
├── Cargo.toml # tells alien extensions build which crate is the hooks crate
└── hooks/
└── src/lib.rs # the two modifiers and their registrationRead the modifiers
A template modifier gets the template Alien generated for initial setup and returns a changed one. This crate has one for CloudFormation and one for Terraform. Here are their AWS parts. The backups example also shows the Google Cloud and Azure parts:
use alien_extension_sdk::prelude::*;
/// Keeps every RDS cluster's backups for 30 days.
struct CloudFormation;
impl CloudFormationModifier for CloudFormation {
fn modify(&self, mut template: CfTemplate) -> Result<CfTemplate> {
for cluster in template.resources_of_type_mut("AWS::RDS::DBCluster") {
cluster.set_property("BackupRetentionPeriod", 30);
}
Ok(template)
}
}
/// The same setting in the Terraform module.
struct Terraform;
impl TerraformModifier for Terraform {
fn modify(&self, mut module: TfModule) -> Result<TfModule> {
for cluster in module.resources_of_type_mut("aws_rds_cluster") {
cluster.set_attribute("backup_retention_period", 30);
}
Ok(module)
}
}
fn register(ext: &mut Extension) {
ext.cloudformation_modifier(CloudFormation);
ext.terraform_modifier(Terraform);
}
alien_extension_sdk::export!("backups", register);export! names the extension backups. The modifiers run when Alien builds the setup template, never in your customer's cloud.
Test it
cd backups
alien extensions testIt runs the crate's tests natively and again inside the WebAssembly module Alien loads, and fails if the two give different results.
Build it
alien extensions buildIt builds the hooks module and writes generated/index.ts, the TypeScript your stack imports.
Add it to your stack
Import the generated module and list it in .extensions():
import * as alien from "@alienplatform/core"
import backups from "./backups/generated"
const db = new alien.Postgres("db").build()
export default new alien.Stack("my-app")
.extensions([backups])
.add(db, "frozen")
.build()See the template
Print the CloudFormation template your customers will get, and read the cluster's retention:
alien render --format cloudformation --stack alien.ts --json \
| jq '.Resources[] | select(.Type == "AWS::RDS::DBCluster") | .Properties.BackupRetentionPeriod'30Without .extensions([backups]), the same command prints 7. alien render also lists which extension changed which resource.
Use the alien CLI you install from alien.dev. A CLI built from the open-source repository has no Postgres emitter, so it can't render this stack.
Release
alien releaseThe release uploads the extension and pins its digest. Setup templates built from this release keep backups for 30 days. A deployment set up before it gets the setting when its admin reruns initial setup with the new template.
Live databases
A live Postgres is created by Alien's controller, not by the setup template, so a modifier doesn't reach it. An interceptor on the CreateDBCluster call does, as the IAM database authentication example shows. The backups example also covers Google Cloud and Azure.
Next
- Template modifiers: the CloudFormation, Terraform, and Helm APIs, and what a modifier may change
- Interceptors: change the calls Alien's controllers make
- Testing: test hooks and controllers before a release
Overview
Change what Alien deploys, add resources Alien doesn't have, and change the cloud calls Alien makes, with Rust code that ships in your release.
Template modifiers
Change the CloudFormation template, Terraform module, or Helm chart Alien generates for initial setup, with Rust code in your extension.