Skip to content

Commit

Permalink
feat(): add missing resources + docs (#144)
Browse files Browse the repository at this point in the history
* feat(): add missing resources + docs

* chore(ci): update CI to use super admin kestra config

* feat(): doc from plugindocs

* feat(): missing props in namespace and tenants

* feat(): make email mandatory for user resource as its now in kestra 0.20
  • Loading branch information
Skraye authored Dec 20, 2024
1 parent 6188d3b commit 3edaead
Show file tree
Hide file tree
Showing 20 changed files with 582 additions and 27 deletions.
4 changes: 4 additions & 0 deletions .github/docker/application.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
kestra:
security:
super-admin:
username: [email protected]
password: Root!1234
encryption:
secret-key: LWBErwwlb/BQcxWujsm+/scPeO01cTKzvW44GbAWvII=
kafka:
Expand Down
28 changes: 14 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,20 @@ jobs:
curl "127.27.27.27:9200" > /dev/null
curl -X POST "127.27.27.27:8080/api/v1/users" > /dev/null
curl -u john@doe.com:pass -X POST -H 'Content-Type: application/json' -d '{"id":"unit_test","name":"Unit Test"}' "127.27.27.27:8080/api/v1/tenants" > /dev/null
curl -u root@root.com:Root!1234 -X POST -H 'Content-Type: application/json' -d '{"id":"unit_test","name":"Unit Test"}' "127.27.27.27:8080/api/v1/tenants" > /dev/null
curl -H "Content-Type: application/x-ndjson" -XPOST "127.27.27.27:9200/_bulk?pretty" --data-binary @.github/workflows/index.jsonl
sleep 3
curl -H "Content-Type: multipart/form-data" -u john@doe.com:pass -X POST -F fileContent=@internal/resources/flow.py "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/files?path=/flow.py"
curl -H "Content-Type: text/plain" -u john@doe.com:pass -X PUT -d '"stringValue"' "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/kv/string"
curl -H "Content-Type: text/plain" -u john@doe.com:pass -X PUT -d '1' "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/kv/int"
curl -H "Content-Type: text/plain" -u john@doe.com:pass -X PUT -d '1.5' "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/kv/double"
curl -H "Content-Type: text/plain" -u john@doe.com:pass -X PUT -d 'false' "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/kv/falseBoolean"
curl -H "Content-Type: text/plain" -u john@doe.com:pass -X PUT -d 'true' "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/kv/trueBoolean"
curl -H "Content-Type: text/plain" -u john@doe.com:pass -X PUT -d '2022-05-01T03:02:01Z' "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/kv/dateTime"
curl -H "Content-Type: text/plain" -u john@doe.com:pass -X PUT -d '2022-05-01' "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/kv/date"
curl -H "Content-Type: text/plain" -u john@doe.com:pass -X PUT -d 'P3DT3H2M1S' "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/kv/duration"
curl -H "Content-Type: application/json" -u john@doe.com:pass -X PUT -d '{"some":"value","in":"object"}' "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/kv/object"
curl -H "Content-Type: application/json" -u john@doe.com:pass -X PUT -d '[{"some":"value","in":"object"},{"yet":"another","array":"object"}]' "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/kv/array"
curl -H "Content-Type: multipart/form-data" -u root@root.com:Root!1234 -X POST -F fileContent=@internal/resources/flow.py "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/files?path=/flow.py"
curl -H "Content-Type: text/plain" -u root@root.com:Root!1234 -X PUT -d '"stringValue"' "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/kv/string"
curl -H "Content-Type: text/plain" -u root@root.com:Root!1234 -X PUT -d '1' "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/kv/int"
curl -H "Content-Type: text/plain" -u root@root.com:Root!1234 -X PUT -d '1.5' "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/kv/double"
curl -H "Content-Type: text/plain" -u root@root.com:Root!1234 -X PUT -d 'false' "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/kv/falseBoolean"
curl -H "Content-Type: text/plain" -u root@root.com:Root!1234 -X PUT -d 'true' "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/kv/trueBoolean"
curl -H "Content-Type: text/plain" -u root@root.com:Root!1234 -X PUT -d '2022-05-01T03:02:01Z' "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/kv/dateTime"
curl -H "Content-Type: text/plain" -u root@root.com:Root!1234 -X PUT -d '2022-05-01' "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/kv/date"
curl -H "Content-Type: text/plain" -u root@root.com:Root!1234 -X PUT -d 'P3DT3H2M1S' "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/kv/duration"
curl -H "Content-Type: application/json" -u root@root.com:Root!1234 -X PUT -d '{"some":"value","in":"object"}' "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/kv/object"
curl -H "Content-Type: application/json" -u root@root.com:Root!1234 -X PUT -d '[{"some":"value","in":"object"},{"yet":"another","array":"object"}]' "127.27.27.27:8080/api/v1/namespaces/io.kestra.terraform.data/kv/array"
- name: Set up Go
Expand All @@ -108,8 +108,8 @@ jobs:
TF_ACC: "1"
TF_ACC_TERRAFORM_VERSION: ${{ matrix.terraform }}
KESTRA_URL: "http://127.27.27.27:8080"
KESTRA_USERNAME: john@doe.com
KESTRA_PASSWORD: pass
KESTRA_USERNAME: root@root.com
KESTRA_PASSWORD: Root!1234
run: |
go test -v -cover ./internal/provider/
Expand Down
3 changes: 0 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ provider "kestra" {
# mandatory, the Kestra webserver/standalone URL
url = "http://localhost:8080"
# optional api token (EE)
api_token = "api-token-value"
# optional basic auth username
username = "john"
Expand Down
25 changes: 25 additions & 0 deletions docs/resources/app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "kestra_app Resource - terraform-provider-kestra"
subcategory: ""
description: |-
Manages an App resource.
---

# kestra_app (Resource)

Manages an App resource.



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `source` (String) The source text.

### Read-Only

- `id` (String) The ID of this resource.
- `uid` (String) The unique identifier.
24 changes: 24 additions & 0 deletions docs/resources/dashboard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "kestra_dashboard Resource - terraform-provider-kestra"
subcategory: ""
description: |-
Manages a Dashboard resource.
---

# kestra_dashboard (Resource)

Manages a Dashboard resource.



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `source_code` (String) The source code text.

### Read-Only

- `id` (String) The unique identifier.
2 changes: 1 addition & 1 deletion docs/resources/kv.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: |-

# kestra_kv (Resource)

Manages a Kestra Namespace Key Value Store.
Manages a Kestra Namespace File.



Expand Down
28 changes: 25 additions & 3 deletions docs/resources/namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Manages a Kestra Namespace.

```terraform
resource "kestra_namespace" "example" {
namespace_id = "company.team"
description = "Friendly description"
variables = <<EOT
namespace_id = "company.team"
description = "Friendly description"
variables = <<EOT
k1: 1
k2:
v1: 1
Expand All @@ -41,15 +41,37 @@ EOT

### Optional

- `allowed_namespaces` (Block List) The allowed namespaces. (see [below for nested schema](#nestedblock--allowed_namespaces))
- `description` (String) The namespace friendly description.
- `plugin_defaults` (String) The namespace plugin defaults in yaml string.
- `secret_configuration` (Map of String) The secret configuration.
- `secret_type` (String) The secret type.
- `storage_configuration` (Map of String) The storage configuration.
- `storage_type` (String) The storage type.
- `variables` (String) The namespace variables in yaml string.
- `worker_group` (Block List, Max: 1) The worker group. (see [below for nested schema](#nestedblock--worker_group))

### Read-Only

- `id` (String) The ID of this resource.
- `tenant_id` (String) The tenant id.

<a id="nestedblock--allowed_namespaces"></a>
### Nested Schema for `allowed_namespaces`

Required:

- `namespace` (String) The namespace.


<a id="nestedblock--worker_group"></a>
### Nested Schema for `worker_group`

Required:

- `fallback` (String) The fallback strategy.
- `key` (String) The worker group key.

## Import

Import is supported using the following syntax:
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/service_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Manages a Kestra Service Account.

```terraform
resource "kestra_service_account" "example" {
username = "my-service-account"
username = "my-service-account"
description = "Friendly description"
}
```
Expand Down
13 changes: 13 additions & 0 deletions docs/resources/tenant.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,24 @@ resource "kestra_tenant" "example" {
### Optional

- `name` (String) The tenant name.
- `secret_configuration` (Map of String) The secret configuration.
- `secret_type` (String) The secret type.
- `storage_configuration` (Map of String) The storage configuration.
- `storage_type` (String) The storage type.
- `worker_group` (Block List, Max: 1) The worker group. (see [below for nested schema](#nestedblock--worker_group))

### Read-Only

- `id` (String) The ID of this resource.

<a id="nestedblock--worker_group"></a>
### Nested Schema for `worker_group`

Required:

- `fallback` (String) The fallback strategy.
- `key` (String) The worker group key.

## Import

Import is supported using the following syntax:
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ resource "kestra_user" "example" {

### Required

- `email` (String) The user email.
- `username` (String) The user name.

### Optional

- `description` (String) The user description.
- `email` (String) The user email.
- `first_name` (String) The user first name.
- `groups` (List of String) The user groups id.
- `last_name` (String) The user last name.
Expand Down
6 changes: 3 additions & 3 deletions docs/resources/user_api_token.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Manages a Kestra User Api Token.
resource "kestra_user_api_token" "example" {
user_id = "4by6NvSLcPXFhCj8nwbZOM"
name = "test-token"
name = "test-token"
description = "Test token"
max_age = "PT1H"
extended = false
max_age = "PT1H"
extended = false
}
```

Expand Down
2 changes: 2 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ func New(version string, tenant *string) func() *schema.Provider {
"kestra_user_api_token": resourceUserApiToken(),
"kestra_kv": resourceKv(),
"kestra_worker_group": resourceWorkerGroup(),
"kestra_app": resourceApp(),
"kestra_dashboard": resourceDashboard(),
},
}

Expand Down
109 changes: 109 additions & 0 deletions internal/provider/resource_app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package provider

import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"net/http"
)

func resourceApp() *schema.Resource {
return &schema.Resource{
Description: "Manages an App resource.",

CreateContext: resourceAppCreate,
ReadContext: resourceAppRead,
UpdateContext: resourceAppUpdate,
DeleteContext: resourceAppDelete,
Schema: map[string]*schema.Schema{
"source": {
Description: "The source text.",
Type: schema.TypeString,
Required: true,
},
"uid": {
Description: "The unique identifier.",
Type: schema.TypeString,
Computed: true,
},
},
}
}

func resourceAppCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c := meta.(*Client)
var diags diag.Diagnostics

source := d.Get("source").(string)

req, reqErr := c.yamlRequest("POST", fmt.Sprintf("%s/apps", apiRoot(c.TenantId)), &source)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}

d.SetId(req.(map[string]interface{})["uid"].(string))
return diags
}

func resourceAppRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c := meta.(*Client)
var diags diag.Diagnostics

id := d.Id()
url := fmt.Sprintf("%s/apps/%s", apiRoot(c.TenantId), id)

req, reqErr := c.yamlRequest("GET", url, nil)
if reqErr != nil {
if reqErr.StatusCode == http.StatusNotFound {
d.SetId("")
return diags
}
return diag.FromErr(reqErr.Err)
}

response := req.(map[string]interface{})
if err := d.Set("source", response["source"].(string)); err != nil {
return diag.FromErr(err)
}
if err := d.Set("uid", response["uid"].(string)); err != nil {
return diag.FromErr(err)
}

return diags
}

func resourceAppUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c := meta.(*Client)
var diags diag.Diagnostics

if d.HasChanges("source") {
uid := d.Id()
source := d.Get("source").(string)
url := fmt.Sprintf("%s/apps/%s", apiRoot(c.TenantId), uid)

_, reqErr := c.yamlRequest("PUT", url, &source)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}

return diags
}
return resourceAppRead(ctx, d, meta)
}

func resourceAppDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c := meta.(*Client)
var diags diag.Diagnostics

uid := d.Id()
url := fmt.Sprintf("%s/apps/%s", apiRoot(c.TenantId), uid)

_, reqErr := c.request("DELETE", url, nil)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}

d.SetId("")
return diags
}
Loading

0 comments on commit 3edaead

Please sign in to comment.