Skip to content

Commit

Permalink
Add authoring Dotnet Stack Examples (#68)
Browse files Browse the repository at this point in the history
* Add csharp code examples

* remove extra space

* fix

* PR feedback

* Remove extra line
  • Loading branch information
komalali authored Aug 7, 2020
1 parent ea9e3a0 commit 12ed1f5
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 4 deletions.
162 changes: 160 additions & 2 deletions docs/create-stacks-using-pulumi-dotnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,74 @@ Update the Pulumi API token Secret to use your Pulumi credentials.
Also update the `stack` org to match your account, leaving the stack project name as-is to work with the example repo's `Pulumi.yaml`.

```csharp
TODO
using Pulumi;
using Pulumi.Kubernetes.ApiExtensions;
using Pulumi.Kubernetes.Core.V1;
using Pulumi.Kubernetes.Types.Inputs.Core.V1;

class StackArgs : CustomResourceArgs
{
[Input("spec")]
public Input<StackSpecArgs>? Spec { get; set; }

public StackArgs() : base("pulumi.com/v1alpha1", "Stack")
{
}
}

class StackSpecArgs : ResourceArgs
{
[Input("accessTokenSecret")]
public Input<string>? AccessTokenSecret { get; set; }

[Input("stack")]
public Input<string>? Stack { get; set; }

[Input("initOnCreate")]
public Input<bool>? InitOnCreate { get; set; }

[Input("projectRepo")]
public Input<string>? ProjectRepo { get; set; }

[Input("commit")]
public Input<string>? Commit { get; set; }

[Input("destroyOnFinalize")]
public Input<bool>? DestroyOnFinalize { get; set; }
}

class MyStack : Stack
{
public MyStack()
{
// Get the Pulumi API token.
var config = new Config();
var pulumiAccessToken = config.RequireSecret("pulumiAccessToken");

// Create the API token as a Kubernetes Secret.
var accessToken = new Secret("accesstoken", new SecretArgs
{
StringData =
{
{"accessToken", pulumiAccessToken}
}
});

// Create an NGINX deployment in-cluster.
var myStack = new Pulumi.Kubernetes.ApiExtensions.CustomResource("nginx", new StackArgs
{
Spec = new StackSpecArgs
{
AccessTokenSecret = accessToken.Metadata.Apply(m => m.Name),
Stack = "<YOUR_ORG>/nginx/dev",
InitOnCreate = true,
ProjectRepo = "https://github.com/metral/pulumi-nginx",
Commit = "2b0889718d3e63feeb6079ccd5e4488d8601e353",
DestroyOnFinalize = true,
}
});
}
}
```

## AWS S3 Buckets
Expand All @@ -67,7 +134,98 @@ your Pulumi and AWS credentials.
Also update the `stack` org to match your account, leaving the stack project name as-is to work with the example repo's `Pulumi.yaml`.

```csharp
TODO
using System;
using Pulumi;
using Pulumi.Kubernetes.ApiExtensions;
using Pulumi.Kubernetes.Core.V1;
using Pulumi.Kubernetes.Types.Inputs.Core.V1;

class StackArgs : CustomResourceArgs
{
[Input("spec")]
public Input<StackSpecArgs>? Spec { get; set; }

public StackArgs() : base("pulumi.com/v1alpha1", "Stack")
{
}
}

class StackSpecArgs : ResourceArgs
{
[Input("accessTokenSecret")]
public Input<string>? AccessTokenSecret { get; set; }

[Input("stack")]
public Input<string>? Stack { get; set; }

[Input("initOnCreate")]
public Input<bool>? InitOnCreate { get; set; }

[Input("projectRepo")]
public Input<string>? ProjectRepo { get; set; }

[Input("commit")]
public Input<string>? Commit { get; set; }

[Input("destroyOnFinalize")]
public Input<bool>? DestroyOnFinalize { get; set; }

[Input("envSecrets")]
public InputList<String>? EnvSecrets { get; set; }

[Input("config")]
public InputMap<String>? Config { get; set; }
}

class MyStack : Stack
{
public MyStack()
{
// Get the Pulumi API token.
var config = new Config();
var pulumiAccessToken = config.RequireSecret("pulumiAccessToken");
var awsAccessKeyId = config.Require("awsAccessKeyId");
var awsSecretAccessKey = config.RequireSecret("awsSecretAccessKey");
var awsSessionToken = config.RequireSecret("awsSessionToken");

// Create the creds as Kubernetes Secrets.
var accessToken = new Secret("accesstoken", new SecretArgs
{
StringData =
{
{"accessToken", pulumiAccessToken}
}
});
var awsCreds = new Secret("aws-creds", new SecretArgs
{
StringData =
{
{"AWS_ACCESS_KEY_ID", awsAccessKeyId},
{"AWS_SECRET_ACCESS_KEY", awsSecretAccessKey},
{"AWS_SESSION_TOKEN", awsSessionToken}
}
});

// Create an AWS S3 Pulumi Stack in Kubernetes
var myStack = new Pulumi.Kubernetes.ApiExtensions.CustomResource("my-stack", new StackArgs
{
Spec = new StackSpecArgs
{
Stack = "<YOUR_ORG>/s3-op-project/dev",
ProjectRepo = "https://github.com/metral/test-s3-op-project",
Commit = "bd1edfac28577d62068b7ace0586df595bda33be",
AccessTokenSecret = accessToken.Metadata.Apply(m => m.Name),
Config =
{
{"aws:region", "us-west-2"}
},
EnvSecrets = {awsCreds.Metadata.Apply(m => m.Name)},
InitOnCreate = true,
DestroyOnFinalize = true,
}
});
}
}
```

Deploy the Stack CustomResource by running a `pulumi up`.
Expand Down
2 changes: 0 additions & 2 deletions docs/create-stacks-using-pulumi.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ Note: running Python programs is [coming soon](https://github.com/pulumi/pulumi-

### .NET

[TODO](https://github.com/pulumi/pulumi-kubernetes-operator/issues/48)

Check out [Create a Pulumi Stack using .NET](./create-stacks-using-pulumi-dotnet.md).

Note: running .NET programs is [coming soon](https://github.com/pulumi/pulumi-kubernetes-operator/issues/40)
Expand Down

0 comments on commit 12ed1f5

Please sign in to comment.