Pulumi Concepts Inputs and Outputs: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 2: Line 2:
* https://www.pulumi.com/docs/intro/concepts/inputs-outputs/
* https://www.pulumi.com/docs/intro/concepts/inputs-outputs/
* https://www.pulumi.com/docs/intro/concepts/stack/#outputs
* https://www.pulumi.com/docs/intro/concepts/stack/#outputs
* https://www.pulumi.com/docs/reference/pkg/python/pulumi/#outputs-and-inputs-1


=Internal=
=Internal=

Revision as of 19:11, 17 February 2022

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

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)

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.

Also see:

Stack Outputs

Output Access Patterns

apply()

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

Input

Promise

Organizatorium