Skip to content

Resource

A resource is a piece of infrastructure that formae manages—like an S3 bucket, EC2 instance, or database. Each resource has properties and behaviors specific to its type.

Resources are implemented through plugins that translate between formae's abstract resource definitions and the actual cloud provider APIs. This allows formae to work with different technologies through a consistent interface.

Resource References

Resources can reference other resources and their properties using .res notation. This makes it easy to connect resources together, regardless of which cloud provider or technology you're using. Under the hood, resolvables (see Res) make these references work.

Note: The examples below use the local pattern to create variables for resources that need to be referenced later. This allows you to use .res to access their properties. Learn more about this pattern in Formae 101 - Fundamentals.

Example:

local myVpc = new vpc.VPC {
  label = "main-vpc"
  cidrBlock = "10.0.0.0/16"
}

myVpc  // Instantiate the resource

new subnet.Subnet {
  label = "public-subnet"
  vpcId = myVpc.res.id  // Reference the VPC's ID
  cidrBlock = "10.0.1.0/24"
}

In this example, the subnet references the VPC's ID using .res.id. formae automatically handles the dependency and ensures the VPC is created first.

Another example with S3 and IAM:

local myBucket = new bucket.Bucket {
  label = "app-bucket"
  bucketName = "my-app-bucket"
}

myBucket

new policy.Policy {
  label = "bucket-policy"
  policyDocument {
    ["Resource"] = myBucket.res.arn  // Reference the bucket's ARN
  }
}

Note: Learn more about how resource references work in the Res concept page.