Pulumi Programming Model: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 6: Line 6:
In Pulumi, infrastructure resources are described programmatically in a [[Pulumi_Programming_Model#Program|program]], that gets executed when the <code>[[Pulumi_Operations#Project_Update_Dry_Run|pulumi preview]]</code> and <code>[[Pulumi_Operations#Project_Update|pulumi up]]</code> are run. At the end of the program execution, the '''desired state''' of the infrastructure is built in memory and it is compared with the '''actual state''', pulled from the Pulumi backend, specifically from the state file associated with the active stack the program is being executed in the context of.  
In Pulumi, infrastructure resources are described programmatically in a [[Pulumi_Programming_Model#Program|program]], that gets executed when the <code>[[Pulumi_Operations#Project_Update_Dry_Run|pulumi preview]]</code> and <code>[[Pulumi_Operations#Project_Update|pulumi up]]</code> are run. At the end of the program execution, the '''desired state''' of the infrastructure is built in memory and it is compared with the '''actual state''', pulled from the Pulumi backend, specifically from the state file associated with the active stack the program is being executed in the context of.  


Before any interaction with the infrastructure platform could takes place, Pulumi needs to build a context to maintain a model of the infrastructure resources, as they exist in the infrastructure platform backend - the actual state. That is the [[Pulumi_Concepts#Stack|stack]]. A stack contains metadata and a state file, which has the actual state of the resources in the stack, as known at the moment.
Before any interaction with the infrastructure platform could takes place, Pulumi needs to build a context to maintain a model of the infrastructure resources, as they exist in the infrastructure platform backend - the actual state. That is the [[Pulumi_Concepts#Stack|stack]]. A stack contains metadata and a state file, which has the actual state of the resources in the stack, as known at the moment. This is how [[#Creating_an_Empty_Stack|an empty stack is created]].





Revision as of 23:32, 14 April 2022

Internal

Overview

In Pulumi, infrastructure resources are described programmatically in a program, that gets executed when the pulumi preview and pulumi up are run. At the end of the program execution, the desired state of the infrastructure is built in memory and it is compared with the actual state, pulled from the Pulumi backend, specifically from the state file associated with the active stack the program is being executed in the context of.

Before any interaction with the infrastructure platform could takes place, Pulumi needs to build a context to maintain a model of the infrastructure resources, as they exist in the infrastructure platform backend - the actual state. That is the stack. A stack contains metadata and a state file, which has the actual state of the resources in the stack, as known at the moment. This is how an empty stack is created.


Note that the state file maintained by a stack is a cache of the actual state of the infrastructure platform backend, and it can be synchronized with pulumi refresh.

Depending on delta between the desired state and the actual state, the Pulumi client takes various actions: infrastructure resources are created, updated or deleted. It is the Pulumi client that interacts with the infrastructure platform, so proper access credentials must exist in the environment that runs the Pulumi client.

While the rest of this article uses Python as example, Pulumi offers SDKs for Python, TypeScript and Go.

Creating an Empty Stack

Creating an Infrastructure Resource in Code

Updating an Infrastructure Resource in Code

Importing (Adopting) an Infrastructure Resource

Deleting an Infrastructure Resource in Code

I think there is a misunderstanding here. Apologies if the below info is redundant, but I think we can clear this up. Pulumi uses a statefile to capture a “current” state of resources contained in the current stack, from a physical cloud provider perspective and a pulumi metadata perspective. The statefile is just that, a file or dumb storage that is the result of a pulumi up. When you execute a pulumi up against a Pulumi program, Pulumi is taking the existing statefile (if one exists) and comparing it to the desired state, which is declared by the code in your Pulumi program. So what is happening here is, you’ve imported the resource into your Pulumi state and you’ve not included the resource definition (in code) in your Pulumi program. So when you run a pulumi up Pulumi looks at the statefile, sees the datadog dashboard and compares it with your code, which does not contain the resource definition and correctly determines it needs to delete the resource The Pulumi programming model defines the core concepts in use when creating infrastructure as code programs.

Start with Programming Model https://kb.novaordis.com/index.php/Pulumi_Concepts#Programming_Model as a central place to specify that while the “program” runs, the program builds a model of the infrastructure that is then synchronized with the infrastructure platform. Remove “Code Example” https://kb.novaordis.com/index.php/Pulumi_Concepts#Code_Examples section work out https://kb.novaordis.com/index.php/Python_Pulumi_Code_Examples page into the “Programming Model” Move the content of “Python Pulumi Code Examples” in-line into the “Programming Model” section and resolve the links pointing to the “Python Pulumi Code Examples” Link to https://kb.novaordis.com/index.php/Pulumi_Datadog_DashboardJson#Internal Programming Model. Describe in detail these two models (the second if we don’t want to change anything)


Understand the difference between stack configuration and stack output.