@@ -78,6 +78,25 @@ includes support for the 100+ functions from the [Sprig
7878library](http://masterminds.github.io/sprig) as well as a `toYaml`
7979function.
8080
81+ Typically templates will result in a single resource, but conditionals
82+ and loops may result in templates rendering to zero or more than one
83+ resource. This is supported, but should be used wit caution.
84+
85+ Consideration for multi-resource templates :
86+
87+ - Resources should be separated by a line with `---` (like in Helm).
88+
89+ - The template as a whole is single unit in the graph of resources,
90+ i.e. individual resources in a template cannot refer to each other
91+ using the `.Resources` method described below. References across
92+ templates using multiple resources are supported.
93+
94+ - It is supported to mix resource kinds in a single template, however,
95+ consider if it would be more appropriate to use separate templates
96+ in such cases.
97+
98+ # # Namespaced Resources
99+
81100Namespace-scoped templated resources are always created in the
82101namespace of the parent resource, e.g. a resource defined under
83102` gatewayTemplate` will be created in the namespace of the parent
@@ -95,12 +114,17 @@ When a resource template can be rendered without missing references,
95114the rendered template will be used to retrieve the current version of
96115the resource from the API server. These 'current resources' will be
97116made available as template variables under `.Resources` and the name
98- of the template.
117+ of the template. **Since a template may render to more than one
118+ resource, the `.Resources` variable is a list**.
99119
100120The following excerpt from a `GatewayClassBlueprint` illustrates how a
101121value is read from the status field of one resource `LBTargetGroup`
102122and how the `status.atProvider.arn` value is used in the template of
103- ` TargetGroupBinding` through `.Resources.LBTargetGroup`.
123+ ` TargetGroupBinding` through `.Resources.LBTargetGroup`. The use of
124+ the `index` function is because we refer to the first resource
125+ rendered from the `LBTargetGroup` template. This is necessary even if
126+ we in this case know that there is always only a single resource
127+ rendered from the template.
104128
105129` ` ` yaml
106130...
@@ -120,7 +144,7 @@ spec:
120144 ...
121145 spec:
122146 # And here we use the value 'status.atProvider.arn' from the 'LBTargetGroup' resource
123- targetGroupARN: {{ .Resources.LBTargetGroup.status.atProvider.arn }}
147+ targetGroupARN: {{ (index .Resources.LBTargetGroup 0) .status.atProvider.arn }}
124148` ` `
125149
126150The following figure illustrates variables available to templates,
0 commit comments