crossplane-contrib / crossplane-contrib/function-go-templating
Question: is it possible to use managed resource result in go-template?
- Dominant language
- Go
- Stars
- 100
- Forks
- 65
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 9
Description
### What happened?
I'm pretty new to use `go-templating-function` for composition. What I want to achieve is to pass result of provisioned managed resource to another managed resource in compostion. Let's say I want to create AWS security group and security group rule associated with group I created like:
```yaml
{{- $xr := .observed.composite.resource }}
apiVersion: ec2.aws.upbound.io/v1beta1
kind: SecurityGroup
metadata:
name: security-group
annotations:
crossplane.io/composition-resource-name: security-group
spec:
forProvider:
region: {{ $xr.spec.region }}
vpcId: {{ $xr.spec.vpcId }}
name: {{ $xr.spec.name }}-security-group
apiVersion: ec2.aws.upbound.io/v1beta1
kind: SecurityGroupRule
metadata:
name: security-group-rule
annotations:
crossplane.io/composition-resource-name: security-group-rule
spec:
forProvider:
region: {{ $xr.spec.region }}
fromPort: {{ $xr.spec.fromPort}}
toPort: {{ $xr.spec.toPort}}
protocol: TCP
type: ingress
securityGroupId: ???
```
so, I just want to use security group id created by security group in security group rule. If I use patch way, normally I can use `ToCompositeFieldPath` patch in security group resource to write security group id to XR , then use `FromCompositeFieldPath` patch in security group rule resource to read security group id from XR.
But I don't know how to achieve that in go-templating function?
### How can we reproduce it?
No need
### What environment did it happen in?
Function version: v0.4.1
Contributor guide
No contributing guide indexed for this repository
Research direction
Review the go-templating function's handling of `.observed` resources and the documented composition patch flow, using the supplied SecurityGroup and SecurityGroupRule manifests as the reproduction. Done should be a clear, version-specific answer or an actionable requirement with a documented way to pass the observed security-group ID.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- infrastructure
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100