Skip to main content

2. Build your composition logic

In the previous guide, you created a brand new project and reviewed the foundational components of your project. This guide walks through how to update those components to create real resources in your Upbound organization.

Prerequisites​

Make sure you've completed the previous guide and have:

If you missed any of the previous steps, go to the project foundations guide to get started.

Generate a function​

Composition functions allow you to write the logic for creating cloud resources with programming languages like KCL, Python, or Go.

With composition functions you can:

  • Write code with familiar programming concepts like variables, loops, and conditions
  • Catch errors with type safety before deployment
  • Keep related logic together in an easier to parse format
  • Test your infrastructure logic like any other code

Your composition function is a program you write that translates your user's requests as the inputs and returns specific cloud resources as the outputs.

Generate the composition function scaffolding and choose your preferred language:

This command creates a function directory and creates a new file based on your chosen language.

Create your function logic​

Next, create the actual program logic that builds your cloud resources.

Save your composition file.

Review your function​

Resource imports and user inputs​

Metadata and helper functions​

This section:

  • Standardizes resource naming
  • Adds required labels and annotations where needed
  • Leverages helper functions to sanitize naming where applicable
  • Reduces metadata duplication

Cloud resource definition​

This section:

  • Creates the primary resource for your chosen cloud provider
  • Inserts your claim parameters as required fields
  • Applies the metadata function to the resource

Security configuration​

This section:

  • Applies object ownership to the bucket
  • Allows for public access to the bucket

Access control and encryption​

This section:

  • Sets the access level using the user's ACL parameter
  • Automatically enables encryption for all objects

Bucket versioning​

This section:

  • Only creates versioning if requested in the claim
  • Captures the items defined in the function as a single variable.

Save your changes.

Render your composition locally​

The up composition render command allows you to review your desired composed resources.

Render the composition against your XR file:

up composition render apis/storagebuckets/composition.yaml examples/storagebucket/example.yaml

This process ensures the build, configuration, and orchestration runs as expected before you deploy to a development control plane.

Errors in the render command can indicate a malformed function or other issues within the composition itself.

Next steps​

You constructed a new embedded function that allows user input from your claim file. This function uses your composition to create a fully configured storage resources to your specifications.

The next guide walks through how to test your composition function logic with the built-in test suite.