Pulumi Concepts Inputs and Outputs

From NovaOrdis Knowledge Base
Revision as of 01:04, 15 April 2022 by Ovidiu (talk | contribs) (→‎Output)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

External

Internal

Overview

The Pulumi programming model includes the concepts of Input and Output values, which model how output of one resource flows in as input of another resource.


A stack's input and output is just a particular case of resource input/output, as stack is a resource.

Output

https://www.pulumi.com/learn/building-with-pulumi/stack-outputs/
https://www.pulumi.com/docs/intro/concepts/stack/#outputs

A stack can be turned into a component that integrates with other components. The way Pulumi programs communicate information for external consumption and integration with other stacks is by using outputs, or exports. Outputs are values produced during an update and can be thought as programmatic results of a stack update, additional to the infrastructure resources created in the infrastructure platform. They are also known as "properties". They are maintained as part of the stack's state, by the backend service. If the stack was not deployed yet, no outputs are available, and the output values are resolved after pulumi up command completes. They can be retrieved via CLI with pulumi stack output <property-name>, displayed on the console or shared with other stacks, via stack references. Exposing an output is called "exporting". This is how it's done in Python:

import pulumi
...
pulumi.export("something", resource.someAttribute)
pulumi.export("color", "blue")
pulumi.export("details", {"shape": "square", "size": 10})
pulumi.export("whole_resource", resource)

⚠️ Hierarchical Python data structures can be provided as the second argument of pulumi.export() and they will be correctly translated to JSON. If the data structure literals are used, both "..." and '...' quotation styles can be used for strings, they will be correctly converted to "..." in JSON. In this case, DO NOT enclose the entire structure in quotes, otherwise it will be handled as a string.

⚠️ Do not use dashes in keys, jq is having problems with them. Use "_" instead. Use "some_stuff" instead of "some-stuff".

Some resource properties are handled as secrets, and not displayed as part of the pulumi stack output unless the --show-secrets flag is used.

The value of a stack export can be a regular value, an Output or a Promise, effectively the same as an Input. They are JSON, though quotes are removed when exporting strings. An entire resource can be exported, and if that happens, it will be serialized as JSON. For example, if a SSM parameter is exported, it will be available as:

whole_resource   {"allowed_pattern":"","arn":"arn:aws:ssm:us-west-2:999999999999:parameter/experimental/ovidiu/test2-382b9f1","data_type":"text","description":"","id":null,"key_id":"","name":"/experimental/ovidiu/test2-382b9f1","overwrite":null,"tags":{},"tags_all":{},"tier":"Standard","type":"String","urn":"urn:pulumi:ssm::blue::aws:ssm/parameter:Parameter::/experimental/ovidiu/test2","value":null,"version":1}

An Output encodes the relationship between infrastructure resources and a Pulumi application, by holding onto a piece of data and the resource it was generated from. When a consumer resource needs a piece of data generated by a provider resource, the consumer resource gets the Output of the provider resource, allowing it to know both the data value, and the provider resource it came from. This allows building a resource dependency graph, which Pulumi used to track dependencies between resources.

Stacks behave like any other resource, they are capable of producing data to be exported to other stacks, which access the data as stack outputs.

Access to the data being held onto by an Output instance must be done inside a callback, like apply(), which will be called by the runtime if, and when the provider resource has the data available.

Understand the difference between stack configuration and stack output, and how they are related.

Output Access Patterns

apply()

https://www.pulumi.com/docs/intro/concepts/inputs-outputs/#apply

Stack Output Operations

Input

Promise

Organizatorium