Skip to content

Commit 1884950

Browse files
Merge pull request #143 from DefangLabs/jordan/pulumi-docs
Defang Pulumi Provider Docs
2 parents 5d16394 + e998b41 commit 1884950

File tree

2 files changed

+123
-36
lines changed

2 files changed

+123
-36
lines changed

docs/concepts/pulumi.md

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ import TabItem from '@theme/TabItem';
1313
Pulumi support is currently only available for Defang Playground. We are working on support for Defang BYOC.
1414
:::
1515

16-
You can use Pulumi to define your Defang services. This allows you to integrate your Defang services with other cloud resources.
16+
[Pulumi](https://www.pulumi.com) is a modern infrastructure-as-code toolkit that allows developers to use a programming language like Typescript to provision and manage cloud resources.
1717

18-
For example, you might define an Aiven PostgreSQL database in your Pulumi code and then use the outputs of that resource to configure the secrets to connect to the database in your Defang service.
18+
Defang provides a Pulumi [_Provider_](https://www.pulumi.com/docs/iac/concepts/resources/providers/) written in Typescript which can be used to deploy Defang services alongside other Pulumi-managed infrastructure.
1919

20-
It also allows you to manage configuration for different environments using Pulumi's config system.
21-
22-
## Defang Pulumi Provider
20+
## Install the Defang Pulumi Provider
2321

2422
To get started with Pulumi and Defang you will need to install the Defang provider in [your Pulumi project](https://www.pulumi.com/learn/pulumi-fundamentals/create-a-pulumi-project/):
2523

@@ -47,8 +45,15 @@ yarn add @defang-io/pulumi-defang
4745
</TabItem>
4846
</Tabs>
4947

48+
## When to Use the Defang Pulumi Provider
49+
50+
The Defang Pulumi Provider is a good option for developers with more complex requirements than those supported by a [Compose File](/docs/concepts/compose).
51+
52+
One reason to use the Defang Pulumi provider is if you wish to integrate your services with other cloud resources. This is particularly true if you need to configure your services dynamically as other cloud resources are being provisioned.
53+
54+
Another reason would be if you want to deploy your services alongside cloud-specific resources, like a DynamoDB table, or an S3 bucket.
5055

51-
## Sample
56+
## Example
5257

5358
The following is a minimal example of a Pulumi program that defines a Defang service:
5459

@@ -63,4 +68,86 @@ const service = new defang.DefangService("my-service", {
6368
protocol: "http",
6469
}],
6570
});
66-
```
71+
```
72+
73+
:::info
74+
See the [Deploy using Pulumi](/docs/tutorials/deploy-using-pulumi) tutorial for more information about how to use it.
75+
:::
76+
77+
## API
78+
79+
### `DefangService`
80+
81+
```typescript
82+
constructor(
83+
name: string,
84+
args: DefangServiceArgs,
85+
opts?: pulumi.CustomResourceOptions
86+
)
87+
```
88+
89+
### `DefangServiceArgs`
90+
91+
```typescript
92+
interface DefangServiceArgs {
93+
/** the DNS name of the Defang Fabric service; defaults to the value of DEFANG_FABRIC or prod, if unset */
94+
fabricDNS?: pulumi.Input<string>;
95+
/** the name of the service; defaults to the name of the resource */
96+
name?: pulumi.Input<string>;
97+
/** the container image to deploy; required when no build configuration was provided */
98+
image?: pulumi.Input<string>;
99+
/** the platform to deploy to; defaults to "linux/amd64" */
100+
platform?: pulumi.Input<Platform>;
101+
/** which network the service is in, ie. whether the service requires a public IP or not; defaults to "private" (was: internal=true) */
102+
networks?: { [key in NetworkName]?: Network };
103+
/** the optional deployment configuration */
104+
deploy?: pulumi.Input<Deploy>;
105+
/** the ports to expose */
106+
ports?: pulumi.Input<pulumi.Input<Port>[]>;
107+
/** the environment variables to set; use `null` to mark at sensitive */
108+
environment?: pulumi.Input<{ [key: string]: pulumi.Input<string> | null }>;
109+
/** the secrets to expose as environment variables @deprecated use environment key with value `null` */
110+
secrets?: pulumi.Input<pulumi.Input<Secret>[]>;
111+
/** force deployment of the service even if nothing has changed */
112+
forceNewDeployment?: pulumi.Input<boolean>;
113+
/** the command to run; overrides the container image's CMD */
114+
command?: pulumi.Input<pulumi.Input<string>[]>;
115+
/** the optional build configuration; required when no image was provided */
116+
build?: pulumi.Input<Build>;
117+
/** the optional health-check test for the service */
118+
healthcheck?: pulumi.Input<HealthCheck>;
119+
/** the optional fully qualified domain name for the service; requires CNAME to the publicFqdn */
120+
domainname?: pulumi.Input<string>;
121+
/** experimental: mark this service as (managed) Redis */
122+
x_redis?: pulumi.Input<unknown>;
123+
/** experimental: mark this service as serving static files */
124+
x_static_files?: pulumi.Input<StaticFiles>;
125+
/** if true, this provider will wait for the service to reach a steady state before continuing */
126+
waitForSteadyState?: pulumi.Input<boolean>;
127+
/** the project to deploy the service to */
128+
project?: pulumi.Input<string>;
129+
}
130+
```
131+
132+
### `Platform`
133+
134+
```typescript
135+
type Platform = "linux/arm64" | "linux/amd64" | "linux";
136+
```
137+
138+
### `Protocol`
139+
```typescript
140+
type Protocol = "tcp" | "udp" | "http" | "http2" | "grpc";
141+
```
142+
### `DeviceCapability`
143+
```typescript
144+
type DeviceCapability = "gpu";
145+
```
146+
### `NetworkName`
147+
```typescript
148+
type NetworkName = "private" | "public";
149+
```
150+
### `Network`
151+
```typescript
152+
type Network = { aliases?: string[] } | null;
153+
```

docs/tutorials/deploy-using-pulumi.mdx

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,41 @@ sidebar_position: 400
55

66
# Deploy Using Pulumi
77

8+
:::warning
9+
At the time of writing, the Defang Pulumi Provider only works with [Defang Playground](../concepts/defang-playground.md). We are working on [BYOC](../concepts/defang-byoc.md) support.
10+
:::
11+
12+
This tutorial will show you how to deploy Minio with Pulumi using the Defang Provider.
13+
814
<iframe width="560" height="315" src="https://www.youtube.com/embed/A4uiP5FIgg0?si=BHZLOxN4noJ56f7x" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
915

10-
## Installing Dependencies
16+
## Pre-requisites
1117

12-
Make sure to install the [Pulumi CLI](https://www.pulumi.com/docs/install/) and the [Defang CLI](../getting-started#install-the-defang-cli.md).
18+
* [A Defang Account](/docs/concepts/authentication)
19+
* [Pulumi CLI](https://www.pulumi.com/docs/install)
20+
* [The Defang CLI](/docs/getting-started#install-the-defang-cli)
21+
* [The Defang Pulumi Provider](/docs/concepts/pulumi#install-the-defang-pulumi-provider)
22+
23+
## Step 1 - Authenticate With Defang
1324

1425
Make sure you are logged into the [Defang CLI](/docs/concepts/authentication.md). Don't worry about the Pulumi CLI for now.
1526

16-
## Project Directory Setup
27+
## Step 2 - Configure the Pulumi Backend
1728

18-
Create a new directory for your project and navigate to it.
29+
Navigate to your project directly. (If you don't have a project yet, try one of our [samples](https://defang.io/#samples))
1930

20-
```bash
21-
mkdir project && cd project
22-
```
2331

24-
If you're familiar with Pulumi and/or are already logged in with the Pulumi CLI, you can skip the next step.
32+
Pulumi uses the `pulumi login` command to select a backend. In this tutorial, we will use the Local Filesystem backend for simplicity. When you are ready to deploy to production, you will probably want to look into other [Pulumi backend options](https://www.pulumi.com/docs/iac/concepts/state-and-backends).
2533

26-
If you are new to Pulumi and/or don't have an account, you can "login" to the filesystem by running the following command:
34+
Run the following command to "login" to the filesystem backend in the local directory.
2735

2836
```bash
2937
pulumi login file://./
3038
```
3139

3240
This will make the Pulumi CLI store the state of your infrastructure in the current directory.
3341

34-
## Initialize the Project
42+
## Step 3 - Initialize the Pulumi Project
3543

3644
Run the following command to set your encryption passphrase for this terminal session:
3745

@@ -53,17 +61,9 @@ Run the following command to add to the `.gitignore` file:
5361
echo ".pulumi" >> .gitignore
5462
```
5563

56-
## Install the Defang Provider
57-
58-
Run the following command to install the Defang provider:
59-
60-
```bash
61-
npm install @defang-io/pulumi-defang
62-
```
63-
64-
## Write the Pulumi Code
64+
## Step 4 - Write Your Pulumi Code
6565

66-
Your `index.ts` file should look like this:
66+
Create an `index.ts` file to contain your Pulumi code. This code will describe our services, our service's dependencies, and our service's configuration.
6767

6868
```typescript
6969
import * as defang from '@defang-io/pulumi-defang/lib';
@@ -107,27 +107,23 @@ export const service = new defang.DefangService('minio', {
107107
});
108108
```
109109

110-
## Deploy to Defang
111-
112-
:::warning
113-
At the time of writing, the Defang Pulumi Provider only works with [Defang Playground](../concepts/defang-playground.md). We are working on [BYOC](../concepts/defang-byoc.md) support.
114-
:::
110+
## Step 5 - Deploy to Defang
115111

116-
Run the following command to deploy your service:
112+
Now we're ready to deploy to Defang with Pulumi! Run the following command to deploy your service:
117113

118114
```bash
119115
pulumi up --stack=dev
120116
```
121117

122-
## Monitor the Deployment
118+
## Step 6 - Monitor the Deployment
123119

124120
You can monitor the deployment by running the following command:
125121

126122
```bash
127123
defang tail --name minio
128124
```
129125

130-
## Logging Into Minio
126+
### Logging Into Minio
131127

132128
The [Defang Playground](../concepts/defang-playground.md) will give you a domain, which you can obtain by running the following command:
133129

@@ -137,10 +133,14 @@ defang ls | grep 'minio.*9001'
137133

138134
If you navigate to the domain in your browser, you will be prompted to log in. Use the username `minio` and the password `minio123`.
139135

140-
## Clean Up
136+
### Clean Up
141137

142138
To clean up the deployment, run the following command:
143139

144140
```bash
145141
pulumi destroy --stack=dev
146142
```
143+
144+
---
145+
146+
See the [Pulumi concept docs](/docs/concepts/pulumi) for more information about the Defang Pulumi Provider.

0 commit comments

Comments
 (0)