Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
11194: [auto/dotnet] Support for remote operations r=Frassle a=justinvp This change adds preview support for remote operations in .NET's Automation API. **Note:** ~~I've tried _many_ incantations of `dotnet format dotnet.sln analyzers --diagnostics=RS0016`, but have not been able to get the code fix applied to update `sdk/dotnet/Pulumi.Automation/PublicAPI.Shipped.txt`. Perhaps a .NET 6 bug (I'm running on an M1 Mac)? dotnet/format#1416 might be relevant. I'll try again a bit later, but I might have to manually update the file, unless someone else's tools are working and can pull down the branch and run it.~~ Update: I didn't see any failures in the PR related to not having updated `sdk/dotnet/Pulumi.Automation/PublicAPI.Shipped.txt`, so maybe we're no longer checking this or something is broken? In any case, I still wasn't able to get `dotnet format` to automatically apply the updates, so I manually edited `PublicAPI.Shipped.txt`. I _think_ I got everything, but it's possible I missed something. Let's see what CI says. Here's an example of using it: ```c# using System; using System.Linq; using Pulumi.Automation; bool destroy = args.Any() && args[0] == "destroy"; const string org = "justinvp"; const string projectName = "aws-ts-s3-folder"; var stackName = $"{org}/{projectName}/devdotnet"; var stackArgs = new RemoteGitProgramArgs(stackName, "https://github.com/pulumi/examples.git") { Branch = "refs/heads/master", ProjectPath = projectName, EnvironmentVariables = { { "AWS_REGION", new EnvironmentVariableValue("us-west-2") }, { "AWS_ACCESS_KEY_ID", RequireFromEnvironment("AWS_ACCESS_KEY_ID") }, { "AWS_SECRET_ACCESS_KEY", RequireFromEnvironment("AWS_SECRET_ACCESS_KEY", isSecret: true) }, { "AWS_SESSION_TOKEN", RequireFromEnvironment("AWS_SESSION_TOKEN", isSecret: true) }, }, }; var stack = await RemoteWorkspace.CreateOrSelectStackAsync(stackArgs); if (destroy) { await stack.DestroyAsync(new RemoteDestroyOptions { OnStandardOutput = Console.WriteLine }); } else { Console.WriteLine("updating stack..."); var result = await stack.UpAsync(new RemoteUpOptions { OnStandardOutput = Console.WriteLine }); if (result.Summary.ResourceChanges != null) { Console.WriteLine("update summary:"); foreach (var change in result.Summary.ResourceChanges) Console.WriteLine($" {change.Key}: {change.Value}"); } Console.WriteLine($"url: {result.Outputs["websiteUrl"].Value}"); } static EnvironmentVariableValue RequireFromEnvironment(string variable, bool isSecret = false) { var value = Environment.GetEnvironmentVariable(variable) ?? throw new InvalidOperationException($"Required environment variable {variable} not set."); return new EnvironmentVariableValue(value, isSecret); } ``` I will add sanity tests subsequently. Co-authored-by: Justin Van Patten <jvp@justinvp.com>
- Loading branch information
Showing
19 changed files
with
1,097 additions
and
14 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
changelog/pending/20221031--auto-dotnet--support-for-remote-operations.yaml
This file contains 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,4 @@ | ||
changes: | ||
- type: feat | ||
scope: auto/dotnet | ||
description: Support for remote operations |
24 changes: 24 additions & 0 deletions
24
sdk/dotnet/Pulumi.Automation.Tests/RemoteWorkspaceTests.cs
This file contains 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,24 @@ | ||
// Copyright 2016-2022, Pulumi Corporation | ||
|
||
using Xunit; | ||
|
||
namespace Pulumi.Automation.Tests | ||
{ | ||
public class RemoteWorkspaceTests | ||
{ | ||
[Theory] | ||
[InlineData("owner/project/stack", true)] | ||
[InlineData("", false)] | ||
[InlineData("name", false)] | ||
[InlineData("owner/name", false)] | ||
[InlineData("/", false)] | ||
[InlineData("//", false)] | ||
[InlineData("///", false)] | ||
[InlineData("owner/project/stack/wat", false)] | ||
public void IsFullyQualifiedStackName(string input, bool expected) | ||
{ | ||
var actual = RemoteWorkspace.IsFullyQualifiedStackName(input); | ||
Assert.Equal(expected, actual); | ||
} | ||
} | ||
} |
This file contains 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,19 @@ | ||
// Copyright 2016-2022, Pulumi Corporation | ||
|
||
namespace Pulumi.Automation | ||
{ | ||
public class EnvironmentVariableValue | ||
{ | ||
public string Value { get; set; } | ||
|
||
public bool IsSecret { get; set; } | ||
|
||
public EnvironmentVariableValue( | ||
string value, | ||
bool isSecret = false) | ||
{ | ||
Value = value; | ||
IsSecret = isSecret; | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.