Skip to content

Instantly share code, notes, and snippets.

@muvaf
Last active June 3, 2021 20:29
Show Gist options
  • Save muvaf/77a9141e07a52298afddb6d674d1175c to your computer and use it in GitHub Desktop.
Save muvaf/77a9141e07a52298afddb6d674d1175c to your computer and use it in GitHub Desktop.
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: compositepostgresqlinstances.aws.database.example.org
labels:
provider: aws
guide: quickstart
vpc: default
spec:
writeConnectionSecretsToNamespace: crossplane-system
compositeTypeRef:
apiVersion: database.example.org/v1alpha1
kind: CompositePostgreSQLInstance
resources:
- name: rdsinstance
base:
apiVersion: database.aws.crossplane.io/v1beta1
kind: RDSInstance
spec:
forProvider:
region: us-east-1
dbInstanceClass: db.t2.small
masterUsername: masteruser
engine: postgres
engineVersion: "9.6"
skipFinalSnapshotBeforeDeletion: true
publiclyAccessible: true
writeConnectionSecretToRef:
namespace: crossplane-system
patches:
- type: CombineFromCompositeFieldPaths
combineFrom:
variables:
- fieldPath: "metadata.name"
- fieldPath: "spec.somefield"
strategy: string # maybe "template" in future?
string:
fmt: "%s-somestuff-%s"
toFieldPath: "spec.policy"
transforms:
- type: string
string:
fmt: "%s-value"
# The direction? Could it ever be ToComposite?
# Maybe we can inject random generator?
# Why "From" prefix? "ConstantValue"?
- type: FromConstantValue
constantValue:
type: int
int: 55
toFieldPath: "spec.number"
# Type has always been about direction AND (if fromMany accepted) form of the input.
# It's a bit of a departure, similar to PatchSet. We're getting closer to "type can be anything".
# Maybe use "FromConstantValue" that has random string set and then have "randomString" transform accept it as input set?
# Though we need to consider whether future Fns could be worth the addition.
# Once set and don't touch? Is this compatible with current composition mechanics?
- type: FromFn
fromFn:
type: randomString
randomString: "abcdefdgsdgds"
toFieldPath: "spec.randomId"
- fromFieldPath: "metadata.uid"
toFieldPath: "spec.writeConnectionSecretToRef.name"
transforms:
- type: string
string:
fmt: "%s-postgresql"
- fromFieldPath: "spec.parameters.storageGB"
toFieldPath: "spec.forProvider.allocatedStorage"
connectionDetails:
- fromConnectionSecretKey: username
- fromConnectionSecretKey: password
- fromConnectionSecretKey: endpoint
- fromConnectionSecretKey: port
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment