Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use the function in a composition #45

Open
passoszup opened this issue Feb 7, 2025 · 0 comments
Open

How to use the function in a composition #45

passoszup opened this issue Feb 7, 2025 · 0 comments

Comments

@passoszup
Copy link

passoszup commented Feb 7, 2025

My vpc is being created in this composition but it will get the value through the ipam id. In this case I need to check whether the subnet entries must follow the same cidr and I am using two functions (three in my case). the expample file did not help me understand my problem. How to use the function to take the cird that the vcn received from ipam and distribute the ranges among my subnets of created types. I'm confused

apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
  name: network.aws.foundation.com
  labels:
    aws.foundation.com/provider: aws
spec:
  compositeTypeRef:
    apiVersion: aws.foundation.com/v1alpha1
    kind: XNetwork
  mode: Pipeline
  pipeline:
    - step: patch-and-transform
      functionRef:
        name: function-patch-and-transform
      input:
        apiVersion: pt.fn.crossplane.io/v1beta1
        kind: Resources
        patchSets:
          - name: common-fields
            patches:
              - type: FromCompositeFieldPath
                fromFieldPath: spec.resourceConfig.accountID
                toFieldPath: spec.providerConfigRef.name
                transforms:
                  - type: string
                    string:
                      type: Format
                      fmt: "aws-provider-config-%s"
              - type: FromCompositeFieldPath
                fromFieldPath: spec.resourceConfig.region
                toFieldPath: spec.forProvider.region
        resources:
          # Create VPC with specified CIDR
          - name: VPN-NETWORK
            base:
              apiVersion: ec2.aws.upbound.io/v1beta1
              kind: VPC
              spec:
                forProvider:
                  enableDnsSupport: true
                  enableDnsHostnames: true
            patches:
              - type: PatchSet
                patchSetName: common-fields
              - type: FromCompositeFieldPath
                fromFieldPath: spec.ipamPoolId
                toFieldPath: spec.forProvider.ipv4IpamPoolId
              - type: FromCompositeFieldPath
                fromFieldPath: spec.NetmaskLength
                toFieldPath: spec.forProvider.ipv4NetmaskLength
              - type: ToCompositeFieldPath
                fromFieldPath: status.atProvider.id
                toFieldPath: status.vpcId
              - type: ToCompositeFieldPath
                fromFieldPath: status.atProvider.cidrBlock
                toFieldPath: status.vpcCidr  # vpc ipam
              - type: FromCompositeFieldPath
                fromFieldPath: spec.resourceConfig.tags
                toFieldPath: spec.forProvider.tags
```
         
          ```
# Conditional VPCIPv4CidrBlockAssociation for additional CIDR
          - name: vpc-ipv4-cidr-association
            base:
              apiVersion: ec2.aws.upbound.io/v1beta1
              kind: VPCIPv4CidrBlockAssociation
              spec:
                forProvider:
                  cidrBlock: "10.144.0.0/16"
            patches:
              - type: PatchSet
                patchSetName: common-fields
              - type: FromCompositeFieldPath
                fromFieldPath: "status.vpcId"
                toFieldPath: "spec.forProvider.vpcId"
              - type: ToCompositeFieldPath
                fromFieldPath: status.atProvider.cidrBlockAssociationId
                toFieldPath: status.cidrAssociationId

################ INTERNET GATEWAY ###############################
          # Internet Gateways for Subnet public
          - name: Internet-Gateway
            base:
              apiVersion: ec2.aws.upbound.io/v1beta1
              kind: InternetGateway
              spec:
                forProvider:
                  tags:
                    Name: Internet-Gateway
            patches:
              - type: PatchSet
                patchSetName: common-fields
              - type: FromCompositeFieldPath
                fromFieldPath: "status.vpcId"
                toFieldPath: "spec.forProvider.vpcId"
              - type: ToCompositeFieldPath
                fromFieldPath: status.atProvider.id
                toFieldPath: status.internetGatewayId

############## SUBNET PUBLIC'S ########################
          # Create Public Subnet 1A
          - name: Public-Subnet-1A 
            base: 
              apiVersion: aws.foundation.com/v1alpha1
              kind: XSubnet
              spec:
                subnetType: public
                availabilityZone: "sa-east-1a"
                tags:
                    Name: Public-Subnet-1A
            patches:
              - type: FromCompositeFieldPath
                fromFieldPath: spec.resourceConfig.region
                toFieldPath: spec.resourceConfig.region
              - type: FromCompositeFieldPath
                fromFieldPath: spec.resourceConfig.accountID
                toFieldPath: spec.resourceConfig.accountID
              - type: FromCompositeFieldPath
                fromFieldPath: status.internetGatewayId
                toFieldPath: spec.destination.gatewayId
              - type: ToCompositeFieldPath
                fromFieldPath: status.atProvider.irouteTableId
                toFieldPath: status.routeTableIdpublic1a
              - type: FromCompositeFieldPath
                fromFieldPath: status.vpcId
                toFieldPath: spec.vpcId
              - type: FromCompositeFieldPath
                fromFieldPath: status.atFunction.cidr
                toFieldPath: spec.cidrBlock

    
    - step: cidr-subnets-partitions
      functionRef:
        name: upbound-function-cidr
      input:
        apiVersion: cidr.fn.crossplane.io/v1beta1
        kind: Parameters
        cidrFunc: cidrsubnets
        prefixField: desired.composite.resource.status.vpcCidr  # Block CIDR from vpc
        newBits: [1, 1, 1]  # 3 subnets (/25 cada)
        outputField: status.atFunction.cidr # output in status.partitions`
```
            
     
"Message:               cannot compose resources: pipeline step "cidr-subnets-partitions" returned a fatal result: invalid Function input: parameters: Required value: invalid CIDR prefix address desired.composite.resource.status.vpcCidr"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant