Pulumi Concepts Inputs and Outputs: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Pulumi Concepts =Overview= =Output= An Output encodes the relationship between resources an...")
 
 
(30 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=
* https://www.pulumi.com/docs/intro/concepts/inputs-outputs/
* https://www.pulumi.com/docs/reference/pkg/python/pulumi/#outputs-and-inputs-1
=Internal=
=Internal=
* [[Pulumi_Concepts#Inputs_and_Outputs|Pulumi Concepts]]
* [[Pulumi_Concepts#Inputs_and_Outputs|Pulumi Concepts]]


=Overview=
=Overview=
The Pulumi [[Pulumi_Concepts#Programming_Model|programming model]] includes the concepts of Input and Output values, which model how output of one [[Pulumi_Resource#Overview|resource]] flows in as input of another resource.
<font color=darkkhaki>A stack's input and output is just a particular case of resource input/output, as stack is a resource.</font>


=Output=
=Output=
{{External|https://www.pulumi.com/learn/building-with-pulumi/stack-outputs/}}
{{External|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 [[Pulumi_Concepts_Inputs_and_Outputs#Overview|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|state]], by the backend service. If the stack was not deployed yet, no outputs are available, and the output values are resolved after <code>pulumi up</code> command completes. They can be retrieved via CLI with <code>[[Pulumi_Operations#stack_output|pulumi stack output <property-name>]]</code>, displayed on the console or shared with other stacks, via [[#Stack_References|stack references]]. Exposing an output is called "exporting". This is how it's done in Python:
<syntaxhighlight lang='python'>
import pulumi
...
pulumi.export("something", resource.someAttribute)
pulumi.export("color", "blue")
pulumi.export("details", {"shape": "square", "size": 10})
pulumi.export("whole_resource", resource)
</syntaxhighlight>
⚠️ Hierarchical Python data structures can be provided as the second argument of <code>pulumi.export()</code> and they will be correctly translated to JSON. If the data structure literals are used, both <code>"..."</code> and <code>'...'</code> quotation styles can be used for strings, they will be correctly converted to <code>"..."</code> 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".
<span id='Secret_Values'></span>Some resource properties are handled as secrets, and not displayed as part of the <code>pulumi stack output</code> unless the <code>--show-secrets</code> flag is used.
The value of a stack export can be a regular value, <font color=darkkhaki>an [[Pulumi_Concepts_Inputs_and_Outputs#Output|Output]] or a [[#Promise|Promise]], effectively the same as an [[Pulumi_Concepts_Inputs_and_Outputs#Input|Input]]</font>. They are JSON, <font color=darkkhaki>though quotes are removed when exporting strings</font>. 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:
<syntaxhighlight lang='text'>
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}
</syntaxhighlight>
An Output encodes the relationship between infrastructure [[Pulumi_Concepts#Resource|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 [[Pulumi_Concepts#Stack_Output_.28Exports.29|stack outputs]].
Access to the data being held onto by an Output instance must be done inside a callback, like <code>[[#apply.28.29|apply()]]</code>, which will be called by the runtime if, and when the provider resource has the data available.
<font color=darkkhaki>Understand the difference between stack configuration and stack output, and how they are related.</font>
==Output Access Patterns==
===<tt>apply()</tt>===
{{External|https://www.pulumi.com/docs/intro/concepts/inputs-outputs/#apply}}
==Stack Output Operations==
* [[Pulumi_Operations#Show_Stack_Output_Properties|Show stack output properties]]
* [[Pulumi_Operations#Show_an_Individual_Output_Property|Show an individual output property]]


An Output encodes the relationship between [[Pulumi_Concepts#Resource|resources]] and a Pulumi application, by holding onto a piece of data and the resource it was generated from.
=Input=
=Promise=
=Organizatorium=
<font color=darkkhaki>
* TO PROCESS: https://www.pulumi.com/docs/intro/concepts/inputs-outputs/
* <code>pulumi.Output.concat(...)</code>
* https://github.com/pulumi/pulumi/issues/3722
</font>

Latest revision as of 01:04, 15 April 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

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