Skip to main content

Components

Pulumi allows users to define their own logical aggregations of resources called components and so does Besom. The API is a bit different in comparison to other Pulumi SDKs. User is expected to define a case class that will contain all the Output properties one wants to expose from the internals of the component.

The case class has to:

  1. extend besom.ComponentResource trait
  2. have a (using ComponentBase) clause after it's primary constructor
  3. have a derives RegistersOutputs at the end of it's class declaration

Next step is to declare a function that will use the component constructor function to compose all the resources together. Every component expects:

Here's a small example using the S3 bucket resource again:

import besom.*
import besom.api.aws
import java.time.OffsetDateTime

case class ZooVisit(
catPicsUrl: Output[String],
parrotPicsUrl: Output[String]
)(using ComponentBase)
extends ComponentResource
derives RegistersOutputs
object ZooVisit:
def apply(date: OffsetDateTime)(using Context): Output[ZooVisit] =
component(s"zoo-visit-at-$date", "user:component:ZooVisit") {
val cats = aws.s3.Bucket(s"cats-$date")
val parrots = aws.s3.Bucket(s"parrot-$date")
ZooVisit(cats.websiteEndpoint, parrots.websiteEndpoint)
}

@main def main = Pulumi.run {
val visit = ZooVisit(OffsetDateTime.now())

Stack.exports(
cats = visit.map(_.catPicsUrl),
parrots = visit.map(_.parrotPicsUrl)
)
}