Skip to content

Commit 681a79b

Browse files
authored
Merge pull request #13 from appwrite/CLO-4192-sites-and-functions-deployments
feat: add `deployment` resource for both `site` and `function`
2 parents b0ec6f5 + 349e94c commit 681a79b

37 files changed

Lines changed: 1997 additions & 8 deletions

README.md

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,19 @@ export APPWRITE_API_KEY="api-key"
6565

6666
### Functions
6767

68-
| Resource | Description |
69-
|--------------------------------|----------------------|
70-
| `appwrite_function` | Function |
71-
| `appwrite_function_variable` | Environment variable |
68+
| Resource | Description |
69+
|-----------------------------------|----------------------|
70+
| `appwrite_function` | Function |
71+
| `appwrite_function_variable` | Environment variable |
72+
| `appwrite_function_deployment` | Deployment |
7273

7374
### Sites
7475

75-
| Resource | Description |
76-
|----------------------------|----------------------|
77-
| `appwrite_site` | Site |
78-
| `appwrite_site_variable` | Environment variable |
76+
| Resource | Description |
77+
|-------------------------------|----------------------|
78+
| `appwrite_site` | Site |
79+
| `appwrite_site_variable` | Environment variable |
80+
| `appwrite_site_deployment` | Deployment |
7981

8082
### Messaging
8183

@@ -150,6 +152,25 @@ resource "appwrite_site_variable" "api_url" {
150152
value = "https://api.example.com"
151153
}
152154
155+
resource "appwrite_function_deployment" "on_signup" {
156+
function_id = appwrite_function.on_signup.id
157+
source_type = "code"
158+
code_path = "./on-signup.tar.gz"
159+
code_hash = filesha256("./on-signup.tar.gz")
160+
activate = true
161+
}
162+
163+
resource "appwrite_site_deployment" "dashboard" {
164+
site_id = appwrite_site.dashboard.id
165+
source_type = "template"
166+
repository = "templates-for-sites"
167+
owner = "appwrite"
168+
root_directory = "nextjs/starter"
169+
type = "branch"
170+
reference = "main"
171+
activate = true
172+
}
173+
153174
resource "appwrite_storage_bucket" "images" {
154175
id = "images"
155176
name = "images"

docs/index.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ The `project_id` can be set at the provider level as a default for all resources
7171
- [appwrite_auth_user](resources/auth_user.md) - Manage users
7272
- [appwrite_auth_team](resources/auth_team.md) - Manage teams
7373

74+
### Functions
75+
76+
- [appwrite_function](resources/function.md) - Manage functions
77+
- [appwrite_function_variable](resources/function_variable.md) - Manage function environment variables
78+
- [appwrite_function_deployment](resources/function_deployment.md) - Manage function deployments
79+
80+
### Sites
81+
82+
- [appwrite_site](resources/site.md) - Manage sites
83+
- [appwrite_site_variable](resources/site_variable.md) - Manage site environment variables
84+
- [appwrite_site_deployment](resources/site_deployment.md) - Manage site deployments
85+
7486
### Messaging
7587

7688
- [appwrite_messaging_provider](resources/messaging_provider.md) - Manage messaging providers (email, SMS, push)

docs/resources/function.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,6 @@ resource "appwrite_function" "api" {
106106

107107
## See Also
108108

109+
- [appwrite_function_deployment](function_deployment.md) - Manage function deployments
109110
- [appwrite_function_variable](function_variable.md) - Manage function environment variables
110111
- [appwrite_webhook](webhook.md) - Manage webhooks
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
page_title: "Resource: appwrite_function_deployment"
3+
subcategory: "Functions"
4+
description: |-
5+
Manages an Appwrite function deployment.
6+
---
7+
8+
# Resource: appwrite_function_deployment
9+
10+
Manages an Appwrite function deployment.
11+
12+
Deployments are immutable - any change to input attributes will destroy the existing deployment and create a new one. Use the `wait_for_ready` attribute (default `true`) to wait for the build to complete before Terraform proceeds.
13+
14+
-> **Tip:** Use `code_hash = filesha256("./code.tar.gz")` to trigger a new deployment when your code file changes, even if the file path stays the same.
15+
16+
## Example Usage
17+
18+
### Code Upload
19+
20+
```terraform
21+
resource "appwrite_function_deployment" "process_order" {
22+
function_id = appwrite_function.process_order.id
23+
source_type = "code"
24+
code_path = "./process-order.tar.gz"
25+
code_hash = filesha256("./process-order.tar.gz")
26+
entrypoint = "index.js"
27+
commands = "npm install"
28+
activate = true
29+
}
30+
```
31+
32+
### Template
33+
34+
```terraform
35+
resource "appwrite_function_deployment" "daily_report" {
36+
function_id = appwrite_function.daily_report.id
37+
source_type = "template"
38+
repository = "templates"
39+
owner = "appwrite"
40+
root_directory = "node/starter"
41+
type = "branch"
42+
reference = "main"
43+
activate = true
44+
}
45+
```
46+
47+
<!-- schema generated by tfplugindocs -->
48+
## Schema
49+
50+
### Required
51+
52+
- `function_id` (String) The function ID this deployment belongs to.
53+
- `source_type` (String) The deployment source type. Must be one of "code" or "template".
54+
55+
### Optional
56+
57+
- `activate` (Boolean) Whether to activate this deployment after creation.
58+
- `code_hash` (String) Hash of the code file for drift detection. Use filesha256() to compute.
59+
- `code_path` (String) Local path to the code tar.gz file to upload. Required when source_type is code.
60+
- `commands` (String) Build commands for code deployments.
61+
- `entrypoint` (String) The entrypoint file for code deployments.
62+
- `owner` (String) Repository owner for template deployments.
63+
- `project_id` (String) The Appwrite project ID. Defaults to the provider-level project_id.
64+
- `reference` (String) Reference value for template deployments (e.g. branch name, tag, or commit hash).
65+
- `repository` (String) Repository name for template deployments.
66+
- `root_directory` (String) Root directory in the repository for template deployments.
67+
- `type` (String) Reference type for template deployments (e.g. "branch", "tag", "commit").
68+
- `wait_for_ready` (Boolean) Whether to wait for the deployment to reach ready status before completing. Defaults to true.
69+
70+
### Read-Only
71+
72+
- `build_duration` (Number) The build duration in seconds.
73+
- `build_logs` (String) The build logs.
74+
- `build_size` (Number) The build output size in bytes.
75+
- `created_at` (String) The deployment creation timestamp in ISO 8601 format.
76+
- `id` (String) The deployment ID.
77+
- `source_size` (Number) The source code size in bytes.
78+
- `status` (String) The deployment build status.
79+
- `total_size` (Number) The total size in bytes.
80+
- `updated_at` (String) The deployment last update timestamp in ISO 8601 format.
81+
82+
83+
84+
~> **NOTE:** Imported deployments will not have `source_type`, `code_path`, or template attributes in state since these are not returned by the API. The imported resource can be read and deleted but not recreated without specifying these attributes.
85+
86+
## See Also
87+
88+
- [appwrite_function](function.md) - Manage functions
89+
- [appwrite_function_variable](function_variable.md) - Manage function environment variables

docs/resources/function_variable.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,4 @@ import {
6868
## See Also
6969

7070
- [appwrite_function](function.md) - Manage functions
71+
- [appwrite_function_deployment](function_deployment.md) - Manage function deployments

docs/resources/site.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,6 @@ resource "appwrite_site" "app" {
111111

112112
## See Also
113113

114+
- [appwrite_site_deployment](site_deployment.md) - Manage site deployments
114115
- [appwrite_site_variable](site_variable.md) - Manage site environment variables
115116
- [appwrite_webhook](webhook.md) - Manage webhooks

docs/resources/site_deployment.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
page_title: "Resource: appwrite_site_deployment"
3+
subcategory: "Sites"
4+
description: |-
5+
Manages an Appwrite site deployment.
6+
---
7+
8+
# Resource: appwrite_site_deployment
9+
10+
Manages an Appwrite site deployment.
11+
12+
Deployments are immutable - any change to input attributes will destroy the existing deployment and create a new one. Use the `wait_for_ready` attribute (default `true`) to wait for the build to complete before Terraform proceeds.
13+
14+
-> **Tip:** Use `code_hash = filesha256("./dist.tar.gz")` to trigger a new deployment when your code file changes, even if the file path stays the same.
15+
16+
## Example Usage
17+
18+
### Code Upload
19+
20+
```terraform
21+
resource "appwrite_site_deployment" "landing_page" {
22+
site_id = appwrite_site.landing_page.id
23+
source_type = "code"
24+
code_path = "./dist.tar.gz"
25+
code_hash = filesha256("./dist.tar.gz")
26+
activate = true
27+
}
28+
```
29+
30+
### Template
31+
32+
```terraform
33+
resource "appwrite_site_deployment" "dashboard" {
34+
site_id = appwrite_site.dashboard.id
35+
source_type = "template"
36+
repository = "templates-for-sites"
37+
owner = "appwrite"
38+
root_directory = "nextjs/starter"
39+
type = "branch"
40+
reference = "main"
41+
activate = true
42+
}
43+
```
44+
45+
<!-- schema generated by tfplugindocs -->
46+
## Schema
47+
48+
### Required
49+
50+
- `site_id` (String) The site ID this deployment belongs to.
51+
- `source_type` (String) The deployment source type. Must be one of "code" or "template".
52+
53+
### Optional
54+
55+
- `activate` (Boolean) Whether to activate this deployment after creation.
56+
- `build_command` (String) Custom build command for code deployments.
57+
- `code_hash` (String) Hash of the code file for drift detection. Use filesha256() to compute.
58+
- `code_path` (String) Local path to the code file to upload. Required when source_type is code.
59+
- `install_command` (String) Custom install command for code deployments.
60+
- `output_directory` (String) Build output directory for code deployments.
61+
- `owner` (String) Repository owner for template deployments.
62+
- `project_id` (String) The Appwrite project ID. Defaults to the provider-level project_id.
63+
- `reference` (String) Reference value for template deployments (e.g. branch name, tag, or commit hash).
64+
- `repository` (String) Repository name for template deployments.
65+
- `root_directory` (String) Root directory in the repository for template deployments.
66+
- `type` (String) Reference type for template deployments (e.g. "branch", "tag", "commit").
67+
- `wait_for_ready` (Boolean) Whether to wait for the deployment to reach ready status before completing. Defaults to true.
68+
69+
### Read-Only
70+
71+
- `build_duration` (Number) The build duration in seconds.
72+
- `build_logs` (String) The build logs.
73+
- `build_size` (Number) The build output size in bytes.
74+
- `created_at` (String) The deployment creation timestamp in ISO 8601 format.
75+
- `id` (String) The deployment ID.
76+
- `source_size` (Number) The source code size in bytes.
77+
- `status` (String) The deployment build status.
78+
- `total_size` (Number) The total size in bytes.
79+
- `updated_at` (String) The deployment last update timestamp in ISO 8601 format.
80+
81+
82+
83+
~> **NOTE:** Imported deployments will not have `source_type`, `code_path`, or template attributes in state since these are not returned by the API. The imported resource can be read and deleted but not recreated without specifying these attributes.
84+
85+
## See Also
86+
87+
- [appwrite_site](site.md) - Manage sites
88+
- [appwrite_site_variable](site_variable.md) - Manage site environment variables

docs/resources/site_variable.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,4 @@ import {
6868
## See Also
6969

7070
- [appwrite_site](site.md) - Manage sites
71+
- [appwrite_site_deployment](site_deployment.md) - Manage site deployments

examples/dist.tar.gz

459 Bytes
Binary file not shown.

examples/functions.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,26 @@ resource "appwrite_function_variable" "daily_report_smtp_host" {
2727
key = "SMTP_HOST"
2828
value = "smtp.example.com"
2929
}
30+
31+
# Deploy a function from a code upload
32+
resource "appwrite_function_deployment" "process_order_code" {
33+
function_id = appwrite_function.process_order.id
34+
source_type = "code"
35+
code_path = "./process-order.tar.gz"
36+
code_hash = filesha256("./process-order.tar.gz")
37+
entrypoint = "index.js"
38+
commands = "npm install"
39+
activate = true
40+
}
41+
42+
# Deploy a function from a template
43+
resource "appwrite_function_deployment" "daily_report_template" {
44+
function_id = appwrite_function.daily_report.id
45+
source_type = "template"
46+
repository = "templates"
47+
owner = "appwrite"
48+
root_directory = "node/starter"
49+
type = "branch"
50+
reference = "main"
51+
activate = true
52+
}

0 commit comments

Comments
 (0)