Pulumi Automation API: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 8: Line 8:
An inline Pulumi program example is available here: https://github.com/pulumi/automation-api-examples/tree/main/python/inline_program
An inline Pulumi program example is available here: https://github.com/pulumi/automation-api-examples/tree/main/python/inline_program
=Programming Model=
=Programming Model=
<syntaxhighlight lang='py'>
import pulumi
def pulumi_program():
    pass
org_name="my-org"
project_name ="my-project"
stack_name ="my-stack"
qualified_stack_name = f'{org_name}/{stack_name}'
pulumi_stack = pulumi.automation.create_or_select_stack(
  stack_name=qualified_stack_name,
  project_name=project_name,
  program=pulumi_program) # a valid function must be passed here, 'None' does not work
print(f'successfully initialized stack {pulumi_stack}')
pulumi_stack.preview(on_output=print)
print(pulumi_stack.outputs())
pulumi.Output.all()
</syntaxhighlight>
==<tt>stack.outputs()</tt>==
<code>stack.outputs()</code> returns a map of strings to <code>OutputValue</code>s. To get the value from the <code>OutputValue</code> instance, use the <code>value</code> member variable:
<syntaxhighlight lang='py'>
m = pulumi_stack.outputs()
value = m.get('some_key').value
</syntaxhighlight>

Latest revision as of 03:47, 5 March 2022

External

Internal

Overview

An inline Pulumi program example is available here: https://github.com/pulumi/automation-api-examples/tree/main/python/inline_program

Programming Model

import pulumi

def pulumi_program():
    pass

org_name="my-org"
project_name ="my-project"
stack_name ="my-stack"
qualified_stack_name = f'{org_name}/{stack_name}'
pulumi_stack = pulumi.automation.create_or_select_stack(
  stack_name=qualified_stack_name,
  project_name=project_name,
  program=pulumi_program) # a valid function must be passed here, 'None' does not work
print(f'successfully initialized stack {pulumi_stack}')
pulumi_stack.preview(on_output=print)
print(pulumi_stack.outputs())
pulumi.Output.all()

stack.outputs()

stack.outputs() returns a map of strings to OutputValues. To get the value from the OutputValue instance, use the value member variable:

m = pulumi_stack.outputs()
value = m.get('some_key').value