Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions content/blog/automation-api-dotnet/index.md
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
---

{{% 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 enables you to provision your infrastructure programmatically using the Pulumi engine. 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" >}}).

## 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 our [Community Slack](https://slack.pulumi.com/).
8 changes: 8 additions & 0 deletions data/team/team/joshua-studt.toml
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"
Binary file added static/images/team/joshua-studt.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.