-
-
Save HighonAces/93a977a12aa7460c939576a02b2357c4 to your computer and use it in GitHub Desktop.
Composition to create VPC and Subnets
This file contains hidden or 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
| apiVersion: apiextensions.crossplane.io/v1 | |
| kind: Composition | |
| metadata: | |
| name: aws-db-network | |
| labels: | |
| function: kcl | |
| spec: | |
| compositeTypeRef: | |
| apiVersion: db.srujanpakanati.com/v1alpha1 #The API group this composition serves | |
| kind: XDBNetwork # The component name | |
| mode: Pipeline | |
| pipeline: | |
| - step: main | |
| functionRef: | |
| name: function-kcl | |
| input: | |
| apiVersion: krm.kcl.dev/v1alpha1 | |
| kind: KCLRun | |
| spec: | |
| source: | | |
| import regex | |
| oxr = option("params").oxr | |
| ocds = option("params").ocds | |
| _metadata = lambda suffix: str -> any { | |
| { | |
| annotations = { | |
| "krm.kcl.dev/composition-resource-name" = oxr.metadata.name + "-" + suffix | |
| } | |
| } | |
| } | |
| _formatSubnet = lambda s = dict -> str { | |
| "{}-{}-{}".format(s.availabilityZone, _cidrEscaped(s.cidrBlock), s.type) | |
| } | |
| _cidrEscaped = lambda cidr = str -> str { | |
| regex.replace(cidr, "\.|\/", "-") | |
| } | |
| _items = [{ | |
| apiVersion: "ec2.aws.upbound.io/v1beta1" | |
| kind = "VPC" | |
| metadata = _metadata("vpc") | |
| spec.forProvider = { | |
| cidrBlock = oxr.spec.parameters.vpcCidrBlock | |
| enableDnsHostnames = True | |
| enableDnsSupport = True | |
| region = oxr.spec.parameters.region | |
| tags = { | |
| Name = oxr.metadata.name | |
| } | |
| } | |
| }] | |
| _items+= [{ | |
| apiVersion = "ec2.aws.upbound.io/v1beta1" | |
| kind = "Subnet" | |
| metadata = _metadata("subnet-" + _formatSubnet(s)) | |
| spec.forProvider = { | |
| cidrBlock = s.cidrBlock | |
| if s.type == "public": | |
| mapPublicIpOnLaunch = True | |
| region = oxr.spec.parameters.region | |
| vpcIdSelector = { | |
| matchControllerRef = True | |
| } | |
| availabilityZone = s.availabilityZone | |
| } | |
| } for s in oxr.spec.parameters.subnets] | |
| items = _items |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment