Overview
Walk around the code first
Before processing, feel free to do Rust tutorial, open code in your IDE, walk through it and check abstractions behind Output and generated provider.
Abstractions
The Pulumi Gestalt SDK provides abstractions for working with Pulumi in a structured way. It is built around three core concepts:
- Context: Represents a single execution environment for Pulumi operations. It is not recommended to use a global context, as doing so may limit compatibility with advanced features like the Pulumi Automation API.
- Output: Represents values that are resolved asynchronously (e.g., cloud resource outputs).
- CompositeOutput: Represents a map of outputs returned by a resource or function.
Context
The Context abstraction manages the lifecycle of Pulumi operations. It includes the following methods:
create_context: Initializes a new context. This should be called at the start of your program.finish: Executes all registered operations. Call this before destroying the context.destroy_context: Cleans up the context. This should be called at the end of your program.register_resource: Registers a new resource in the context.invoke_resource: Invokes a resource (also referred to as afunction).add_export: Add output as stack output.
Output
The Output abstraction is used to work with values that are not immediately available (e.g., cloud resource outputs). It provides the following methods:
create_output: Creates anOutputfrom a known value.map: Applies a function to transform the value inside anOutput.combine: Combines multipleOutputobjects into a singleOutput.
Abstraction Levels for Output::map
The Output::map function is implemented at different levels of abstraction depending on the language or integration:
High Level
- Description: Pass a function of type
T1 -> T2toOutput::map. - Examples: Rust language.
Medium Level
- Description: Pass a function of type
String -> StringtoOutput::mapwhereStringis a serialized JSON value. - Examples: C FFI, Rust integration.
Low Level
- Description: Pass a function id to
Output::mapand receive it later. - Examples: Wasm.
CompositeOutput
register_resource and invoke_resource return a CompositeOutput object. This object is an abstration over map containing resource/function outputs.
For example Docker image will have 7 - baseImageName, context, dockerfile, id, registryServer, repoDigest and platform.
Object has the following methods:
get_field: Get output of map field value