### Project Initialization with npm Source: https://takomo.io/docs/getting-started/quick-start This snippet demonstrates initializing a new Node.js project and installing Takomo as a development dependency using npm. This sets up the project structure for using Takomo. ```bash mkdir takomo-quick-start cd takomo-quick-start npm init -y npm install --save-dev takomo npx tkm --version ``` -------------------------------- ### Initialize npm Project Source: https://takomo.io/docs/getting-started/installation Initializes a new Node.js project with a default package.json file. This is the first step before installing Takomo as a project dependency. ```shell npm init -y ``` -------------------------------- ### Install Takomo Globally Source: https://takomo.io/docs/getting-started/installation Installs Takomo as a global package, making the 'tkm' command available system-wide. Useful for quick experimentation or global access. ```shell npm install -g takomo ``` -------------------------------- ### Deploying Takomo Stack Source: https://takomo.io/docs/getting-started/quick-start This bash command deploys a Takomo stack using the specified AWS profile. It will prompt for confirmation and show a plan of proposed changes before executing the deployment. ```bash npx tkm stacks deploy --profile takomo-quick-start ``` -------------------------------- ### Verify Local Takomo Installation Source: https://takomo.io/docs/getting-started/installation Checks the installed Takomo version when installed as a project dependency, using npx to run the command. ```shell npx tkm --version ``` -------------------------------- ### CloudFormation VPC Template Source: https://takomo.io/docs/getting-started/quick-start This YAML snippet defines a CloudFormation template for creating a VPC. It includes a description, a parameter for the CIDR block, and a resource definition for the AWS::EC2::VPC. ```yaml Description: My VPC Parameters: CidrBlock: Type: String Description: VPC CIDR block Resources: VPC: Type: AWS::EC2::VPC Properties: CidrBlock: !Ref CidrBlock ``` -------------------------------- ### Check Node.js Version Source: https://takomo.io/docs/getting-started/installation Verifies the installed Node.js version. This is a prerequisite for installing Takomo. ```shell node --version ``` -------------------------------- ### AWS Credentials Configuration Source: https://takomo.io/docs/getting-started/quick-start This snippet shows how to configure AWS credentials in the `~/.aws/credentials` file. It requires an AWS access key ID and secret access key for the specified profile. Ensure the IAM user has sufficient permissions. ```ini [takomo-quick-start] aws_access_key_id = ENTER_YOUR_ACCESS_KEY_ID_HERE aws_secret_access_key = ENTER_YOUR_SECRET_ACCESS_KEY_HERE ``` -------------------------------- ### Initialize Takomo Project with NPM Source: https://takomo.io/docs/getting-started/tutorial These commands initialize a new Node.js project using npm and install Takomo as a development dependency. This sets up the basic project structure and installs the necessary Takomo package for managing your infrastructure. ```bash mkdir takomo-tutorial cd takomo-tutorial npm init -y npm install -D takomo ``` -------------------------------- ### Undeploying Takomo Stack Source: https://takomo.io/docs/getting-started/quick-start This bash command undeploys a Takomo stack using the specified AWS profile. It will present a plan before removing the stack and its associated resources, followed by a summary of the results. ```bash npx tkm stacks undeploy --profile takomo-quick-start ``` -------------------------------- ### Install Takomo as Project Dependency Source: https://takomo.io/docs/getting-started/installation Installs Takomo as a development dependency within your Node.js project. This ensures version consistency across different environments. ```shell npm install --save-dev takomo ``` -------------------------------- ### Takomo CLI Examples - Deploying Stacks Source: https://takomo.io/docs/command-line-usage/deploy-stacks A collection of examples demonstrating various ways to deploy stacks using the Takomo CLI. These examples cover deploying all stacks, stacks in a specific path, individual stacks with dependencies, stacks in a particular region, and deploying a single stack while ignoring its dependencies. ```bash # Deploy all stacks: tkm stacks deploy ``` ```bash # Deploy stacks within the given command path: tkm stacks deploy /prod ``` ```bash # Deploy only /dev/vpc.yml stack and its dependencies: tkm stacks deploy /dev/vpc.yml ``` ```bash # The region part must be specified if the stack has more than one region and you want to deploy it to only one region. tkm stacks deploy /dev/vpc.yml/eu-west-1 ``` ```bash # Deploy exactly one stack and skip its dependencies: tkm stacks deploy /cloudtrail.yml --ignore-dependencies ``` -------------------------------- ### Takomo Stack Configuration for VPC Source: https://takomo.io/docs/getting-started/quick-start This YAML snippet defines the configuration for a VPC stack, including the target region and parameters. It specifies 'eu-west-1' as the region and '10.0.0.0/24' as the default CIDR block for the VPC. ```yaml regions: eu-west-1 parameters: CidrBlock: 10.0.0.0/24 ``` -------------------------------- ### Verify Global Takomo Installation Source: https://takomo.io/docs/getting-started/installation Checks the installed Takomo version when installed globally. The 'tkm' command is directly available from the shell. ```shell tkm --version ``` -------------------------------- ### Install Takomo CLI Source: https://context7.com/context7/takomo_io/llms.txt Installs the Takomo CLI as a local development dependency in a Node.js project using npm. Requires Node.js v22.16.0 or later and is compatible with macOS/Linux. ```bash npm init -y npm install --save-dev takomo npx tkm --version ``` -------------------------------- ### Takomo CLI: Example IAM Policy Generation Source: https://takomo.io/docs/command-line-usage/generate-iam-policies This example demonstrates generating IAM policies for a specific user across multiple AWS regions. It specifies the start and end times, the identity ARN, and lists the regions to query CloudTrail events from. ```bash tkm iam generate-policies \ --start-time 2021-05-02T16:45:54.169Z \ --end-time 2021-05-02T16:45:54.462Z \ --identity arn:aws:iam::123456789012:user/john@example.com \ --region eu-west-1 \ --region us-east-1 ``` -------------------------------- ### Display Takomo Version Information Source: https://takomo.io/docs/command-line-usage/common-options Print the currently installed version of Takomo CLI by using the `--version` option. This is helpful for verifying installation and compatibility. ```cli --version ``` -------------------------------- ### Takomo Deploy Stacks Command Examples Source: https://context7.com/context7/takomo_io/llms.txt Demonstrates various ways to deploy stacks using the Takomo CLI, including deploying all stacks, specific paths, single stacks with dependency management, targeting specific regions, ignoring dependencies, interactive deployment, validation checks, and output formatting. ```bash tkm stacks deploy tkm stacks deploy /prod tkm stacks deploy /dev/vpc.yml tkm stacks deploy /dev/vpc.yml/eu-west-1 tkm stacks deploy /cloudtrail.yml --ignore-dependencies tkm stacks deploy -i tkm stacks deploy --expect-no-changes tkm stacks deploy --output json ``` -------------------------------- ### Takomo List Stacks Command Examples Source: https://context7.com/context7/takomo_io/llms.txt Shows how to list configured stacks and their deployment status using the Takomo CLI, including listing all stacks, stacks within a specific environment, and outputting the results in JSON format for programmatic parsing. ```bash tkm stacks list tkm stacks list /prod tkm stacks list --output json ``` -------------------------------- ### Takomo CLI - Examples for Detect Drift Source: https://takomo.io/docs/command-line-usage/detect-drift These examples demonstrate how to use the `tkm stacks detect-drift` command. The first example shows detecting drift from all stacks, while the second shows detecting drift from stacks within a specific command path like `/prod`. ```bash tkm stacks detect-drift ``` ```bash tkm stacks detect-drift /prod ``` -------------------------------- ### Takomo Undeploy Stacks Command Examples Source: https://context7.com/context7/takomo_io/llms.txt Illustrates different methods for undeploying stacks with Takomo, covering all stacks, specific environments, single stacks with dependency handling, targeting specific regions, ignoring dependencies, and output formatting. ```bash tkm stacks undeploy tkm stacks undeploy /dev tkm stacks undeploy /dev/vpc.yml tkm stacks undeploy /dev/vpc.yml/eu-west-1 tkm stacks undeploy /cloudtrail.yml --ignore-dependencies tkm stacks undeploy --output yaml ``` -------------------------------- ### Stack and Stack Group Path Examples (Takomo) Source: https://takomo.io/docs/configuration/stacks-and-stack-groups Provides examples of how stacks and stack groups are represented by their file paths within the Takomo project structure. These paths are used in Takomo's CLI commands and configuration files. ```table File | Path ---|-- stacks directory | `/` dev (stack group) | `/dev` dev/application.yml | `/dev/application.yml/us-east-1` dev/vpc.yml | `/dev/vpc.yml/us-east-1` prod (stack group) | `/prod` prod/application.yml | `/prod/application.yml/eu-west-1` prod/vpc.yml | `/prod/vpc.yml/eu-west-1` ``` -------------------------------- ### Takomo CLI Examples: Undeploying Stacks Source: https://takomo.io/docs/command-line-usage/undeploy-stacks Illustrative examples demonstrating various ways to undeploy stacks using the Takomo CLI, including undeploying all stacks, specific stacks, stacks with dependencies ignored, and stacks from a particular region. ```bash # Undeploy all stacks: tkm stacks undeploy ``` ```bash # Undeploy stacks within the given command path: tkm stacks undeploy /dev ``` ```bash # Undeploy only /dev/vpc.yml stack and its dependants: tkm stacks undeploy /dev/vpc.yml ``` ```bash # Undeploy from a specific region: tkm stacks undeploy /dev/vpc.yml/eu-west-1 ``` ```bash # Undeploy exactly one stack and skip its dependants: tkm stacks undeploy /cloudtrail.yml --ignore-dependencies ``` -------------------------------- ### Deploy DynamoDB Stack with Takomo CLI Source: https://takomo.io/docs/getting-started/tutorial This command initiates the deployment of the DynamoDB stack. It requires the Takomo CLI to be installed and a specific AWS profile to be configured. The output shows a deployment plan and prompts for user confirmation. ```bash npx tkm stacks deploy --profile takomo-tutorial ``` -------------------------------- ### Takomo Command Resolver Configuration Example Source: https://takomo.io/docs/parameter-resolvers/command-resolver This example demonstrates how to configure the Takomo command resolver to use the content of a file as a parameter value. It specifies the resolver type as 'cmd' and provides the shell command to execute. ```yaml parameters: Password: resolver: cmd command: cat /home/password.txt ``` -------------------------------- ### Takomo CLI: Examples of Emitting Stack Templates Source: https://takomo.io/docs/command-line-usage/emit-stack-templates Demonstrates various ways to use the 'tkm stacks emit' command, covering different scenarios such as emitting all templates, targeting specific directories, omitting logs, selecting specific stacks, and ignoring dependencies. ```bash # Emit templates for all stacks: tkm stacks emit ``` ```bash # Emit templates to /tmp dir: tkm stacks emit --out-dir /tmp ``` ```bash # Omit all logging expect the templates themselves: tkm stacks emit -q ``` ```bash # Emit templates for stacks within the given command path: tkm stacks emit /prod ``` ```bash # Emit template only for stack /dev/vpc.yml stack and its dependencies: tkm stacks emit /dev/vpc.yml ``` ```bash # The region part must be specified if the stack has more than one region and you want to choose only one region. tkm stacks emit /dev/vpc.yml/eu-west-1 ``` ```bash # Emit template of exactly one stack and skip its dependencies: tkm stacks emit /cloudtrail.yml --ignore-dependencies ``` -------------------------------- ### Takomo CLI Example: Prune All Obsolete Stacks Source: https://takomo.io/docs/command-line-usage/prune-stacks A simple example demonstrating how to prune all stacks marked as obsolete using the Takomo CLI without specifying a command path. ```bash tkm stacks prune ``` -------------------------------- ### Example: Cmd Hook After Create and Update (YAML) Source: https://takomo.io/docs/stack-properties/hooks This example shows a command-line hook named 'my-hook' configured to run after both 'create' and 'update' operations. It utilizes a list for the 'operation' property and specifies the 'after' stage with a simple 'echo' command. ```yaml hooks: - name: my-hook type: cmd operation: - create - update stage: after command: echo 'hello' ``` -------------------------------- ### Define Simple Static Parameter List Source: https://takomo.io/docs/stack-properties/parameters This example demonstrates defining a parameter named 'CidrBlocks' with a list of static string values. This is useful for parameters that accept multiple distinct values, such as CIDR blocks for network configurations. ```yaml parameters: CidrBlocks: - 10.0.0.0/26 - 10.0.0.64/26 ``` -------------------------------- ### Iterate Over Collections in EJS Source: https://takomo.io/docs/variables-and-templating/ejs-syntax Provides an example of looping through an array or collection in EJS. Each item in the collection can be accessed and processed within the loop body. ```ejs <% it.securityGroupIds.forEach(function(sg){ %> <%= sg %> <% }) %> ``` -------------------------------- ### Example Takomo Project Structure (File System) Source: https://takomo.io/docs/configuration/stacks-and-stack-groups Illustrates a typical Takomo project layout, showing the organization of stack configuration files within 'stacks' directories and templates in a 'templates' directory. This structure supports hierarchical configuration through stack groups. ```tree . ├─ stacks │ ├─ config.yml │ ├─ dev │ │ ├─ config.yml │ │ ├─ application.yml │ │ └─ vpc.yml │ └─ prod │ ├─ application.yml │ └─ vpc.yml └─ templates ├─ application-template.yml └─ vpc-template.yml ``` -------------------------------- ### Inspect All Stack Configurations (Takomo CLI) Source: https://takomo.io/docs/command-line-usage/inspect-stack-configuration Displays the configuration of all stacks managed by Takomo. This command is useful for a comprehensive overview of your deployment setup. It accepts an optional output format. ```bash tkm stacks inspect configuration ``` -------------------------------- ### Example: Cmd Hook After Successful Create (YAML) Source: https://takomo.io/docs/stack-properties/hooks This example demonstrates a command-line hook that executes after a stack creation operation is successful. It specifies the hook's name, type, the operation ('create'), stage ('after'), and status ('success'), along with the command to be executed. ```yaml hooks: - name: executed-after-successful-create type: cmd operation: create stage: after status: success command: echo 'success' ``` -------------------------------- ### Takomo CLI Example: Prune Specific Stack and Dependants Source: https://takomo.io/docs/command-line-usage/prune-stacks Demonstrates pruning a single stack, '/dev/vpc.yml', along with any stacks that depend on it using the Takomo CLI. ```bash tkm stacks prune /dev/vpc.yml ``` -------------------------------- ### Takomo Stack Group Configuration Source: https://context7.com/context7/takomo_io/llms.txt Provides examples of hierarchical configuration for organizing stacks using directory-based stack groups. Demonstrates how `config.yml` files in parent directories inherit configuration to child stack groups and individual stacks. ```yaml # stacks/config.yml (root stack group) regions: eu-west-1 tags: Project: MyProject ManagedBy: Takomo ``` ```yaml # stacks/dev/config.yml (inherits from root) regions: us-east-1 tags: Environment: Development accountIds: - "123456789012" ``` ```yaml # stacks/dev/application.yml (inherits from dev stack group) template: application-template.yml parameters: InstanceType: t3.micro Environment: dev depends: - /dev/vpc.yml ``` ```yaml # stacks/prod/application.yml (different configuration for production) template: application-template.yml regions: eu-west-1 parameters: InstanceType: m5.large Environment: prod terminationProtection: true depends: - /prod/vpc.yml ``` -------------------------------- ### Takomo Schema Configuration Example Source: https://takomo.io/docs/stack-properties/schemas This example demonstrates how to configure Takomo to use custom schemas for validating stack data and tags. It shows the 'schemas' property with references to 'myDataSchema', 'commonTags', and 'environmentTag', including specific properties for 'environmentTag'. ```yaml schemas: data: myDataSchema tags: - commonTags - name: environmentTag allowedValues: - dev - test - prod ``` -------------------------------- ### Define Simple Static Parameter Value Source: https://takomo.io/docs/stack-properties/parameters This example shows how to define a single static string value for a parameter named 'VpcId' directly in the stack configuration file. This is the most straightforward way to set a parameter when the value is known and constant. ```yaml parameters: VpcId: vpc-06e4ab6c6c ``` -------------------------------- ### Handlebars Collection Iteration Source: https://takomo.io/docs/variables-and-templating/handlebars-syntax Demonstrates the `each` block helper for iterating over collections (arrays or objects) in Handlebars. It allows processing each item in a collection. ```handlebars {{#each securityGroupIds}} - {{this}} {{/each}} ``` -------------------------------- ### Takomo CLI Example: Prune Stack and Ignore Dependants Source: https://takomo.io/docs/command-line-usage/prune-stacks Shows how to prune a single stack, '/cloudtrail.yml', while explicitly skipping the removal of its dependent stacks using the `--ignore-dependencies` option. ```bash tkm stacks prune /cloudtrail.yml --ignore-dependencies ``` -------------------------------- ### Specify Template Bucket Name Only (YAML) Source: https://takomo.io/docs/stack-properties/template-bucket This example shows the minimal configuration for `templateBucket` in Takomo, where only the S3 bucket `name` is provided. Takomo will upload templates to the root of this bucket. ```yaml templateBucket: name: hello-bucket ``` -------------------------------- ### Dynamic Parameter using Stack Output Resolver Source: https://takomo.io/docs/stack-properties/parameters This example demonstrates using the 'stack-output' resolver to dynamically set the 'VpcId' parameter from an output value of another stack within the same Takomo project. It specifies the target stack file and the output key. ```yaml parameters: VpcId: resolver: stack-output stack: /vpc.yml output: vpcId ``` -------------------------------- ### Define Static Parameter Using Object Notation Source: https://takomo.io/docs/stack-properties/parameters This example illustrates defining a static parameter 'VpcId' using object notation. This method is used when additional properties, like 'value', are required to configure the parameter, even for static assignments. ```yaml parameters: VpcId: value: vpc-06e4ab6c6c ``` -------------------------------- ### Initialize Takomo Project and Deploy VPC Source: https://context7.com/context7/takomo_io/llms.txt Sets up a basic Takomo project structure, configures AWS credentials, defines a VPC stack configuration and template, and deploys the stack using the Takomo CLI. Includes commands for both deployment and cleanup. ```bash mkdir -p takomo-quick-start/{stacks,templates} cd takomo-quick-start cat >> ~/.aws/credentials < Date.now(), } ``` ```json { "name": "takomo-timestamp-resolver", "version": "0.0.1", "description": "My custom timestamp resolver", "files": [ "index.js" ], "main": "index.js", "license": "MIT", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" } } ``` -------------------------------- ### Takomo CLI Example: Prune Stacks in Command Path Source: https://takomo.io/docs/command-line-usage/prune-stacks Shows how to prune obsolete stacks within a specific command path using the Takomo CLI. This targets stacks that reside under the '/dev' directory or path. ```bash tkm stacks prune /dev ``` -------------------------------- ### Customize Handlebars Template Engine with Typescript Source: https://takomo.io/docs/variables-and-templating/typescript-support This example demonstrates how to customize Takomo's default Handlebars templating engine using Typescript. It involves creating a `HandlebarsTemplateEngineProvider` and configuring directories for helpers and partials. This method allows extending Handlebars without replacing it entirely. ```typescript import { HandlebarsTemplateEngineProvider, TakomoConfigProvider, } from "takomo" const provider: TakomoConfigProvider = async () => ({ templateEngineProvider: new HandlebarsTemplateEngineProvider({ helpersDirs: [/* paths to dirs containing helpers implemented with JavaScript */], partialsDirs: [/* paths to dirs containing partials */], }), }) export default provider ``` -------------------------------- ### Reference Stack Output as Parameter (YAML) Source: https://takomo.io/docs/parameter-resolvers/stack-output-resolver This example demonstrates how to use the 'stack-output' resolver in a Takomo project to reference a stack output from another stack. The 'stack' property specifies the path to the source stack, and the 'output' property specifies the name of the output to retrieve. This configuration is typically used within a 'parameters' block of a stack's YAML definition. ```yaml parameters: VpcId: resolver: stack-output stack: /vpc.yml output: MyVpcId ``` -------------------------------- ### Define Immutable Static Parameter Source: https://takomo.io/docs/stack-properties/parameters This example shows how to define an immutable static parameter 'VpcId'. Marking a parameter as immutable ensures its value cannot be changed after deployment, preventing potential failures for resources with non-updatable properties. It requires the 'value' property and sets 'immutable' to true. ```yaml parameters: VpcId: value: vpc-06e4ab6c6c immutable: true ``` -------------------------------- ### Initialize Project Command (Removed) Source: https://takomo.io/docs/upgrade-guide/from-5-to-6 The 'tkm init' command was removed to simplify the codebase and user experience. Its purpose was to assist users in creating new Takomo projects, optionally with sample code. ```bash tkm init ``` -------------------------------- ### Takomo CLI: Generate IAM Policies Command Usage Source: https://takomo.io/docs/command-line-usage/generate-iam-policies This snippet shows the basic command structure for generating IAM policies using Takomo. It requires start and end times, and at least one identity. Optional parameters include specific regions and a role name for multi-account scenarios. ```bash tkm iam generate-policies \ --start-time \ --end-time \ --identity ... \ --region ... \ [--role-name ] ``` -------------------------------- ### VPC Stack Configuration (YAML) Source: https://takomo.io/docs/getting-started/tutorial Sets up the Virtual Private Cloud (VPC) stack. It defines the template and the 'Environment' parameter, along with a specific 'VpcCidr' block for the network. ```yaml template: vpc.yml parameters: Environment: {{ stackGroup.data.environment }} VpcCidr: 10.0.0.64/26 ``` -------------------------------- ### Implement Debug Hook with JavaScript Source: https://takomo.io/docs/hooks/custom-hooks This JavaScript hook provider exports a `type` and an `init` function. The `init` function receives properties and returns an object with an `execute` function. The `execute` function takes an `input` object and returns a hook output object. This example logs debug information to the console. ```javascript export default { type: "debug", init: (props) => { console.log("Initialize debug hook") return { execute: (input) => { console.log("Execute debug hook!") console.log(`Stage: ${input.stage}`) console.log(`Operation: ${input.operation}`) console.log(`Status: ${input.status}`) console.log(JSON.stringify(props, null, 2)) return { message: "OK", success: true, value: "Did some debugging" } } } } } ``` -------------------------------- ### Deploy VPC Endpoints Stack with Dependencies Source: https://takomo.io/docs/getting-started/tutorial This command demonstrates how to deploy a specific Takomo stack, 'vpc-endpoints.yml', along with any of its detected dependencies. Takomo automatically handles the order of deployment based on parameter resolvers, ensuring prerequisites are met. ```bash npx tkm stacks deploy /dev/eu-west-1/vpc-endpoints.yml --profile takomo-tutorial ``` -------------------------------- ### List Configured Stacks with Takomo CLI Source: https://takomo.io/docs/getting-started/tutorial This command lists all configured stacks and their deployment status. It's useful for verifying that Takomo recognizes both deployed and pending stacks before initiating a new deployment. ```bash npx tkm stacks list --profile takomo-tutorial ``` -------------------------------- ### Create Frontend Stack Inheriting Blueprint Source: https://context7.com/context7/takomo_io/llms.txt Creates a frontend stack named 'Frontend App' that inherits from the 'application.yml' blueprint and provides specific parameters like environment and Docker image. ```yaml # stacks/frontend.yml (inherits from blueprint) blueprint: application.yml parameters: Environment: dev Name: Frontend App DockerImage: frontend:1.0.0 ``` -------------------------------- ### Create Stack Configuration Files Source: https://takomo.io/docs/getting-started/tutorial This command sequence creates the necessary YAML files for defining AWS infrastructure stacks within the Takomo project. These files specify stack templates and parameters, enabling the deployment of resources like DynamoDB, Lambda, and VPCs. ```bash touch stacks/prod/eu-west-1/dynamodb.yml touch stacks/prod/eu-west-1/lambda.yml touch stacks/prod/eu-west-1/vpc.yml touch stacks/prod/eu-west-1/vpc-endpoints.yml ``` -------------------------------- ### Handlebars Expression Escaping Source: https://takomo.io/docs/variables-and-templating/handlebars-syntax Explains how to prevent Handlebars from processing an expression by escaping it with a backslash. This is useful when literal Handlebars syntax needs to be displayed. ```handlebars \{{my expression to escape}} ``` -------------------------------- ### Handlebars Variable Usage Source: https://takomo.io/docs/variables-and-templating/handlebars-syntax Demonstrates how to access variables and their properties or array elements within Handlebars templates. This is fundamental for dynamic content rendering. ```handlebars {{ variable_name }} {{ person.firstName }} {{ people.[0] }} ``` -------------------------------- ### Create Takomo Project Directory Structure Source: https://takomo.io/docs/getting-started/tutorial This command creates the necessary directories for organizing Takomo stack configurations and CloudFormation templates. The 'stacks' directory holds stack configurations, and the 'templates' directory holds the CloudFormation templates themselves. Nested directories within 'stacks' are used for organizing by environment and region. ```bash mkdir stacks mkdir templates mkdir -p stacks/dev/eu-west-1 mkdir -p stacks/prod/eu-west-1 ``` -------------------------------- ### Add Comments in EJS Source: https://takomo.io/docs/variables-and-templating/ejs-syntax Shows the syntax for including comments in EJS templates. These comments are ignored during rendering and do not appear in the final output. ```ejs <%# This comment will not show up in the output %> ``` -------------------------------- ### Deploy All Stacks (CLI) Source: https://takomo.io/docs/getting-started/tutorial Deploys all stacks configured in the Takomo project to AWS. The `-y` flag is used to automatically confirm any prompts, skipping the review process. ```bash npx tkm stacks deploy --profile takomo-tutorial -y ``` -------------------------------- ### Display Variables in EJS Source: https://takomo.io/docs/variables-and-templating/ejs-syntax Demonstrates how to output the value of a variable or its nested properties within an EJS template. Assumes variables are available under the `it` object. ```ejs <%= it.variable_name %> <%= it.person.firstName %> ``` -------------------------------- ### Display Help Information (Takomo CLI) Source: https://takomo.io/docs/command-line-usage/common-options Access help documentation for Takomo commands using the `--help` option. For command-specific help, it also lists the minimum IAM permissions required to execute the command. ```cli --help ``` -------------------------------- ### Handlebars Comment Syntax Source: https://takomo.io/docs/variables-and-templating/handlebars-syntax Shows two methods for adding comments in Handlebars templates. These comments are excluded from the final rendered output, useful for code annotations. ```handlebars {{! This comment will not show up in the output}} {{!-- This comment may contain mustaches like }} --}} ``` -------------------------------- ### Escape Expressions in EJS Source: https://takomo.io/docs/variables-and-templating/ejs-syntax Demonstrates how to prevent EJS from processing a specific expression. This is useful when you want to display the EJS syntax literally without it being interpreted. ```ejs <%% this content is not processed %> ``` -------------------------------- ### Handlebars Conditional Logic Source: https://takomo.io/docs/variables-and-templating/handlebars-syntax Illustrates how to use the `if` block helper in Handlebars to conditionally include content based on the truthiness of a variable. Requires a boolean or truthy value for the condition. ```handlebars {{#if some_variable}} this will be included in the output {{/if}} ``` -------------------------------- ### Configure VPC Endpoints Stack for Deployment Source: https://takomo.io/docs/getting-started/tutorial This snippet shows the Takomo stack configuration file for the VPC endpoints. It references the previously defined CloudFormation template and utilizes 'stack-output' parameter resolvers to dynamically fetch the VPC ID and Route Table IDs from the 'vpc.yml' stack. ```yaml template: vpc-endpoints.yml parameters: Environment: {{ stackGroup.data.environment }} VpcId: resolver: stack-output stack: vpc.yml output: VpcId RouteTableIds: resolver: stack-output stack: vpc.yml output: RouteTableIds ``` -------------------------------- ### Inspect Stack Configuration with Options (Takomo CLI) Source: https://takomo.io/docs/command-line-usage/inspect-stack-configuration Demonstrates how to inspect stack configurations using command-line options like interactive search or specifying the output format (text, json, yaml). This provides flexibility in how you retrieve and view configuration data. ```bash tkm stacks inspect configuration /prod --interactive --output json ``` -------------------------------- ### Takomo CLI: Emit Stack Templates Usage Source: https://takomo.io/docs/command-line-usage/emit-stack-templates Shows the command-line syntax for emitting stack templates. It includes the main command, optional command-path argument, and various flags for controlling the output and execution flow. ```bash tkm stacks emit [command-path] \ [--ignore-dependencies] \ [--interactive|-i] \ [--out-dir ] [--skip-parameters] \ [--skip-hooks] ``` -------------------------------- ### Takomo CLI Example: Prune Stack in Specific Region Source: https://takomo.io/docs/command-line-usage/prune-stacks Illustrates how to prune an obsolete stack from a specific region when the stack is deployed across multiple regions. The region is appended to the stack path. ```bash tkm stacks prune /dev/vpc.yml/eu-west-1 ``` -------------------------------- ### Bash: IAM Policy Generation Steps Source: https://context7.com/context7/takomo_io/llms.txt Outlines the bash commands and process for auto-generating least-privilege IAM policies based on CloudTrail events. It involves deploying with admin permissions, then running a generation command with specific time ranges and identities. ```bash # Step 1: Deploy with full admin permissions and track generation command tkm stacks deploy /dev --show-generate-iam-policies --profile admin # Output includes: # To generate IAM policies, run this command after waiting 15 minutes: # tkm iam generate-policies \ # --start-time 2021-05-02T16:45:54.169Z \ # --end-time 2021-05-02T16:45:54.462Z \ # --identity arn:aws:iam::123456789012:user/deploy-user \ # --region eu-west-1 \ # --region us-east-1 # Step 2: Wait 15 minutes for CloudTrail events to be available # Step 3: Generate IAM policies tkm iam generate-policies \ --start-time 2021-05-02T16:45:54.169Z \ --end-time 2021-05-02T16:45:54.462Z \ --identity arn:aws:iam::123456789012:user/deploy-user \ --region eu-west-1 \ --region us-east-1 ``` -------------------------------- ### Implement If-Conditions in EJS Source: https://takomo.io/docs/variables-and-templating/ejs-syntax Illustrates how to use conditional statements in EJS to selectively include content based on a variable's truthiness. The condition is evaluated and output is generated only if the condition is met. ```ejs <% if (it.some_variable) { %> this will be included in the output <% } %> ``` -------------------------------- ### Application Template YAML - templates/application-template.yml Source: https://takomo.io/docs/blueprints/introduction Defines parameters for application stacks. This template is used by the application blueprint and specifies required parameters like Environment, Name, and DockerImage. ```yaml Parameters: Environment: Type: String Description: Application environment Name: Type: String Description: Application name DockerImage: Type: String Description: Application docker image Resources: # ...Resources omitted for brevity ``` -------------------------------- ### Read Secret Parameter from Different Region (YAML) Source: https://takomo.io/docs/parameter-resolvers/secret-resolver This example demonstrates reading a parameter value from a secret in a different AWS region. It includes the 'region' property to specify the target region, in addition to the 'resolver' and 'secretId'. ```yaml parameters: MyParam: resolver: secret secretId: my-secret-password region: eu-west-1 ``` -------------------------------- ### Configure Lambda Stack Parameters (Takomo) Source: https://takomo.io/docs/getting-started/tutorial This configuration file is used by Takomo to define the parameters for deploying the Lambda stack. It references the `lambda.yml` template and resolves parameters like Environment, VpcId, SubnetIds, TableName, and TableArn by fetching outputs from other deployed stacks (`vpc.yml` and `dynamodb.yml`). This allows for dynamic parameterization based on existing infrastructure. ```yaml template: lambda.yml parameters: Environment: {{ stackGroup.data.environment }} VpcId: resolver: stack-output stack: vpc.yml output: VpcId SubnetIds: resolver: stack-output stack: vpc.yml output: SubnetIds TableName: resolver: stack-output stack: dynamodb.yml output: TableName TableArn: resolver: stack-output stack: dynamodb.yml output: TableArn ``` -------------------------------- ### TypeScript Schema Provider for Stack Names Source: https://takomo.io/docs/validation-schemas/custom-validation-schemas This TypeScript code defines a schema provider for stack names. It enforces that the stack name must be lowercase and start with a specified prefix provided in the configuration properties. ```typescript import { InitSchemaProps, SchemaProvider } from "takomo" const init = async ({ joi, props }: InitSchemaProps) => joi .string() .lowercase() .custom((value, helpers) => { // Name must begin with the given prefix if (!value.startsWith(props.prefix)) { return helpers.error("invalidPrefix", { prefix: props.prefix, name: value, }) } }) .messages({ invalidPrefix: "Stack name '{{#name}}' does not begin with required prefix '{{#prefix}}'", }) export const stackNameSchemaProvider: SchemaProvider = { name: "stack-name", init, } ``` -------------------------------- ### Create Database Stack Overriding Blueprint Defaults Source: https://context7.com/context7/takomo_io/llms.txt Creates an 'operative-database' stack that inherits from the 'database.yml' blueprint and overrides the instance class and allocated storage parameters. ```yaml # stacks/operative-database.yml (override some defaults) blueprint: database.yml parameters: Environment: dev InstanceClass: db.m4.medium AllocatedStorage: 25 ``` -------------------------------- ### Configure AWS Profile for Assuming Roles with MFA Source: https://takomo.io/docs/configuration/aws-credentials This example extends role assumption configuration by including the `mfa_serial` property. This is necessary for roles that require multi-factor authentication. When using this profile, Takomo will prompt for an MFA code. ```ini [manager] aws_access_key_id = aws_secret_access_key = [account-a-admin] role_arn = arn:aws:iam::123456789012:role/admin source_profile = manager mfa_serial = arn:aws:iam::224466880011:mfa/username ``` -------------------------------- ### Takomo CLI - List All Stacks Source: https://takomo.io/docs/command-line-usage/list-stacks Lists all stacks managed by Takomo. This command requires 'cloudformation:DescribeStacks' IAM permission. It has no specific input arguments beyond the command itself and outputs results in text format by default. ```bash tkm stacks list ``` -------------------------------- ### Create VPC CloudFormation Template Source: https://takomo.io/docs/getting-started/tutorial This YAML defines a basic VPC stack using AWS CloudFormation. It includes parameters for environment and VPC CIDR block, and resources for VPC, Subnet, Route Table, and Route Table Association. Outputs provide IDs for created resources. ```yaml Parameters: Environment: Type: String Description: Application environment AllowedValues: - dev - prod VpcCidr: Type: String Description: VPC CIDR block Resources: Vpc: Type: AWS::EC2::VPC Properties: CidrBlock: !Ref VpcCidr Subnet: Type: AWS::EC2::Subnet Properties: CidrBlock: !Ref VpcCidr VpcId: !Ref Vpc RouteTable: Type: AWS::EC2::RouteTable Properties: VpcId: !Ref Vpc RouteTableAssociation: Type: AWS::EC2::SubnetRouteTableAssociation Properties: SubnetId: !Ref Subnet RouteTableId: !Ref RouteTable Outputs: VpcId: Value: !Ref Vpc RouteTableIds: Value: !Ref RouteTable SubnetIds: Value: !Ref Subnet ``` -------------------------------- ### Frontend Stack YAML - stacks/frontend.yml Source: https://takomo.io/docs/blueprints/introduction Configures a frontend application stack. It inherits from the 'application.yml' blueprint and provides specific values for the application parameters. ```yaml blueprint: application.yml paramters: Environment: dev Name: Frontend App DockerImage: frontend:1.0.0 ``` -------------------------------- ### Use Handlebars in CloudFormation Template Source: https://context7.com/context7/takomo_io/llms.txt Demonstrates using Handlebars syntax within a CloudFormation template to dynamically set descriptions, parameter values based on conditions, and resource tags, utilizing variables defined in the Takomo configuration. ```yaml # templates/vpc-template.yml (Handlebars in CloudFormation) Description: VPC for {{ var.context.projectDir.name }} Parameters: Environment: Type: String AllowedValues: {{#each var.data.environments}} - {{this}} {{/each}} Resources: VPC: Type: AWS::EC2::VPC Properties: CidrBlock: {{ var.data.vpc_cidrs.[var.parameters.Environment] }} {{#if (eq var.parameters.Environment "prod")}} EnableDnsHostnames: true EnableDnsSupport: true {{/if}} Tags: - Key: Name Value: {{ var.parameters.Environment }}-vpc ``` -------------------------------- ### Backend Stack YAML - stacks/backend.yml Source: https://takomo.io/docs/blueprints/introduction Configures a backend application stack. It inherits from the 'application.yml' blueprint and provides specific values for the application parameters. ```yaml blueprint: application.yml paramters: Environment: dev Name: Backend App DockerImage: backend:2.0.0 ``` -------------------------------- ### Specify Command Role ARN Source: https://takomo.io/docs/stack-properties/command-role This example demonstrates how to specify a command role using its Amazon Resource Name (ARN). The command role is an IAM role that Takomo assumes to execute commands in a target AWS account. ```plaintext arn:aws:iam::123456789012:role/deployer-role ``` -------------------------------- ### Takomo CLI Usage - Deploy Stacks Source: https://takomo.io/docs/command-line-usage/deploy-stacks This code snippet shows the general command-line usage for deploying stacks with the Takomo CLI. It outlines the command structure and available options for controlling the deployment process, such as ignoring dependencies or enabling interactive mode. ```bash tkm stacks deploy [command-path] \ [--ignore-dependencies] \ [--interactive|-i] \ [--expect-no-changes] \ [--output ] ``` -------------------------------- ### Reference Custom Data in Stack Template Source: https://takomo.io/docs/stack-properties/data This example shows how to reference the custom data defined in a stack configuration file within a CloudFormation stack template. It utilizes a templating syntax to insert dynamic values for resource properties, such as tags. ```yaml Resources: Bucket: Type: AWS::S3::Bucket Properties: Tags: - Key: Environment Value: {{ stack.data.environment.name }} - Key: Code Value: {{ stack.data.environment.code }} ``` -------------------------------- ### Configure VPC Stack in Takomo Source: https://takomo.io/docs/getting-started/tutorial This YAML file configures the VPC stack for deployment with Takomo. It specifies the region, the CloudFormation template to use, and overrides default parameters with environment-specific values. ```yaml regions: eu-west-1 template: vpc.yml parameters: Environment: dev VpcCidr: 10.0.0.0/26 ``` -------------------------------- ### Create Backend Stack Inheriting and Overriding Blueprint Source: https://context7.com/context7/takomo_io/llms.txt Creates a backend stack that inherits from 'application.yml' but overrides the region and timeout settings, while also providing specific parameters. ```yaml # stacks/backend.yml (inherits and overrides) blueprint: application.yml regions: us-east-1 # Override blueprint region parameters: Environment: dev Name: Backend App DockerImage: backend:2.0.0 timeout: create: 45 # Override blueprint timeout ``` -------------------------------- ### Takomo CLI Usage: Prune Stacks Source: https://takomo.io/docs/command-line-usage/prune-stacks Illustrates the command-line syntax for pruning stacks with Takomo. It shows the main command, optional command-path argument, and available options such as `--ignore-dependencies`, `--interactive`, and `--output`. ```bash tkm stacks prune [command-path] \ [--ignore-dependencies] \ [--interactive|-i] \ [--output ] ``` -------------------------------- ### Database Blueprint YAML - blueprints/database.yml Source: https://takomo.io/docs/blueprints/introduction Defines a reusable blueprint for database stacks. It specifies the template and provides default values for parameters like InstanceClass, AllocatedStorage, Engine, and EngineVersion. ```yaml template: database-template.yml regions: eu-west-1 parameters: InstanceClass: db.m4.large AllocatedStorage: 50 Engine: mariadb EngineVersion: 10.6.8 ```