Skip to main content

Sets up TFE / TFC workspaces for all stacks based on a seed stack.

Project description

cdktf-multi-stack-tfe

Setting up Terraform Cloud / Terraform Enterprise workspaces can be tiring when dealing with CDK for Terraform applications spanning multiple stacks and therefore workspaces. This library aims to automate this.

Usage

You need to create the initial workspace yourself, in this case my-app-base.

import * as cdktf from "cdktf";
import Construct from "constructs";
import { BaseStack, Stack } from "cdktf-multi-stack-tfe";

// We need to have an already created "base" TFE workspace as a basis.
// It will store the TFE workspace configuration and state for all stacks.
// As it creates all TFE workspaces, it's required to be created first (and as a result will scaffold out all the required workspaces).
class MyAppBaseStack extends BaseStack {
  // The name is set to my-app-base
  constructor(scope: Construct) {
    // This will configure the remote backend to use my-company/my-app-base as a workspace
    // my-company is the Terraform organization
    // my-app is the prefix to use for all workspaces
    super(scope, "my-company", "my-app", {
      hostname: "app.terraform.io", // can be set to configure a different Terraform Cloud hostname, e.g. for privately hosted Terraform Enterprise
      token: "my-token", // can be set to configure a token to use
    });

    // You can do additional things in this stack as well
  }
}

class VpcStack extends Stack {
  public vpcId: string

  // This stack will depend on the base stack and it
  // will use the my-company/my-app-$stackName workspace as a backend
  constructor(scope: Construct, stackName: string) {
    super(scope, stackName);

    // Setup an VPC, etc.

    this.vpcId = ....
  }
}

class WebStack extends Stack {
  constructor(scope: Construct, stackName: string, vpcId: string) {
    super(scope, stackName);

    // Setup yourwebapp using the vpcId
  }
}

const app = new cdktf.App();
new MyAppBaseStack(app); // the stack name is "base"

// This cross-stack reference will lead to permissions being set up so that
// the staging-web workspace can access the staging-vpc workspace.
const vpc = new VpcStack(app, "staging-vpc"); // the stack name is "staging-vpc"
new Web(app, "staging-web", vpc.vpcId); // the stack name is "staging-web"

const prodVpc = new VpcStack(app, "production-vpc");
new Web(app, "production-web", prodVpc.vpcId);

app.synth();

Warning

There are some potentially harmful side effects you could run into, so please always carefully read the diff before applying it.

Renaming stacks

This is not supported by the library, if you rename an already existing stack the workspace hosting it will be destroyed and a new one with the new name will be created. This means all references to the infrastructure provisioned in the old stack will be lost, making it impossible to destroy the infrastructure through terraform. In this case we recommend destroying the stack, renaming it and then re-creating it. There are some ways around this issue, but the library currently does not support them.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cdktf-multi-stack-tfe-0.0.7.tar.gz (23.5 kB view details)

Uploaded Source

Built Distribution

cdktf_multi_stack_tfe-0.0.7-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file cdktf-multi-stack-tfe-0.0.7.tar.gz.

File metadata

  • Download URL: cdktf-multi-stack-tfe-0.0.7.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for cdktf-multi-stack-tfe-0.0.7.tar.gz
Algorithm Hash digest
SHA256 8c1a90ab33c2995c79eef84e852ab89a27c8d3a3e66cd6f4d6b6e1178d1bf3df
MD5 347b190990f5264f4662e155a99e6bc0
BLAKE2b-256 b98cddf8abe21768972e76a8e2be16423ca6b4bf29cf4cf7ec5a821d38a4a645

See more details on using hashes here.

File details

Details for the file cdktf_multi_stack_tfe-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: cdktf_multi_stack_tfe-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 22.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for cdktf_multi_stack_tfe-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 2358b02be23b4202ff982408e793206a6671f58cbfccdd2c3dd053c2aeb43893
MD5 18e2167425a4e6b4a07ff121e344027d
BLAKE2b-256 062dd1c5a592cd9407a795bae9b6e56a5e382018d22db1b2ab64af1c8d71f45f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page