From 72e77464c71ce6da32a0ad0ecb3e02f5ac048101 Mon Sep 17 00:00:00 2001 From: Yury Tsarev Date: Fri, 7 Oct 2022 00:34:23 +0200 Subject: [PATCH] Example of observe-only workaround experiment Provides a temporary solution to the observe-only problem using provider-terraform. See https://github.com/crossplane/crossplane/issues/1722 Signed-off-by: Yury Tsarev --- examples/observe-only-composition/README.md | 16 ++++++ .../observe-only-composition/composition.yaml | 57 +++++++++++++++++++ .../observe-only-composition/definition.yaml | 32 +++++++++++ .../observe-only-composition/xsubnet.yaml | 6 ++ 4 files changed, 111 insertions(+) create mode 100644 examples/observe-only-composition/README.md create mode 100644 examples/observe-only-composition/composition.yaml create mode 100644 examples/observe-only-composition/definition.yaml create mode 100644 examples/observe-only-composition/xsubnet.yaml diff --git a/examples/observe-only-composition/README.md b/examples/observe-only-composition/README.md new file mode 100644 index 0000000..6f4036f --- /dev/null +++ b/examples/observe-only-composition/README.md @@ -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`. diff --git a/examples/observe-only-composition/composition.yaml b/examples/observe-only-composition/composition.yaml new file mode 100644 index 0000000..9962fae --- /dev/null +++ b/examples/observe-only-composition/composition.yaml @@ -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 diff --git a/examples/observe-only-composition/definition.yaml b/examples/observe-only-composition/definition.yaml new file mode 100644 index 0000000..a12029e --- /dev/null +++ b/examples/observe-only-composition/definition.yaml @@ -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 diff --git a/examples/observe-only-composition/xsubnet.yaml b/examples/observe-only-composition/xsubnet.yaml new file mode 100644 index 0000000..0b4364d --- /dev/null +++ b/examples/observe-only-composition/xsubnet.yaml @@ -0,0 +1,6 @@ +apiVersion: aws.platformref.upbound.io/v1alpha1 +kind: XSubnet +metadata: + name: subnet-with-observe-only-vpc +spec: + vpcName: observeonly