Skip to content

Commit

Permalink
Merge pull request #113 from ytsarev/observe-only-workaround-example
Browse files Browse the repository at this point in the history
Example of observe-only workaround experiment
  • Loading branch information
ytsarev committed Oct 6, 2022
2 parents 885c408 + 72e7746 commit 0d8c3da
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
16 changes: 16 additions & 0 deletions examples/observe-only-composition/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Workaround for Observe-Only Resources Functionality

This example Configuration(Composition+XRD) demonstrates a temporary workaround
for Observe-Only Resources functionality before it is [properly
implemented](https://github.com/crossplane/crossplane/issues/1722)
the core Crossplane.

The workaround consists of a `Composition` that provides a mix of provider-terraform
`Workspace` with the
[aws_vpc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc)
**data** resource as Inline module.

It publishes the discovered observe-only `vpcId` to the `XSubnet` XR status.

The `vpcId` from the status is getting eventually consumed by the native `Subnet`
provider-aws resource which is a part of the same `Composition`.
57 changes: 57 additions & 0 deletions examples/observe-only-composition/composition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: xsubnets.aws.platformref.upbound.io
labels:
provider: aws
spec:
compositeTypeRef:
apiVersion: aws.platformref.upbound.io/v1alpha1
kind: XSubnet
resources:
- name: observe-only-vpc
base:
apiVersion: tf.crossplane.io/v1alpha1
kind: Workspace
metadata:
name: observe-only-vpc
spec:
forProvider:
source: Inline
module: |
data "aws_vpc" "observe_only" {
tags = {
Name = var.vpcName
}
}
output "vpc_id" {
description = "Observe Only VPC ID"
value = try(data.aws_vpc.observe_only.id, "")
}
variable "vpcName" {
description = "VPC name"
type = string
}
vars:
- key: vpcName
patches:
- fromFieldPath: spec.vpcName
toFieldPath: spec.forProvider.vars[0].value
- type: ToCompositeFieldPath
fromFieldPath: status.atProvider.outputs.vpc_id
toFieldPath: status.share.vpcId
policy:
fromFieldPath: Optional
- name: subnet
base:
apiVersion: ec2.aws.upbound.io/v1beta1
kind: Subnet
spec:
forProvider:
region: eu-central-1
cidrBlock: 10.0.0.0/25
patches:
- fromFieldPath: status.share.vpcId
toFieldPath: spec.forProvider.vpcId
policy:
fromFieldPath: Required
32 changes: 32 additions & 0 deletions examples/observe-only-composition/definition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: apiextensions.crossplane.io/v1
kind: CompositeResourceDefinition
metadata:
name: xsubnets.aws.platformref.upbound.io
spec:
group: aws.platformref.upbound.io
names:
kind: XSubnet
plural: xsubnets
versions:
- name: v1alpha1
served: true
referenceable: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
vpcName:
type: string
required:
- vpcName
status:
description: A Status represents the observed state
properties:
share:
description: Freeform field containing status information
type: object
x-kubernetes-preserve-unknown-fields: true
type: object
6 changes: 6 additions & 0 deletions examples/observe-only-composition/xsubnet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: aws.platformref.upbound.io/v1alpha1
kind: XSubnet
metadata:
name: subnet-with-observe-only-vpc
spec:
vpcName: observeonly

0 comments on commit 0d8c3da

Please sign in to comment.