logoStacktape docs




Referencing Resources

Referencing between resources is often needed when injecting information about resources of a stack (databases, buckets, etc.) into workloads or other resources of the stack.

The main concepts of referencing are:

  • Each Stacktape resource specified in the resources section of a template is composed of multiple Cloudformation resources. Parameters of these inner Cloudformation resources can be interpolated into template using Param.

  • To find out how to list all Cloudformation resources contained within a Stacktape resource, see section Descriptive names and parameters.

Referencing example

Consider the following Stacktape template file named stacktape.yml

  • In the template file we are using references and built-in directive Param to pass smallPostgres database URL into myContainer workload using environment variables.
  • To get more information about Param directives see Directives page.

serviceName: my-stack
resources:
myContainer:
type: 'container-workload'
properties:
containers:
- name: myContainer
imageConfig:
filePath: containers/ts-container.ts
environment:
- name: DB_URL
value: $Param('smallPostgres', 'DbInstance::Endpoint.Address')
resources:
cpu: 0.25
memory: 512
smallPostgres:
type: 'relational-database'
properties:
credentials:
masterUserName: alexandro
masterUserPassword: <<my-secret-pass>>
engine:
type: postgres
properties:
port: 5432
storage:
diskSizeGB: 20
instance:
dbInstanceSize: db.t3.micro

Descriptive names and parameters

describe-resources command:

  • prints an overview of resources specified in the Stacktape template file
  • prints all underlying Cloudformation resources which are part of the Stacktape resources.
  • prints referencable parameters of the underlying Cloudformation resources

Consider the following command.

stacktape describe-resources --stage my-stage --configPath stacktape.yml --region eu-west-1

If we would run the presented command on the template file in referencing example section, the output would look like this.

Output is shortened for the sake of brevity and contains explanations.

OUTPUT:

Output of describe-resources command

  • The output shows resources myContainer and smallPostgres as well as their underlying Cloudformation resources and referencable parameters, which can be referenced with Param directive.
  • When referencing in Param you use resource name of resource, descriptive name of sub-resource and referencable parameters. See GetParam page for more info.
  • To see full reference of the describe-resources command see describe-resources command page.