-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.k
77 lines (70 loc) · 2.42 KB
/
main.k
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import models.io.upbound.azure.network.v1beta1 as networkv1beta1
import models.io.upbound.azure.network.v1beta2 as networkv1beta2
import models.io.upbound.azure.v1alpha1 as azurev1alpha1
import models.io.upbound.azure.v1beta1 as azurev1beta1
import models.io.upbound.platform.azure.v1alpha1 as platformazurev1alpha1
import models.k8s.apimachinery.pkg.apis.meta.v1 as metav1
# observed composite resource
oxr = platformazurev1alpha1.XNetwork{**option("params").oxr}
params = oxr.spec.parameters
# observed composed resources
_ocds = option("params").ocds
# desired composite resource
_dxr = option("params").dxr
# desired composed resources
dcds = option("params").dcds
_metadata = lambda name: str -> any {
{
name = name
annotations = {"krm.kcl.dev/composition-resource-name" = name}
labels = {"azure.platform.upbound.io/network-id" = params.id}
}
}
# Helper function to add common spec fields
_add_common_spec_fields = lambda spec: any -> any {
spec | {
deletionPolicy = params.deletionPolicy
providerConfigRef.name = params.providerConfigName
}
}
_items = [
# Resource Group
azurev1beta1.ResourceGroup {
metadata = _metadata("${params.id}-rg")
spec = _add_common_spec_fields(azurev1beta1.AzureUpboundIoV1beta1ResourceGroupSpec {
forProvider = {
location = params.region
}
})
}
# Virtual Network
networkv1beta2.VirtualNetwork {
metadata = _metadata("${params.id}-vnet")
spec = _add_common_spec_fields(networkv1beta2.NetworkAzureUpboundIoV1beta2VirtualNetworkSpec {
forProvider = {
location = params.region
addressSpace = ["192.168.0.0/16"]
resourceGroupNameSelector = {
matchControllerRef = True
}
}
})
}
# Subnet
networkv1beta2.Subnet {
metadata = _metadata("${params.id}-sn")
spec = _add_common_spec_fields(networkv1beta2.NetworkAzureUpboundIoV1beta2SubnetSpec {
forProvider = {
addressPrefixes = ["192.168.1.0/24"]
resourceGroupNameSelector = {
matchControllerRef = True
}
serviceEndpoints = ["Microsoft.Sql"]
virtualNetworkNameSelector = {
matchControllerRef = True
}
}
})
}
]
items = _items