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 passsmallPostgres
database URL intomyContainer
workload using environment variables. - To get more information about
Param
directives see Directives page.
serviceName: my-stackresources:myContainer:type: 'container-workload'properties:containers:- name: myContainerimageConfig:filePath: containers/ts-container.tsenvironment:- name: DB_URLvalue: $Param('smallPostgres', 'DbInstance::Endpoint.Address')resources:cpu: 0.25memory: 512smallPostgres:type: 'relational-database'properties:credentials:masterUserName: alexandromasterUserPassword: <<my-secret-pass>>engine:type: postgresproperties:port: 5432storage:diskSizeGB: 20instance: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:
- The output shows resources
myContainer
andsmallPostgres
as well as their underlying Cloudformation resources and referencable parameters, which can be referenced withParam
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.