Skip to content

Commit

Permalink
feat: move tenant_id at provider level
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Nov 4, 2023
1 parent b538de2 commit f81007f
Show file tree
Hide file tree
Showing 44 changed files with 223 additions and 157 deletions.
5 changes: 1 addition & 4 deletions docs/data-sources/binding.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@ data "kestra_binding" "example" {

- `binding_id` (String) The binding id.

### Optional

- `tenant_id` (String) The tenant id.

### Read-Only

- `external_id` (String) The binding external id.
- `id` (String) The ID of this resource.
- `namespace` (String) The linked namespace.
- `role_id` (String) The role id.
- `tenant_id` (String) The tenant id.
- `type` (String) The binding type.
2 changes: 1 addition & 1 deletion docs/data-sources/flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ data "kestra_flow" "example" {
### Optional

- `keep_original_source` (Boolean) Use the content as source code, keeping comment and indentation. Defaults to `false`.
- `tenant_id` (String) The tenant id.

### Read-Only

- `content` (String) The flow content as yaml.
- `id` (String) The ID of this resource.
- `revision` (Number) The flow revision.
- `tenant_id` (String) The tenant id.
2 changes: 1 addition & 1 deletion docs/data-sources/group.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ data "kestra_group" "example" {
### Optional

- `namespace` (String) The linked namespace.
- `tenant_id` (String) The tenant id.

### Read-Only

- `description` (String) The group description.
- `id` (String) The ID of this resource.
- `name` (String) The group name.
- `tenant_id` (String) The tenant id.
5 changes: 1 addition & 4 deletions docs/data-sources/namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ data "kestra_namespace" "example" {

- `namespace_id` (String) The namespace.

### Optional

- `tenant_id` (String) The tenant id.

### Read-Only

- `description` (String) The namespace friendly description.
- `id` (String) The ID of this resource.
- `task_defaults` (String) The namespace task defaults.
- `tenant_id` (String) The tenant id.
- `variables` (String) The namespace variables.
2 changes: 1 addition & 1 deletion docs/data-sources/role.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ data "kestra_role" "example" {
### Optional

- `namespace` (String) The linked namespace.
- `tenant_id` (String) The tenant id.

### Read-Only

- `description` (String) The role description.
- `id` (String) The ID of this resource.
- `name` (String) The role name.
- `permissions` (Set of Object) The role permissions. (see [below for nested schema](#nestedatt--permissions))
- `tenant_id` (String) The tenant id.

<a id="nestedatt--permissions"></a>
### Nested Schema for `permissions`
Expand Down
5 changes: 1 addition & 4 deletions docs/data-sources/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ data "kestra_template" "example" {
- `namespace` (String) The namespace.
- `template_id` (String) The template id.

### Optional

- `tenant_id` (String) The tenant id.

### Read-Only

- `content` (String) The template content as yaml.
- `id` (String) The ID of this resource.
- `tenant_id` (String) The tenant id.
5 changes: 4 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ provider "kestra" {
# optional basic auth password
password = "my-password"
# optional jwt token
# optional jwt token (EE)
jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Iktlc3RyYS5pbyIsImlhdCI6MTUxNjIzOTAyMn0.hm2VKztDJP7CUsI69Th6Y5NLEQrXx7OErLXay55GD5U"
# optional tenant id (EE)
tenant_id = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Iktlc3RyYS5pbyIsImlhdCI6MTUxNjIzOTAyMn0.hm2VKztDJP7CUsI69Th6Y5NLEQrXx7OErLXay55GD5U"
# optional extra headers
extra_headers = {
x-pipeline = "*****"
Expand Down
1 change: 0 additions & 1 deletion docs/resources/binding.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ resource "kestra_binding" "example" {
### Optional

- `namespace` (String) The linked namespace.
- `tenant_id` (String) The tenant id.

### Read-Only

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ EOT
### Optional

- `keep_original_source` (Boolean) Use the content as source code, keeping comment and indentation. Defaults to `true`.
- `tenant_id` (String) The tenant id.

### Read-Only

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

## Import

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/group.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ resource "kestra_group" "example" {

- `description` (String) The group description.
- `namespace` (String) The linked namespace.
- `tenant_id` (String) The tenant id.

### Read-Only

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

## Import

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ EOT

- `description` (String) The namespace friendly description.
- `task_defaults` (String) The namespace task defaults in yaml string.
- `tenant_id` (String) The tenant id.
- `variables` (String) The namespace variables in yaml string.

### Read-Only

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

## Import

Expand Down
5 changes: 1 addition & 4 deletions docs/resources/namespace_secret.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ resource "kestra_namespace_secret" "example" {
- `secret_key` (String) The namespace secrey key.
- `secret_value` (String, Sensitive) The namespace secrey value.

### Optional

- `tenant_id` (String) The tenant id.

### Read-Only

- `id` (String) The ID of this resource.
- `tenant_id` (String) The tenant id.
2 changes: 1 addition & 1 deletion docs/resources/role.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ resource "kestra_role" "example" {
- `description` (String) The role description.
- `namespace` (String) The linked namespace.
- `permissions` (Block Set) The role permissions. (see [below for nested schema](#nestedblock--permissions))
- `tenant_id` (String) The tenant id.

### Read-Only

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

<a id="nestedblock--permissions"></a>
### Nested Schema for `permissions`
Expand Down
5 changes: 1 addition & 4 deletions docs/resources/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@ EOT
- `namespace` (String) The template namespace.
- `template_id` (String) The template id.

### Optional

- `tenant_id` (String) The tenant id.

### Read-Only

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

## Import

Expand Down
5 changes: 4 additions & 1 deletion examples/provider/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ provider "kestra" {
# optional basic auth password
password = "my-password"

# optional jwt token
# optional jwt token (EE)
jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Iktlc3RyYS5pbyIsImlhdCI6MTUxNjIzOTAyMn0.hm2VKztDJP7CUsI69Th6Y5NLEQrXx7OErLXay55GD5U"

# optional tenant id (EE)
tenant_id = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Iktlc3RyYS5pbyIsImlhdCI6MTUxNjIzOTAyMn0.hm2VKztDJP7CUsI69Th6Y5NLEQrXx7OErLXay55GD5U"

# optional extra headers
extra_headers = {
x-pipeline = "*****"
Expand Down
5 changes: 4 additions & 1 deletion internal/provider/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ type Client struct {
Password *string
Jwt *string
ExtraHeader *map[string]string
TenantId *string
}

type RequestError struct {
StatusCode int
Err error
}

func NewClient(url string, username *string, password *string, jwt *string, extraHeaders *interface{}) (*Client, error) {
func NewClient(url string, username *string, password *string, jwt *string, extraHeaders *interface{}, tenantId *string) (*Client, error) {
c := Client{
HTTPClient: &http.Client{Timeout: 10 * time.Second},
Url: DefaultURL,
Expand All @@ -53,6 +54,8 @@ func NewClient(url string, username *string, password *string, jwt *string, extr
}
}

c.TenantId = tenantId

return &c, nil
}

Expand Down
6 changes: 3 additions & 3 deletions internal/provider/data_source_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func dataSourceBinding() *schema.Resource {
"tenant_id": {
Description: "The tenant id.",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"binding_id": {
Description: "The binding id.",
Expand Down Expand Up @@ -53,14 +53,14 @@ func dataSourceBindingRead(ctx context.Context, d *schema.ResourceData, meta int
var diags diag.Diagnostics

bindingId := d.Get("binding_id").(string)
tenantId := d.Get("tenant_id").(string)
tenantId := c.TenantId

r, reqErr := c.request("GET", fmt.Sprintf("%s/bindings/%s", apiRoot(tenantId), bindingId), nil)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}

errs := bindingApiToSchema(r.(map[string]interface{}), d)
errs := bindingApiToSchema(r.(map[string]interface{}), d, c)
if errs != nil {
return errs
}
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/data_source_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func dataSourceFlow() *schema.Resource {
"tenant_id": {
Description: "The tenant id.",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"namespace": {
Description: "The namespace.",
Expand Down Expand Up @@ -55,14 +55,14 @@ func dataSourceFlowRead(ctx context.Context, d *schema.ResourceData, meta interf

namespaceId := d.Get("namespace").(string)
flowId := d.Get("flow_id").(string)
tenantId := d.Get("tenant_id").(string)
tenantId := c.TenantId

r, reqErr := c.request("GET", fmt.Sprintf("%s/flows/%s/%s", apiRoot(tenantId), namespaceId, flowId), nil)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}

errs := flowApiToSchema(r.(map[string]interface{}), d)
errs := flowApiToSchema(r.(map[string]interface{}), d, c)
if errs != nil {
return errs
}
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/data_source_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func dataSourceGroup() *schema.Resource {
"tenant_id": {
Description: "The tenant id.",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"group_id": {
Description: "The group.",
Expand Down Expand Up @@ -48,14 +48,14 @@ func dataSourceGroupRead(ctx context.Context, d *schema.ResourceData, meta inter
var diags diag.Diagnostics

groupId := d.Get("group_id").(string)
tenantId := d.Get("tenant_id").(string)
tenantId := c.TenantId

r, reqErr := c.request("GET", fmt.Sprintf("%s/groups/%s", apiRoot(tenantId), groupId), nil)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}

errs := groupApiToSchema(r.(map[string]interface{}), d)
errs := groupApiToSchema(r.(map[string]interface{}), d, c)
if errs != nil {
return errs
}
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/data_source_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func dataSourceNamespace() *schema.Resource {
"tenant_id": {
Description: "The tenant id.",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"namespace_id": {
Description: "The namespace.",
Expand Down Expand Up @@ -48,14 +48,14 @@ func dataSourceNamespaceRead(ctx context.Context, d *schema.ResourceData, meta i
var diags diag.Diagnostics

namespaceId := d.Get("namespace_id").(string)
tenantId := d.Get("tenant_id").(string)
tenantId := c.TenantId

r, reqErr := c.request("GET", fmt.Sprintf("%s/namespaces/%s", apiRoot(tenantId), namespaceId), nil)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}

errs := namespaceApiToSchema(r.(map[string]interface{}), d)
errs := namespaceApiToSchema(r.(map[string]interface{}), d, c)
if errs != nil {
return errs
}
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/data_source_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func dataSourceRole() *schema.Resource {
"tenant_id": {
Description: "The tenant id.",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"role_id": {
Description: "The role.",
Expand Down Expand Up @@ -68,14 +68,14 @@ func dataSourceRoleRead(ctx context.Context, d *schema.ResourceData, meta interf
var diags diag.Diagnostics

roleId := d.Get("role_id").(string)
tenantId := d.Get("tenant_id").(string)
tenantId := c.TenantId

r, reqErr := c.request("GET", fmt.Sprintf("%s/roles/%s", apiRoot(tenantId), roleId), nil)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}

errs := roleApiToSchema(r.(map[string]interface{}), d)
errs := roleApiToSchema(r.(map[string]interface{}), d, c)
if errs != nil {
return errs
}
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/data_source_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func dataSourceTemplate() *schema.Resource {
"tenant_id": {
Description: "The tenant id.",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"namespace": {
Description: "The namespace.",
Expand All @@ -44,14 +44,14 @@ func dataSourceTemplateRead(ctx context.Context, d *schema.ResourceData, meta in

namespaceId := d.Get("namespace").(string)
templateId := d.Get("template_id").(string)
tenantId := d.Get("tenant_id").(string)
tenantId := c.TenantId

r, reqErr := c.request("GET", fmt.Sprintf("%s/templates/%s/%s", apiRoot(tenantId), namespaceId, templateId), nil)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}

errs := templateApiToSchema(r.(map[string]interface{}), d)
errs := templateApiToSchema(r.(map[string]interface{}), d, c)
if errs != nil {
return errs
}
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/data_source_tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func dataSourceTenantRead(ctx context.Context, d *schema.ResourceData, meta inte

tenantId := d.Get("tenant_id").(string)

r, reqErr := c.request("GET", fmt.Sprintf("%s/tenants/%s", apiRoot(""), tenantId), nil)
r, reqErr := c.request("GET", fmt.Sprintf("%s/tenants/%s", apiRoot(nil), tenantId), nil)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}
Expand Down
Loading

0 comments on commit f81007f

Please sign in to comment.