forked from upbound/function-azresourcegraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resource import example (upbound#18)
* Resource import example * Get the data from az resource graph * Drive the import with function-kcl Signed-off-by: Yury Tsarev <[email protected]> * Handle the case of empty query result Signed-off-by: Yury Tsarev <[email protected]> --------- Signed-off-by: Yury Tsarev <[email protected]>
- Loading branch information
Showing
4 changed files
with
131 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,3 @@ | ||
.PHONY: render | ||
render: | ||
crossplane render ../xr.yaml composition.yaml ./functions.yaml --function-credentials=../secrets/azure-creds.yaml -rc |
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,61 @@ | ||
apiVersion: apiextensions.crossplane.io/v1 | ||
kind: Composition | ||
metadata: | ||
name: function-azresourcegraph | ||
spec: | ||
compositeTypeRef: | ||
apiVersion: example.crossplane.io/v1 | ||
kind: XR | ||
mode: Pipeline | ||
pipeline: | ||
- step: query-azresourcegraph | ||
functionRef: | ||
name: function-azresourcegraph | ||
input: | ||
apiVersion: azresourcegraph.fn.crossplane.io/v1alpha1 | ||
kind: Input | ||
query: | | ||
Resources | ||
| where type == "microsoft.network/virtualnetworks" | ||
| where tags["import"] == "me" | ||
| project name, resourceGroup, location | ||
target: "context.azResourceGraphQueryResult" | ||
credentials: | ||
- name: azure-creds | ||
source: Secret | ||
secretRef: | ||
namespace: upbound-system | ||
name: azure-account-creds | ||
|
||
- step: import-as-observe-only | ||
functionRef: | ||
name: function-kcl | ||
input: | ||
apiVersion: krm.kcl.dev/v1alpha1 | ||
kind: KCLInput | ||
spec: | ||
source: | | ||
queryResult = option("params").ctx.azResourceGraphQueryResult | ||
assert len(queryResult) > 0, "Azure Resource Graph query returned no results. Verify the query criteria." | ||
importName = queryResult[0].name | ||
importRgName = queryResult[0].resourceGroup | ||
importLocation = queryResult[0].location | ||
network = { | ||
apiVersion = "network.azure.upbound.io/v1beta2" | ||
kind = "VirtualNetwork" | ||
metadata.annotations = { | ||
"crossplane.io/external-name" = importName | ||
} | ||
metadata.name = importName | ||
spec.managementPolicies = ["Observe"] | ||
spec.forProvider = { | ||
resourceGroupName = importRgName | ||
location = importLocation | ||
} | ||
} | ||
items = [network] | ||
- step: automatically-detect-ready-composed-resources | ||
functionRef: | ||
name: function-auto-ready |
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,43 @@ | ||
apiVersion: apiextensions.crossplane.io/v1 | ||
kind: CompositeResourceDefinition | ||
metadata: | ||
name: xrs.example.crossplane.io | ||
spec: | ||
group: example.crossplane.io | ||
names: | ||
categories: | ||
- crossplane | ||
kind: XR | ||
plural: xrs | ||
versions: | ||
- name: v1 | ||
referenceable: true | ||
schema: | ||
openAPIV3Schema: | ||
description: XR is the Schema for the XR API. | ||
properties: | ||
spec: | ||
description: XRSpec defines the desired state of XR. | ||
type: object | ||
status: | ||
description: XRStatus defines the observed state of XR. | ||
type: object | ||
properties: | ||
azResourceGraphQueryResult: | ||
description: Freeform field containing query results from function-azresourcegraph | ||
type: array | ||
items: | ||
type: object | ||
x-kubernetes-preserve-unknown-fields: true | ||
required: | ||
- spec | ||
type: object | ||
served: true | ||
status: | ||
controllers: | ||
compositeResourceClaimType: | ||
apiVersion: "" | ||
kind: "" | ||
compositeResourceType: | ||
apiVersion: "" | ||
kind: "" |
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,24 @@ | ||
--- | ||
apiVersion: pkg.crossplane.io/v1beta1 | ||
kind: Function | ||
metadata: | ||
name: function-azresourcegraph | ||
annotations: | ||
# This tells crossplane beta render to connect to the function locally. | ||
#render.crossplane.io/runtime: Development | ||
spec: | ||
package: xpkg.upbound.io/upbound/function-azresourcegraph:v0.4.0 | ||
--- | ||
apiVersion: pkg.crossplane.io/v1beta1 | ||
kind: Function | ||
metadata: | ||
name: function-kcl | ||
spec: | ||
package: xpkg.upbound.io/crossplane-contrib/function-kcl:v0.11.0 | ||
--- | ||
apiVersion: pkg.crossplane.io/v1beta1 | ||
kind: Function | ||
metadata: | ||
name: function-auto-ready | ||
spec: | ||
package: xpkg.upbound.io/crossplane-contrib/function-auto-ready:v0.4.0 |