3bcbe35c0a
10832: Hierarchical and structured config implementation: the initial pass r=Zaid-Ajaj a=Zaid-Ajaj # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> This implements the initial pass of hierarchical and structured config which fixes #10602. This changes the CLI such that configuration can now be defined at the _project_ level using a `config` block. The configuration values defined here are inherited by all the stacks and made available to the Pulumi program without having to duplicate values in every stack (hence hierarchical) and the values are also typed / structured. Example Project.yaml syntax: ```yaml name: config-test runtime: dotnet config: instanceSize: type: string default: t3.micro instanceCount: type: integer default: 5 ``` This can also be rewritten using short-hand syntax and will be equivalent to the above ```yaml name: config-test runtime: dotnet config: instanceSize: t3.micro instanceCount: 5 ``` The complex types allowed for now are only arrays and nested arrays: ```yaml name: config-test runtime: dotnet config: availabilityZones: type: array items: type: string default: [us-east-1-atl-1a, us-east-1-chi-1a] ``` - Project-level configuration values that do not have a default value _MUST_ be defined at the stack level - Stack configuration values are type-checked against their defined type in the project file i.e. Pulumi.yaml - Short-hand syntax only accepts primitive values (no arrays for now) - Accepted config types are a subset of a JSON schema where the property `type: string | integer | boolean | array` is expected. When `type: array` then a config block must also have property `items` which defines the type of array elements (can be nested) - Running `pulumi config` will list the configuration values from the selected stack _AND_ the values inherited from the project - After a successful `pulumi up` run using hierarchical config from the project, `pulumi config refresh` will write _ALL_ the used config back to the refreshed stack - `pulumi config set/rm` only applies to the selected stack ## Checklist <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Service, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. --> Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com> |
||
---|---|---|
.. | ||
debug | ||
events | ||
optdestroy | ||
opthistory | ||
optpreview | ||
optrefresh | ||
optremove | ||
optup | ||
test | ||
README.md | ||
cmd.go | ||
errors.go | ||
errors_test.go | ||
example_test.go | ||
git.go | ||
git_test.go | ||
local_workspace.go | ||
local_workspace_test.go | ||
minimum_version.go | ||
stack.go | ||
stack_test.go | ||
workspace.go |
README.md
Automation API
Programmatic infrastructure.
Godocs
See the full godocs for the most extensive and up to date information including full examples coverage:
https://pkg.go.dev/github.com/pulumi/pulumi/sdk/v3/go/auto?tab=doc
Examples
Multiple full working examples with detailed walkthroughs can be found in this repo:
https://github.com/pulumi/automation-api-examples
Overview
Package auto 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 three out of the box ways to work with Stacks:
- Programs locally available on-disk and addressed via a filepath (NewStackLocalSource)
stack, err := NewStackLocalSource(ctx, "myOrg/myProj/myStack", filepath.Join("..", "path", "to", "project"))
- Programs fetched from a Git URL (NewStackRemoteSource)
stack, err := NewStackRemoteSource(ctx, "myOrg/myProj/myStack", GitRepo{
URL: "https:github.com/pulumi/test-repo.git",
ProjectPath: filepath.Join("project", "path", "repo", "root", "relative"),
})
- Programs defined as a function alongside your Automation API code (NewStackInlineSource)
stack, err := NewStackInlineSource(ctx, "myOrg/myProj/myStack", "myProj", func(pCtx *pulumi.Context) error {
bucket, err := s3.NewBucket(pCtx, "bucket", nil)
if err != nil {
return err
}
pCtx.Export("bucketName", bucket.Bucket)
return nil
})
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.
err := stack.SetConfig(ctx, "key", ConfigValue{ Value: "value", Secret: true })
preRes, err := stack.Preview(ctx)
detailed info about results
fmt.Println(preRes.prev.Steps[0].URN)
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:
w = stack.Workspace()
err := w.InstallPlugin("aws", "v3.2.0")
Workspaces can be explicitly created and customized beyond the three Stack creation helpers noted above:
w, err := NewLocalWorkspace(ctx, WorkDir(filepath.Join(".", "project", "path"), PulumiHome("~/.pulumi"))
s := NewStack(ctx, "org/proj/stack", w)
A default implementation of workspace is provided as LocalWorkspace
. This implementation relies on Pulumi.yaml
and Pulumi..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..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:
uRes, err :=stack.Up(ctx)
if err != nil && IsConcurrentUpdateError(err) { /* retry logic here */ }
Developing the Godocs
This repo has extensive examples and godoc content. To test out your changes locally you can do the following:
- enlist in the appropriate pulumi branch:
- cd $GOPATH/src/github.com/pulumi/pulumi/sdk/go/auto
- godoc -http=:6060
- Navigate to http://localhost:6060/pkg/github.com/pulumi/pulumi/sdk/v3/go/auto/
Known Issues
Please upvote issues, add comments, and open new ones to help prioritize our efforts: https://github.com/pulumi/pulumi/issues?q=is%3Aissue+is%3Aopen+label%3Aarea%2Fautomation-api