generated from crossplane/provider-template
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example of observe-only workaround experiment
Provides a temporary solution to the observe-only problem using provider-terraform. See crossplane/crossplane#1722 Signed-off-by: Yury Tsarev <[email protected]>
- Loading branch information
Showing
4 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |