百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

stack_master

> 数据库
开源

缺少的 CloudFormation 工具

294 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

缺少的 CloudFormation 工具

StackMaster is a CLI tool to manage CloudFormation stacks, with the following features:

  • Synchronous visibility into stack updates. See exactly what is changing and what will happen before agreeing to apply a change.
  • Dynamic parameter resolvers.
  • Template compiler support for YAML and SparkleFormation.

Stack updates can cause a lot of damage if applied blindly. StackMaster helps with this by providing the operator with as much information about the proposed change as possible before asking for confirmation to continue. That information includes:

  • Template body and parameter diffs.
  • Change sets are displayed for review.
  • Once the diffs & change set have been reviewed, the change can be applied and stack events monitored.
  • Stack events will be displayed until an end state is reached.

Stack parameters can be dynamically resolved at runtime using one of the built in parameter resolvers. Parameters can be sourced from other stacks outputs, or by querying various AWS APIs to get resource ARNs, etc.

Installation

System-wide

bash
gem install stack_master

# if you want linting capabilities:
pip install cfn-lint

Bundler

  • pip install cfn-lint if you need lint functionality
  • Add gem 'stack_master' to your Gemfile.
  • Run bundle install
  • Run bundle exec stack_master init to generate a directory structure and stack_master.yml file

Configuration

Stacks are defined inside a stack_master.yml YAML file. When running stack_master, it is assumed that this file will exist in the current working directory, or that the file is passed in with --config /path/to/stack_master.yml. Here's an example configuration file:

…

S3

StackMaster can optionally use S3 to store the templates before creating a stack. This requires you to configure an S3 bucket in stack_master.yml:

yaml
stack_defaults:
  s3:
    bucket: my_bucket_name
    prefix: cfn_templates/my-awesome-app
    region: us-west-2

Additional files can be configured to be uploaded to S3 alongside the templates:

yaml
stacks:
  production:
    myapp-vpc:
      template: myapp_vpc.rb
      files:
        - userdata.sh

Directories

  • templates - CloudFormation, SparkleFormation or CfnDsl templates.
  • parameters - Parameters as YAML files.
  • secrets - encrypted secret files.
  • policies - Stack policy JSON files.

Templates

StackMaster supports CloudFormation templates in plain JSON or YAML. Any .yml or .yaml file will be processed as YAML, while any .json file will be processed as JSON. Additionally, YAML files can be pre-processed using ERB and compile-time parameters.

Ruby DSLs

By default, any template ending with .rb will be processed as a SparkleFormation template. However, if you want to use CfnDsl templates you can add the following lines to your stack_master.yml.

template_compilers:
  rb: cfndsl

Parameters

By default, parameters are loaded from multiple YAML files, merged from the following lookup paths from bottom to top:

  • parameters/[stack_name].yaml
  • parameters/[stack_name].yml
  • parameters/[region]/[stack_name].yaml
  • parameters/[region]/[stack_name].yml
  • parameters/[region_alias]/[stack_name].yaml
  • parameters/[region_alias]/[stack_name].yml

A simple parameter file could look like this:

yaml
key_name: myapp-us-east-1

Alternatively, a parameter_files array can be defined to explicitly list parameter files that will be loaded. If parameter_files are defined, the automatic search locations will not be used.

yaml
parameters_dir: parameters # the default
stacks:
  us-east-1:
    my-app:
      parameter_files:
        - my-app.yml # parameters/my-app.yml

Parameters can also be defined inline with stack definitions:

yaml
stacks:
  us-east-1:
    my-app:
      parameters:
        VpcId:
          stack_output: my-vpc/VpcId

Compile Time Parameters

Compile time parameters can be defined in a stack's parameters file, using the key compile_time_parameters. Keys in parameter files are automatically converted to camel case.

As an example:

yaml
# parameters/some_stack.yml
vpc_cidr: 10.0.0.0/16
compile_time_parameters:
  subnet_cidrs:
    - 10.0.0.0/28
    - 10.0.2.0/28

SparkleFormation

Compile time parameters can be used for SparkleFormation templates. It conforms and allows you to use the Compile Time Parameters feature.

CloudFormation YAML ERB

Compile time parameters can be used to pre-process YAML CloudFormation templates. An example template:

yaml
# templates/some_stack_template.yml.erb
Parameters:
  VpcCidr:
    Type: String
Resources:
  Vpc:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: !Ref VpcCidr
  # Given the two subnet_cidrs parameters, this creates two resources:
  # SubnetPrivate0 with a CidrBlock of 10.0.0.0/28, and
  # SubnetPrivate1 with a CidrBlock of 10.0.2.0/28
  
  SubnetPrivate:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref Vpc
      AvailabilityZone: ap-southeast-2
      CidrBlock: 
  

Parameter Resolvers

Parameter values can be sourced dynamically using parameter resolvers.

One benefit of using parameter resolvers instead of hard coding values like VPC IDs and resource ARNs is that the same configuration works cross region/account, even though the resolved values will be different.

Cross-account parameter resolving

One way to resolve parameter values from different accounts to the one StackMaster runs in, is to assume a role in another account with the relevant IAM permissions to execute successfully.

This is supported in StackMaster by specifying the role and account properties for the parameter resolver in the stack's parameters file.

All parameter resolvers are supported.

…

An example of use case where cross-account parameter resolving is particularly useful is when setting up VPC peering where you need the VPC ID of the peer. Without the ability to assume a role in another account, the only option was to hard code the peer's VPC ID.

Stack Output

The stack output parameter resolver looks up outputs from other stacks in the same or different region. The expected format is [(region|region-alias):]stack-name/(OutputName|output_name).

yaml
vpc_id:
  # Output from a stack in the same region
  stack_output: my-vpc-stack/VpcId

bucket_name:
  # Output from a stack in a different region
  stack_output: us-east-1:init-bucket/bucket_name

zone_name:
  # Output from a stack in a different region using its alias
  stack_output: global:hosted-zone/ZoneName

This is the most used parameter resolver because it enables stacks to be split up into their separated concerns (VPC, web, database etc) with outputs feeding into parameters of dependent stacks.

Secret

Note: The GPG parameter resolver has been extracted into a dedicated gem. Please install and follow the instructions for the stack_master-gpg_parameter_resolver gem.

Parameter Store

An alternative to the secrets store, uses the AWS SSM Parameter store to protect secrets. Expects a parameter of either String or SecureString type to be present in the same region as the stack. You can store the parameter using a command like this

aws ssm put-parameter --region --name --value --type (String|SecureString)

When doing so make sure you don't accidentally store the secret in your .bash_history and you will likely want to set the parameter to NoEcho in your template.

yaml
db_password:
  parameter_store: ssm_parameter_name

1Password Lookup

An alternative to the secrets store is accessing 1password secrets using the 1password cli (op). You declare a 1password lookup with the following parameters in your parameters file:

yaml
# parameters/database.yml
database_password:
  one_password:
    title: production database
    vault: Shared
    type: password

1password stores the name of the secret in the title. You can pass the vault you expect the secret to be in. Currently we support two types of secrets, passwords and secureNotes. All values must be declared, there are no defaults.

For more information on 1password cli please see here

EJSON Store

ejson is a tool to manage asymmetrically encrypted values in JSON format. This allows you to keep secrets securely in git/Github and gives anyone the ability the capability to add new secrets without requiring access to the private key. ejson_wrapper encrypts the underlying EJSON private key with KMS and stores it in the ejson file as _private_key_enc. Each time an ejson secret is required, the underlying EJSON private key is first decrypted before passing it onto ejson to decrypt the file.

First, generate an ejson file with ejson_wrapper, specifying the KMS key ID to be used:

bash
gem install ejson_wrapper
ejson_wrapper generate --region us-east-1 --kms-key-id [key_id] --file secrets/production.ejson

Then, add the ejson_file argument to your stack in stack_master.yml:

yaml
stacks:
  us-east-1:
    my_app:
      template: my_app.json
      ejson_file: production.ejson

finally refer to the secret key in the parameter file, i.e. parameters/my_app.yml:

yaml
my_param:
  ejson: "my_secret"

Additional configuration options:

  • ejson_file_region The AWS region to attempt to decrypt private key with
  • ejson_file_kms Default: true. Set to false to use ejson without KMS.

Security Group

Looks up a security group by name and returns the ARN.

yaml
ssh_sg:
  security_group: SSHSecurityGroup

Security Groups

An array of security group names can also be provided.

yaml
ssh_sg:
  security_groups:
    - SSHSecurityGroup
    - WebAccessSecurityGroup

AWS IIC/SSO Group IDs

Looks up AWS Identity Center group name in the configured Identity Store and returns the ID suitable for use in AWS IIC assignments. It is likely that account and role will need to be specified to do the lookup, the region specification is optional it defaults to stack region.

yaml
GroupId:
  sso_group_id: '[region:]identity-store-id/SSO Group Name'

e.g.

yaml
GroupIdNotInStackRegion:
  sso_group_id: 'us-east-1:d-123456df8:Okta-App-AWS-FooBar'
GroupIdInStackRegion:
  sso_group_id: 'd-123456df8:Okta-App-AWS-FooBar'

SNS Topic

Looks up an SNS topic by name and returns the ARN.

yaml
notification_topic:
  sns_topic_name: PagerDuty

Latest AMI by Tag

Looks up the latest AMI ID by a given set of tags.

yaml
web_ami:
  latest_ami_by_tags: role=web,application=myapp

Note that the corresponding array resolver is named latest_amis_by_tags.

Latest AMI by attribute

Looks up the latest AMI ID by a given set of attributes. By default it will only return AMIs from the account the stack is created in, but you can specify the account ID or certain keywords mentioned in the aws documentation

This selects the latest wily hvm AMI from Ubuntu (using the account id):

yaml
bastion_ami:
  latest_ami:
    owners: 099720109477
    filters:
      name: ubuntu/images/hvm/ubuntu-wily-15.10-amd64-server-*

A set of possible attributes is available in the AWS documentation.

Any

Issues· 24 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubyawsaws-cloudformationcloudformation

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库