|
| 1 | +--- |
| 2 | +# WARNING: this file was fetched from https://raw.githubusercontent.com/DefangLabs/pulumi-defang/v1.0.0-beta.10/docs/installation-configuration.md |
| 3 | +# Do not edit by hand unless you're certain you know what you are doing! |
| 4 | +title: Defang Provider for Pulumi Installation & Configuration |
| 5 | +meta_desc: Provides an overview on how to configure the Pulumi Defang Provider. |
| 6 | +layout: package |
| 7 | +--- |
| 8 | +## Installation |
| 9 | + |
| 10 | +The Pulumi Provider for [Defang](https://defang.io) — Take your app from Docker Compose to a secure and scalable cloud deployment with Pulumi. |
| 11 | + |
| 12 | +The Defang Pulumi Provider is available in most pulumi languages. |
| 13 | + |
| 14 | +* JavaScript/TypeScript: [`@defang-io/pulumi-defang`](https://www.npmjs.com/package/@defang-io/pulumi-defang) |
| 15 | +* Python: [`pulumi-defang`](https://pypi.org/project/pulumi-defang/) |
| 16 | +* Go: [`github.com/DefangLabs/pulumi-defang/sdk/v1/go/defang`](https://github.com/DefangLabs/pulumi-defang) |
| 17 | +* .NET: [`DefangLabs.Defang`](https://www.nuget.org/packages/DefangLabs.Defang/) |
| 18 | +* Java: Coming soon |
| 19 | + |
| 20 | +### Installing the Pulumi Plugin directly |
| 21 | +``` |
| 22 | +pulumi plugin install resource defang --server github://api.github.com/DefangLabs |
| 23 | +``` |
| 24 | + |
| 25 | +## Authentication |
| 26 | + |
| 27 | +### Authenticating with Defang |
| 28 | + |
| 29 | +Sign up for [Defang](https://defang.io) with your Github account. |
| 30 | + |
| 31 | +#### Authenticating in Github Actions workflows |
| 32 | + |
| 33 | +When run in a Github Actions workflow, the Defang Pulumi Provider will automatically use environment varialbes Github providew to authenticate your Github user with Defang if you give your workflow the [appropriate permissions](https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/about-security-hardening-with-openid-connect#adding-permissions-settings). Defang use the `ACTIONS_ID_TOKEN_REQUEST_URL` and `ACTIONS_ID_TOKEN_REQUEST_TOKEN` env vars. |
| 34 | + |
| 35 | +#### Authenticating with `defang token` |
| 36 | + |
| 37 | +You can run `defang token --expires 30d` out of band with a reasonable duration and you can store the result in `DEFANG_ACCESS_TOKEN`. |
| 38 | + |
| 39 | +### Authenticating with your cloud provider |
| 40 | + |
| 41 | +You will also need to authenticate with your cloud provider. |
| 42 | + |
| 43 | +* For AWS, there are many ways to authenticate |
| 44 | + - Use the [`aws-actions/configure-aws-credentials`](https://github.com/aws-actions/configure-aws-credentials) Github Action |
| 45 | + - Use AWS Access Keys by setting the `AWS_ACCESS_KEY_ID`, and `AWS_ACCESS_KEY_SECRET` env vars. |
| 46 | +* For Digital Ocean, you will need to set the following env vars: |
| 47 | + - `DIGITALOCEAN_TOKEN` |
| 48 | + - `SPACES_ACCESS_KEY_ID` |
| 49 | + - `SPACES_SECRET_ACCESS_KEY` |
| 50 | +* For Google Cloud, you may wish to use the [`google-github-actions/auth`](https://github.com/google-github-actions/auth) Github Action |
| 51 | + |
| 52 | +## Example usage |
| 53 | + |
| 54 | +You can find complete working TypeScript, Python, Go, .NET, and Yaml code samples in the [`./examples`](https://github.com/DefangLabs/pulumi-defang/tree/main/examples) directory, and some example snippets below: |
| 55 | + |
| 56 | +{{< chooser language "typescript,python,go,dotnet,yaml" >}} |
| 57 | +{{% choosable language typescript %}} |
| 58 | +```typescript |
| 59 | +import * as pulumi from "@pulumi/pulumi"; |
| 60 | +import * as defang from "@defang-io/pulumi-defang"; |
| 61 | + |
| 62 | +const myProject = new defang.Project("myProject", { |
| 63 | + providerID: "aws", |
| 64 | + configPaths: ["compose.yaml"], |
| 65 | +}); |
| 66 | +export const output = { |
| 67 | + albArn: myProject.albArn, |
| 68 | + etag: myProject.etag, |
| 69 | +}; |
| 70 | +``` |
| 71 | + |
| 72 | +{{% /choosable %}} |
| 73 | + |
| 74 | +{{% choosable language python %}} |
| 75 | +```python |
| 76 | +import pulumi |
| 77 | +import pulumi_defang as defang |
| 78 | + |
| 79 | +my_project = defang.Project("myProject", |
| 80 | + provider_id="aws", |
| 81 | + config_paths=["compose.yaml"]) |
| 82 | +pulumi.export("output", { |
| 83 | + "albArn": my_project.alb_arn, |
| 84 | + "etag": my_project.etag, |
| 85 | +}) |
| 86 | +``` |
| 87 | + |
| 88 | +{{% /choosable %}} |
| 89 | + |
| 90 | +{{% choosable language go %}} |
| 91 | +```go |
| 92 | +package main |
| 93 | + |
| 94 | +import ( |
| 95 | + "example.com/pulumi-defang/sdk/go/defang" |
| 96 | + "github.com/pulumi/pulumi/sdk/v3/go/pulumi" |
| 97 | +) |
| 98 | + |
| 99 | +func main() { |
| 100 | + pulumi.Run(func(ctx *pulumi.Context) error { |
| 101 | + myProject, err := defang.NewProject(ctx, "myProject", &defang.ProjectArgs{ |
| 102 | + ProviderID: pulumi.String("aws"), |
| 103 | + ConfigPaths: pulumi.StringArray{ |
| 104 | + pulumi.String("compose.yaml"), |
| 105 | + }, |
| 106 | + }) |
| 107 | + if err != nil { |
| 108 | + return err |
| 109 | + } |
| 110 | + ctx.Export("output", pulumi.StringMap{ |
| 111 | + "albArn": myProject.AlbArn, |
| 112 | + "etag": myProject.Etag, |
| 113 | + }) |
| 114 | + return nil |
| 115 | + }) |
| 116 | +} |
| 117 | +``` |
| 118 | + |
| 119 | +{{% /choosable %}} |
| 120 | + |
| 121 | +{{% choosable language dotnet %}} |
| 122 | +```dotnet |
| 123 | +using System.Collections.Generic; |
| 124 | +using System.Linq; |
| 125 | +using Pulumi; |
| 126 | +using Defang = DefangLabs.Defang; |
| 127 | +
|
| 128 | +return await Deployment.RunAsync(() => |
| 129 | +{ |
| 130 | + var myProject = new Defang.Project("myProject", new() |
| 131 | + { |
| 132 | + ProviderID = "aws", |
| 133 | + ConfigPaths = new[] |
| 134 | + { |
| 135 | + "./compose.yaml", |
| 136 | + }, |
| 137 | + }); |
| 138 | +
|
| 139 | + return new Dictionary<string, object?> |
| 140 | + { |
| 141 | + ["output"] = |
| 142 | + { |
| 143 | + { "albArn", myProject.AlbArn }, |
| 144 | + { "etag", myProject.Etag }, |
| 145 | + }, |
| 146 | + }; |
| 147 | +}); |
| 148 | +
|
| 149 | +``` |
| 150 | + |
| 151 | +{{% /choosable %}} |
| 152 | + |
| 153 | +{{% choosable language yaml %}} |
| 154 | +```yaml |
| 155 | +# Pulumi.yaml provider configuration file |
| 156 | +name: configuration-example |
| 157 | +runtime: yaml |
| 158 | +config: |
| 159 | + defang:Project: |
| 160 | + providerID: aws |
| 161 | + configPaths: |
| 162 | + - ./compose.yaml |
| 163 | +``` |
| 164 | +
|
| 165 | +{{% /choosable %}} |
| 166 | +{{< /chooser >}} |
| 167 | +
|
| 168 | +## Using Pulumi Cloud |
| 169 | +
|
| 170 | +Defang runs the Pulumi CLI in your cloud account. You can use [Pulumi Cloud](https://www.pulumi.com/product/pulumi-cloud/) to manage the Pulumi resources which Defang creates by setting the following environment variables: |
| 171 | +
|
| 172 | +* `DEFANG_PULUMI_BACKEND=pulumi-cloud` |
| 173 | +* `PULUMI_ACCESS_TOKEN` |
| 174 | + |
| 175 | +## Reference |
| 176 | + |
| 177 | +For detailed reference documentation, please visit [the Pulumi registry](https://www.pulumi.com/registry/packages/defang/). |
0 commit comments