-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
__init__.py
251 lines (219 loc) 路 7.43 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# Copyright 2016-2022, Pulumi Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
The automation module contains the Pulumi Automation API, the programmatic interface for driving Pulumi programs
without the CLI.
Generally this can be thought of as encapsulating the functionality of the CLI (`pulumi up`, `pulumi preview`,
`pulumi destroy`, `pulumi stack init`, etc.) but with more flexibility. This still requires a
CLI binary to be installed and available on your $PATH.
In addition to fine-grained building blocks, Automation API provides two out of the box ways to work with Stacks:
1. Programs locally available on-disk and addressed via a filepath (local source)::
```python
stack = create_stack("myOrg/myProj/myStack", work_dir=os.path.join("..", "path", "to", "project"))
```
2. Programs defined as a function alongside your Automation API code (inline source)::
```python
def pulumi_program():
bucket = s3.Bucket("bucket")
pulumi.export("bucket_name", bucket.Bucket)
stack = create_stack("myOrg/myProj/myStack", program=pulumi_program)
```
Each of these creates a stack with access to the full range of Pulumi lifecycle methods
(up/preview/refresh/destroy), as well as methods for managing config, stack, and project settings::
stack.set_config("key", ConfigValue(value="value", secret=True))
preview_response = stack.preview()
The Automation API provides a natural way to orchestrate multiple stacks,
feeding the output of one stack as an input to the next as shown in the package-level example below.
The package can be used for a number of use cases:
- Driving pulumi deployments within CI/CD workflows
- Integration testing
- Multi-stage deployments such as blue-green deployment patterns
- Deployments involving application code like database migrations
- Building higher level tools, custom CLIs over pulumi, etc.
- Using pulumi behind a REST or GRPC API
- Debugging Pulumi programs (by using a single main entrypoint with "inline" programs)
To enable a broad range of runtime customization the API defines a `Workspace` interface.
A Workspace is the execution context containing a single Pulumi project, a program, and multiple stacks.
Workspaces are used to manage the execution environment, providing various utilities such as plugin
installation, environment configuration ($PULUMI_HOME), and creation, deletion, and listing of Stacks.
Every Stack including those in the above examples are backed by a Workspace which can be accessed via::
ws = stack.workspace()
ws.install_plugin("aws", "v3.20.0")
Workspaces can be explicitly created and customized beyond the three Stack creation helpers noted above::
ws = LocalWorkspace(work_dir=os.path.join(".", "project", "path"), pulumi_home="~/.pulumi")
stack = create_stack("org/proj/stack", ws)
A default implementation of workspace is provided as `LocalWorkspace`. This implementation relies on Pulumi.yaml
and Pulumi.[stack].yaml as the intermediate format for Project and Stack settings. Modifying ProjectSettings will
alter the Workspace Pulumi.yaml file, and setting config on a Stack will modify the Pulumi.[stack].yaml file.
This is identical to the behavior of Pulumi CLI driven workspaces. Custom Workspace
implementations can be used to store Project and Stack settings as well as Config in a different format,
such as an in-memory data structure, a shared persistent SQL database, or cloud object storage. Regardless of
the backing Workspace implementation, the Pulumi SaaS Console will still be able to display configuration
applied to updates as it does with the local version of the Workspace today.
The Automation API also provides error handling utilities to detect common cases such as concurrent update
conflicts::
try:
up_response = stack.up()
except ConcurrentUpdateError:
{ /* retry logic here */ }
"""
from pulumi.automation._remote_workspace import (
RemoteWorkspaceOptions,
RemoteGitAuth,
create_remote_stack_git_source,
create_or_select_remote_stack_git_source,
select_remote_stack_git_source,
)
from pulumi.automation._remote_stack import RemoteStack
from ._cmd import CommandResult, OnOutput
from ._config import ConfigMap, ConfigValue
# pylint: disable=redefined-builtin
from .errors import (
StackNotFoundError,
StackAlreadyExistsError,
CommandError,
ConcurrentUpdateError,
InlineSourceRuntimeError,
RuntimeError,
CompilationError,
InvalidVersionError,
)
from .events import (
CancelEvent,
DiagnosticEvent,
DiffKind,
EngineEvent,
PolicyEvent,
PreludeEvent,
PropertyDiff,
ResOutputsEvent,
ResourcePreEvent,
ResOpFailedEvent,
StdoutEngineEvent,
StepEventStateMetadata,
StepEventMetadata,
SummaryEvent,
OpMap,
OpType,
)
from ._local_workspace import (
LocalWorkspace,
LocalWorkspaceOptions,
Secret,
create_stack,
select_stack,
create_or_select_stack,
)
from ._workspace import (
PluginInfo,
StackSummary,
PulumiFn,
Workspace,
WhoAmIResult,
Deployment,
)
from ._output import OutputMap, OutputValue
from ._project_settings import (
ProjectBackend,
ProjectSettings,
ProjectRuntimeInfo,
)
from ._stack_settings import StackSettings
from ._stack import (
OnEvent,
Stack,
UpdateSummary,
UpResult,
PreviewResult,
RefreshResult,
DestroyResult,
fully_qualified_stack_name,
)
__all__ = [
# _cmd
"CommandResult",
"OnOutput",
# _config
"ConfigMap",
"ConfigValue",
# errors
"StackNotFoundError",
"StackAlreadyExistsError",
"CommandError",
"ConcurrentUpdateError",
"InlineSourceRuntimeError",
"RuntimeError",
"CompilationError",
"InvalidVersionError",
# events
"CancelEvent",
"DiagnosticEvent",
"DiffKind",
"EngineEvent",
"PolicyEvent",
"PreludeEvent",
"PropertyDiff",
"ResOutputsEvent",
"ResourcePreEvent",
"ResOpFailedEvent",
"StdoutEngineEvent",
"StepEventStateMetadata",
"StepEventMetadata",
"SummaryEvent",
"OpType",
"OpMap",
# _local_workspace
"LocalWorkspace",
"LocalWorkspaceOptions",
"Secret",
"create_stack",
"select_stack",
"create_or_select_stack",
# _workspace
"PluginInfo",
"StackSummary",
"PulumiFn",
"Workspace",
"Deployment",
"WhoAmIResult",
# _output
"OutputMap",
"OutputValue",
# _project_settings
"ProjectBackend",
"ProjectSettings",
"ProjectRuntimeInfo",
# _stack_settings
"StackSettings",
# _stack
"OnEvent",
"Stack",
"UpdateSummary",
"UpResult",
"PreviewResult",
"RefreshResult",
"DestroyResult",
"fully_qualified_stack_name",
# _remote_workspace
"RemoteWorkspaceOptions",
"RemoteGitAuth",
"create_remote_stack_git_source",
"create_or_select_remote_stack_git_source",
"select_remote_stack_git_source",
# _remote_stack
"RemoteStack",
# sub-modules
"errors",
"events",
]