Skip to content

Commit 1afef7a

Browse files
authored
Merge pull request #1 from Mythetech/initial-commit
ModularPipelines Pulumi Package
2 parents 1b22356 + f7e93c5 commit 1afef7a

File tree

10 files changed

+278
-0
lines changed

10 files changed

+278
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,4 @@ FodyWeavers.xsd
396396

397397
# JetBrains Rider
398398
*.sln.iml
399+
*.idea
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using System.Runtime.CompilerServices;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.Extensions.DependencyInjection.Extensions;
5+
using ModularPipelines.Context;
6+
using ModularPipelines.Engine;
7+
8+
namespace ModularPipelines.Pulumi.Extensions;
9+
10+
[ExcludeFromCodeCoverage]
11+
public static class PulumiExtensions
12+
{
13+
#pragma warning disable CA2255
14+
[ModuleInitializer]
15+
#pragma warning restore CA2255
16+
public static void RegisterPulumiContext()
17+
{
18+
ModularPipelinesContextRegistry.RegisterContext(collection => RegisterPulumiContext(collection));
19+
}
20+
21+
public static IServiceCollection RegisterPulumiContext(this IServiceCollection services)
22+
{
23+
services.TryAddScoped<IPulumi, Pulumi>();
24+
25+
return services;
26+
}
27+
28+
public static IPulumi Pulumi(this IPipelineHookContext context) => context.ServiceProvider.GetRequiredService<IPulumi>();
29+
}

ModularPipelines.Pulumi/IPulumi.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using ModularPipelines.Models;
2+
using ModularPipelines.Pulumi.Options;
3+
4+
namespace ModularPipelines.Pulumi;
5+
6+
public interface IPulumi
7+
{
8+
public Task<CommandResult> Login(PulumiLoginOptions options, CancellationToken token = default);
9+
10+
public Task<CommandResult> Preview(PulumiPreviewOptions options, CancellationToken token = default);
11+
12+
public Task<CommandResult> Up(PulumiUpOptions options, CancellationToken token = default);
13+
14+
public Task<CommandResult> Stack(PulumiStackOptions options, CancellationToken token = default);
15+
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<Title>ModularPipelines.Pulumi</Title>
8+
<Authors>Mythetech</Authors>
9+
<Description>Helpers for interacting with Pulumi CLI</Description>
10+
<Company>Mythetech</Company>
11+
<AssemblyVersion>0.0.0.1</AssemblyVersion>
12+
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="ModularPipelines" Version="2.42.140" />
16+
</ItemGroup>
17+
18+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using ModularPipelines.Attributes;
2+
3+
namespace ModularPipelines.Pulumi.Options;
4+
5+
[CommandPrecedingArguments("login")]
6+
public record PulumiLoginOptions : PulumiOptions
7+
{
8+
[CommandSwitch("--cloud-url")]
9+
public string? CloudUrl { get; set; }
10+
11+
[CommandSwitch("--default-org")]
12+
public string? DefaultOrg { get; set; }
13+
14+
[BooleanCommandSwitch("--insecure")]
15+
public bool? Insecure { get; set; }
16+
17+
[BooleanCommandSwitch("--local")]
18+
public bool? Local { get; set; }
19+
20+
[BooleanCommandSwitch("--interactive")]
21+
public bool? Interactive { get; set; }
22+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using ModularPipelines.Attributes;
2+
using ModularPipelines.Options;
3+
4+
namespace ModularPipelines.Pulumi.Options;
5+
6+
public record PulumiOptions() : CommandLineToolOptions("pulumi")
7+
{
8+
[CommandSwitch("--color")]
9+
public string? Color { get; set; } // Choices: always, never, raw, auto
10+
11+
[CommandSwitch("-C")]
12+
public string? Cwd { get; set; }
13+
14+
[BooleanCommandSwitch("--disable-integrity-checking")]
15+
public bool? DisableIntegrityChecking { get; set; }
16+
17+
[BooleanCommandSwitch("-e")]
18+
public bool? Emoji { get; set; }
19+
20+
[BooleanCommandSwitch("-Q")]
21+
public bool? FullyQualifiedStackNames { get; set; }
22+
23+
[BooleanCommandSwitch("--logflow")]
24+
public bool? LogFlow { get; set; }
25+
26+
[BooleanCommandSwitch("--logtostderr")]
27+
public bool? LogToStderr { get; set; }
28+
29+
[CommandSwitch("--memprofilerate")]
30+
public int? MemProfilerRate { get; set; }
31+
32+
[BooleanCommandSwitch("--non-interactive")]
33+
public bool? NonInteractive { get; set; }
34+
35+
[CommandSwitch("--profiling")]
36+
public string? Profiling { get; set; }
37+
38+
[CommandSwitch("--tracing")]
39+
public string? Tracing { get; set; }
40+
41+
[CommandSwitch("-v")]
42+
public int? Verbose { get; set; }
43+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using ModularPipelines.Attributes;
2+
3+
namespace ModularPipelines.Pulumi.Options;
4+
5+
[CommandPrecedingArguments("preview")]
6+
public record PulumiPreviewOptions : PulumiOptions
7+
{
8+
[BooleanCommandSwitch("--attach-debugger")]
9+
public bool? AttachDebugger { get; set; }
10+
11+
[CommandSwitch("--config")]
12+
public string[]? Config { get; set; }
13+
14+
[CommandSwitch("--config-file")]
15+
public string? ConfigFile { get; set; }
16+
17+
[BooleanCommandSwitch("--debug")]
18+
public bool? Debug { get; set; }
19+
20+
[BooleanCommandSwitch("--diff")]
21+
public bool? Diff { get; set; }
22+
23+
[BooleanCommandSwitch("--expect-no-changes")]
24+
public bool? ExpectNoChanges { get; set; }
25+
26+
[CommandSwitch("--json")]
27+
public bool? Json { get; set; }
28+
29+
[CommandSwitch("--message")]
30+
public string? Message { get; set; }
31+
32+
[CommandSwitch("--parallel")]
33+
public int? Parallel { get; set; }
34+
35+
[CommandSwitch("--refresh")]
36+
public string? Refresh { get; set; }
37+
38+
[CommandSwitch("--stack")]
39+
public string? Stack { get; set; }
40+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using ModularPipelines.Attributes;
2+
3+
namespace ModularPipelines.Pulumi.Options;
4+
5+
[CommandPrecedingArguments("stack")]
6+
public record PulumiStackOptions : PulumiOptions
7+
{
8+
[CommandSwitch("--stack")]
9+
public string? Stack { get; set; }
10+
11+
[BooleanCommandSwitch("--show-secrets")]
12+
public bool? ShowSecrets { get; set; }
13+
14+
[BooleanCommandSwitch("--show-ids")]
15+
public bool? ShowIds { get; set; }
16+
17+
[BooleanCommandSwitch("--show-urns")]
18+
public bool? ShowUrns { get; set; }
19+
20+
[BooleanCommandSwitch("--show-name")]
21+
public bool? ShowName { get; set; }
22+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using ModularPipelines.Attributes;
2+
3+
namespace ModularPipelines.Pulumi.Options;
4+
5+
[CommandPrecedingArguments("up")]
6+
public record PulumiUpOptions : PulumiOptions
7+
{
8+
[CommandSwitch("--attach-debugger")]
9+
public bool? AttachDebugger { get; set; }
10+
11+
[CommandSwitch("--config")]
12+
public string[]? Config { get; set; }
13+
14+
[CommandSwitch("--config-file")]
15+
public string? ConfigFile { get; set; }
16+
17+
[BooleanCommandSwitch("--continue-on-error")]
18+
public bool? ContinueOnError { get; set; }
19+
20+
[BooleanCommandSwitch("--debug")]
21+
public bool? Debug { get; set; }
22+
23+
[BooleanCommandSwitch("--diff")]
24+
public bool? Diff { get; set; }
25+
26+
[BooleanCommandSwitch("--expect-no-changes")]
27+
public bool? ExpectNoChanges { get; set; }
28+
29+
[CommandSwitch("--message")]
30+
public string? Message { get; set; }
31+
32+
[CommandSwitch("--parallel")]
33+
public int? Parallel { get; set; }
34+
35+
[CommandSwitch("--refresh")]
36+
public string? Refresh { get; set; }
37+
38+
[BooleanCommandSwitch("--replace")]
39+
public string[]? Replace { get; set; }
40+
41+
[CommandSwitch("--stack")]
42+
public string? Stack { get; set; }
43+
44+
[BooleanCommandSwitch("--target")]
45+
public string[]? Target { get; set; }
46+
47+
[BooleanCommandSwitch("--yes")]
48+
public bool? Yes { get; set; }
49+
50+
[BooleanCommandSwitch("--skip-preview")]
51+
public bool? SkipPreview { get; set; }
52+
}

ModularPipelines.Pulumi/Pulumi.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using ModularPipelines.Context;
2+
using ModularPipelines.Models;
3+
using ModularPipelines.Pulumi.Options;
4+
5+
namespace ModularPipelines.Pulumi;
6+
7+
public class Pulumi : IPulumi
8+
{
9+
private readonly ICommand _command;
10+
11+
public Pulumi(ICommand command)
12+
{
13+
_command = command;
14+
}
15+
16+
public async Task<CommandResult> Login(PulumiLoginOptions options, CancellationToken token = default)
17+
{
18+
return await _command.ExecuteCommandLineTool(options, token);
19+
}
20+
21+
public async Task<CommandResult> Preview(PulumiPreviewOptions options, CancellationToken token = default)
22+
{
23+
return await _command.ExecuteCommandLineTool(options, token);
24+
}
25+
26+
public async Task<CommandResult> Up(PulumiUpOptions options, CancellationToken token = default)
27+
{
28+
return await _command.ExecuteCommandLineTool(options, token);
29+
}
30+
31+
public async Task<CommandResult> Stack(PulumiStackOptions options, CancellationToken token = default)
32+
{
33+
return await _command.ExecuteCommandLineTool(options, token);
34+
}
35+
}

0 commit comments

Comments
 (0)