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

Enhance Pulumi StackReference Interface with Typed Outputs #527

Open
lbialy opened this issue Jun 27, 2024 · 0 comments
Open

Enhance Pulumi StackReference Interface with Typed Outputs #527

lbialy opened this issue Jun 27, 2024 · 0 comments
Assignees
Labels
area/api User visible API area/core The SDK's core code impact/usability Something that impacts users' ability to use the product easily and intuitively kind/enhancement New feature or request without workaround size/M Estimated effort to complete (up to 5 days).
Milestone

Comments

@lbialy
Copy link
Collaborator

lbialy commented Jun 27, 2024

Description:

The current StackReference in Pulumi uses a stringly typed interface that necessitates calling getOutput(key: String) to retrieve an Output[Option[JsValue]] and requireOutput(key: String) to fetch an Output[JsValue]. Both methods demand manual type conversion from JsValue, which is error-prone.

Issue:

Develop a type-safe API that allows direct deserialization into predefined types, maintaining backward compatibility with the existing API.

Proposed Solution:

Let's assume this case class as representation of outputs of a referred stack:

case class Platform(kubeconfig: String, nodes: List[String])

Simple variant:

Implement a semiauto derivation pattern for the StackReferenceOutputs typeclass to manage serialization while allowing for customizations. Add a method to StackReference that provides typed outputs directly:

def outputs[A: StackReferenceOutputs]: Output[A]

More involved variant:

Introduce a new API for StackReference that supports typed outputs through a generic type parameter. Define a Platform case class for expected outputs like kubeconfig and nodes.

case class Platform(kubeconfig: String, nodes: List[String])

Adapt the StackReferenceFactory to use type classes for deserialization.

trait StackReferenceOutputs[A]:
  def decode(ref: StackReference): Output[TypedStackReference[A]]

trait StackReferenceFactory:
  def apply[T](using Context, StackReferenceOutputs[T])(
    name: NonEmptyString,
    args: Input.Optional[StackReferenceArgs] = None,
    opts: StackReferenceResourceOptions = StackReferenceResourceOptions()
  ): Output[TypedStackReference[T]]
@lbialy lbialy added kind/enhancement New feature or request without workaround area/core The SDK's core code impact/usability Something that impacts users' ability to use the product easily and intuitively size/M Estimated effort to complete (up to 5 days). area/api User visible API labels Jun 27, 2024
@lbialy lbialy added this to the 0.4.0 milestone Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api User visible API area/core The SDK's core code impact/usability Something that impacts users' ability to use the product easily and intuitively kind/enhancement New feature or request without workaround size/M Estimated effort to complete (up to 5 days).
Projects
None yet
Development

No branches or pull requests

2 participants