Skip to content

Commit dfac575

Browse files
authored
New example: pulumi-ts (#843)
Contributes a new example showing how to use Pulumi IAC to manage `Stacks`. A unique aspect of this example is that it automatically provisions a Pulumi Cloud access token for the stack to use. Note this important limitation of `@pulumi/pulumiservice`: > While you can use this provider to provision access tokens, you’ll still need to have an access token available to generate an access token with the provider.
1 parent 75f64f6 commit dfac575

File tree

8 files changed

+3590
-1
lines changed

8 files changed

+3590
-1
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
CHANGELOG
22
=========
33

4+
## Unreleased
5+
6+
- New example: pulumi-ts [#843](https://github.com/pulumi/pulumi-kubernetes-operator/pull/843)
7+
48
## 2.0.0 (2025-02-18)
59

610
- Sample network policies [#839](https://github.com/pulumi/pulumi-kubernetes-operator/pull/839)

Diff for: README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ Working with sources:
100100
- [Program resources](./examples/program-source)
101101
- [Custom sources](./examples/custom-source)
102102

103-
Advanced:
103+
Better together with Pulumi IAC:
104+
105+
- [Pulumi (TypeScript)](./examples/pulumi-ts)
106+
107+
Advanced configurations:
104108

105109
- [Workspace customization](./examples/custom-workspace)
106110

Diff for: examples/pulumi-ts/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/bin/
2+
/node_modules/

Diff for: examples/pulumi-ts/Pulumi.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: pulumi-ts
2+
description: A Pulumi program to deploy a Stack using the Pulumi Kubernetes Operator
3+
runtime:
4+
name: nodejs
5+
options:
6+
packagemanager: npm
7+
config:
8+
pulumi:tags:
9+
value:
10+
pulumi:template: kubernetes-typescript

Diff for: examples/pulumi-ts/index.ts

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import * as pulumi from "@pulumi/pulumi";
2+
import * as k8s from "@pulumi/kubernetes";
3+
import * as pulumiservice from "@pulumi/pulumiservice";
4+
5+
// Create a Kubernetes ServiceAccount for the Pulumi workspace pod
6+
const sa = new k8s.core.v1.ServiceAccount("random-yaml", {});
7+
8+
// Grant system:auth-delegator to the ServiceAccount
9+
const crb = new k8s.rbac.v1.ClusterRoleBinding("random-yaml:system:auth-delegator", {
10+
roleRef: {
11+
apiGroup: "rbac.authorization.k8s.io",
12+
kind: "ClusterRole",
13+
name: "system:auth-delegator",
14+
},
15+
subjects: [{
16+
kind: "ServiceAccount",
17+
name: sa.metadata.name,
18+
namespace: sa.metadata.namespace,
19+
}],
20+
});
21+
22+
// Provision a Pulumi Cloud access token and store it in a Kubernetes Secret
23+
const accessToken = new pulumiservice.AccessToken("random-yaml", {
24+
description: `For stack "${pulumi.runtime.getOrganization()}/${pulumi.runtime.getProject()}/${pulumi.runtime.getStack()}"`,
25+
});
26+
const apiSecret = new k8s.core.v1.Secret("random-yaml", {
27+
stringData: {
28+
"accessToken": accessToken.value,
29+
}
30+
});
31+
32+
// Deploy the "random-yaml" program from the github.com/pulumi/examples repository.
33+
const stack = new k8s.apiextensions.CustomResource("random-yaml", {
34+
apiVersion: 'pulumi.com/v1',
35+
kind: 'Stack',
36+
spec: {
37+
serviceAccountName: sa.metadata.name,
38+
projectRepo: "https://github.com/pulumi/examples",
39+
repoDir: "random-yaml/",
40+
branch: "master",
41+
shallow: true,
42+
stack: "pulumi-ts",
43+
refresh: true,
44+
destroyOnFinalize: true,
45+
envRefs: {
46+
PULUMI_ACCESS_TOKEN: {
47+
type: "Secret",
48+
secret: {
49+
name: apiSecret.metadata.name,
50+
key: "accessToken",
51+
},
52+
},
53+
},
54+
workspaceTemplate: {
55+
spec: {
56+
image: "pulumi/pulumi:3.147.0-nonroot",
57+
},
58+
},
59+
},
60+
}, {dependsOn: [sa, crb, apiSecret]});
61+
62+
// export const stackName = stack.metadata.name;

0 commit comments

Comments
 (0)