generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(): add missing resources + docs
- Loading branch information
Showing
6 changed files
with
344 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package provider | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccResourceApp(t *testing.T) { | ||
resource.UnitTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: providerFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccResourceApp("new"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet("kestra_app.new", "id"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccResourceApp(resourceId string) string { | ||
return fmt.Sprintf( | ||
` | ||
resource "kestra_flow" "new_flow" { | ||
namespace = "company.team" | ||
flow_id = "get_data" | ||
content = <<EOT | ||
id: get_data | ||
namespace: company.team | ||
tasks: | ||
- id: hello | ||
type: io.kestra.plugin.core.log.Log | ||
message: Hello World! 🚀 | ||
EOT | ||
} | ||
resource "kestra_app" "%s" { | ||
source = <<-EOF | ||
id: test_tf | ||
type: io.kestra.plugin.ee.apps.Execution | ||
displayName: New display name | ||
namespace: company.team | ||
flowId: get_data | ||
access: PRIVATE | ||
layout: | ||
- on: OPEN | ||
blocks: | ||
- type: io.kestra.plugin.ee.apps.core.blocks.Markdown | ||
content: | | ||
## Request data | ||
Select the dataset you want to download. | ||
EOF | ||
}`, | ||
resourceId) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
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 resourceDashboard() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Manages a Dashboard resource.", | ||
|
||
CreateContext: resourceDashboardCreate, | ||
ReadContext: resourceDashboardRead, | ||
UpdateContext: resourceDashboardUpdate, | ||
DeleteContext: resourceDashboardDelete, | ||
Schema: map[string]*schema.Schema{ | ||
"source_code": { | ||
Description: "The source code text.", | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"id": { | ||
Description: "The unique identifier.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceDashboardCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
c := meta.(*Client) | ||
var diags diag.Diagnostics | ||
|
||
sourceCode := d.Get("source_code").(string) | ||
|
||
req, reqErr := c.yamlRequest("POST", fmt.Sprintf("%s/dashboards", apiRoot(c.TenantId)), &sourceCode) | ||
if reqErr != nil { | ||
return diag.FromErr(reqErr.Err) | ||
} | ||
|
||
d.SetId(req.(map[string]interface{})["id"].(string)) | ||
|
||
return diags | ||
} | ||
|
||
func resourceDashboardRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
c := meta.(*Client) | ||
var diags diag.Diagnostics | ||
|
||
id := d.Id() | ||
url := fmt.Sprintf("%s/dashboards/%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_code", response["sourceCode"].(string)); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
if err := d.Set("id", response["id"].(string)); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return diags | ||
} | ||
|
||
func resourceDashboardUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
c := meta.(*Client) | ||
var diags diag.Diagnostics | ||
|
||
if d.HasChanges("source_code") { | ||
id := d.Id() | ||
sourceCode := d.Get("source_code").(string) | ||
url := fmt.Sprintf("%s/dashboards/%s", apiRoot(c.TenantId), id) | ||
|
||
_, reqErr := c.yamlRequest("PUT", url, &sourceCode) | ||
if reqErr != nil { | ||
return diag.FromErr(reqErr.Err) | ||
} | ||
|
||
return diags | ||
} | ||
return resourceDashboardRead(ctx, d, meta) | ||
} | ||
|
||
func resourceDashboardDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
c := meta.(*Client) | ||
var diags diag.Diagnostics | ||
|
||
id := d.Id() | ||
url := fmt.Sprintf("%s/dashboards/%s", apiRoot(c.TenantId), id) | ||
|
||
_, reqErr := c.request("DELETE", url, nil) | ||
if reqErr != nil { | ||
return diag.FromErr(reqErr.Err) | ||
} | ||
|
||
d.SetId("") | ||
return diags | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package provider | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccResourceDashboard(t *testing.T) { | ||
resource.UnitTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: providerFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccResourceDashboard("new"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet("kestra_dashboard.new", "id"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccResourceDashboard(resourceId string) string { | ||
return fmt.Sprintf( | ||
` | ||
resource "kestra_dashboard" "%s" { | ||
source_code = <<-EOF | ||
title: Overview_test | ||
charts: | ||
- id: executions_timeseries | ||
type: io.kestra.plugin.core.dashboard.chart.TimeSeries | ||
chartOptions: | ||
displayName: Executions | ||
description: Executions duration and count per date | ||
legend: | ||
enabled: true | ||
column: date | ||
colorByColumn: state | ||
data: | ||
type: io.kestra.plugin.core.dashboard.data.Executions | ||
columns: | ||
date: | ||
field: START_DATE | ||
displayName: Date | ||
state: | ||
field: STATE | ||
total: | ||
displayName: Executions | ||
agg: COUNT | ||
graphStyle: BARS | ||
EOF | ||
}`, | ||
resourceId) | ||
} |