-
Notifications
You must be signed in to change notification settings - Fork 257
[blog] Automate Your Infrastructure with Automation API and C# #5380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
spara
merged 10 commits into
pulumi:master
from
orionstudt:blog/announce-csharp-automation-preview
Mar 8, 2021
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f35161b
intro commit
orionstudt 8617830
a few small dotnet examples
orionstudt 54d0f4e
add link to examples
orionstudt 8f09506
Apply suggestions from blog post review
orionstudt a330ffd
resolve per PR remarks
orionstudt 31e86c9
minor details
orionstudt 3aec9ae
Apply suggestions from blog post review
orionstudt 04b2f93
add sophia as co-author
orionstudt 408b03e
Update content/blog/automation-api-dotnet/index.md
orionstudt cba8963
Update content/blog/automation-api-dotnet/index.md
orionstudt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| --- | ||
| title: "Automate Your Infrastructure with Automation API and C#" | ||
| date: 2021-03-08 | ||
| meta_desc: "C# developers can programmatically build infrastructure (with out a CLI) using the Pulumi Automation API package. " | ||
| meta_image: automation_api.png | ||
| authors: | ||
| - joshua-studt | ||
| - sophia-parafina | ||
| tags: | ||
| - Automation API | ||
| - C# | ||
| - csharp | ||
| - dotnet | ||
| - .NET | ||
| --- | ||
|
|
||
orionstudt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {{% notes type="info" %}} | ||
| Joshua Studt is a Solutions Architect at Financial Independence Group and a Pulumi Community member who contributed the C# package for Automation API. | ||
| {{% /notes %}} | ||
|
|
||
| Currently available in public preview, Pulumi's Automation API lets you to programmatically call upon the Pulumi engine to provision your infrastructure. Today, we are excited to announce C# support for Automation API, enabling .NET developers to automate infrastructure deployments, create complex orchestration workflows, build custom ops tooling, and build cloud frameworks. Read more about the Automation API [here]({{< relref "/blog/automation-api" >}}). | ||
orionstudt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Using Automation API in .NET | ||
|
|
||
| The `Pulumi.Automation` [NuGet package](https://www.nuget.org/packages/Pulumi.Automation) exposes a `LocalWorkspace` for creating and managing Pulumi [Stacks]({{< relref "/docs/intro/concepts/stack" >}}), and a `WorkspaceStack` that is a programmatic representation of a Stack for updating, refreshing, previewing, and destroying cloud resources. The Automation API makes it trivial to run Pulumi programs inline: | ||
|
|
||
| ```csharp | ||
| var program = PulumiFn.Create(() => | ||
| { | ||
| var bucket = new Pulumi.Aws.S3.Bucket("s3-website-bucket"); | ||
|
|
||
| return new Dictionary<string, object?> | ||
| { | ||
| ["bucket_name"] = bucket.BucketName, | ||
| }; | ||
| }); | ||
|
|
||
| var stackArgs = new InlineProgramArgs("projectName", "stackName", program); | ||
| using var stack = await LocalWorkspace.CreateOrSelectStackAsync(stackArgs); | ||
|
|
||
| await stack.Workspace.InstallPluginAsync("aws", "v3.30.1"); | ||
| var result = await stack.UpAsync(); | ||
| var bucketName = result.Outputs["bucket_name"]; | ||
| ``` | ||
|
|
||
| You can use your existing Pulumi projects and invoke them from the Automation API: | ||
|
|
||
| ```csharp | ||
| var stackArgs = new LocalProgramArgs("stackName", "C:\path\to\pulumi\project\dir"); | ||
| using var stack = await LocalWorkspace.CreateOrSelectStackAsync(stackArgs); | ||
|
|
||
| await stack.UpAsync(); | ||
| ``` | ||
|
|
||
| Since the Automation API can be invoked and debugged like any other code, it enables you to put together complex deployment workflows such as a blue-green deployment model: | ||
|
|
||
| ```csharp | ||
| using var workspace = await LocalWorkspace.CreateAsync(new LocalWorkspaceOptions | ||
| { | ||
| Program = PulumiFn.Create<ApplicationStack>(), // use your existing Pulumi.Stack implementation | ||
| ProjectSettings = new ProjectSettings("projectName", ProjectRuntimeName.Dotnet), | ||
| }); | ||
|
|
||
| // your "blue" production code is already running | ||
|
|
||
| var green = await WorkspaceStack.SelectAsync("green", workspace); | ||
| await green.UpAsync(); | ||
|
|
||
| // do your cutover to "green" logic | ||
| // and then teardown "blue" | ||
|
|
||
| var blue = await WorkspaceStack.SelectAsync("blue", workspace); | ||
| await blue.DestroyAsync(); | ||
| ``` | ||
|
|
||
| See full Automation API examples in [C#](https://github.com/pulumi/automation-api-examples/tree/main/dotnet). Let us know if you're using Automation API on [Twitter](https://twitter.com/PulumiCorp) or in [Pulumi Comunity Slack](https://slack.pulumi.com/). | ||
orionstudt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| id = "joshua-studt" | ||
| name = "Joshua Studt" | ||
| title = "Solutions Architect, Financial Independence Group" | ||
| status = "guest" | ||
|
|
||
| [social] | ||
| github = "orionstudt" | ||
| linkedin = "orionstudt" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.