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 support for the namespace file resource and datasource
- Loading branch information
Martin GUIBERT
committed
Oct 26, 2023
1 parent
6ecd198
commit 4e887f2
Showing
12 changed files
with
565 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "kestra_namespace_file Data Source - terraform-provider-kestra" | ||
subcategory: "" | ||
description: |- | ||
Use this data source to access information about an existing Namespace File | ||
--- | ||
|
||
# kestra_namespace_file (Data Source) | ||
|
||
Use this data source to access information about an existing Namespace File | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "kestra_namespace_file" "example" { | ||
namespace_ = "io.kestra.mynamespace" | ||
filename = "my-file.yml" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `filename` (String) The path to the namespace file that will be created. | ||
Missing parent directories will be created. | ||
If the file already exists, it will be overridden with the given content. | ||
- `namespace` (String) The Namespace file namespace. | ||
|
||
### Optional | ||
|
||
- `content` (String) Content to store in the file, expected to be a UTF-8 encoded string. | ||
- `tenant_id` (String) The tenant id. | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. |
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,62 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "kestra_namespace_file Resource - terraform-provider-kestra" | ||
subcategory: "" | ||
description: |- | ||
Manages a Kestra Namespace File. | ||
--- | ||
|
||
# kestra_namespace_file (Resource) | ||
|
||
Manages a Kestra Namespace File. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "kestra_namespace_file" "example" { | ||
namespace = "io.kestra.mynamespace" | ||
filename = "/path/my-file.sh" | ||
content = <<EOT | ||
#!/bin/bash | ||
echo "Hello World" | ||
EOT | ||
} | ||
resource "kestra_namespace_file" "withsource" { | ||
namespace = "io.kestra.mynamespace" | ||
filename = "/path/my-file.sh" | ||
content = "./kestra/file.sh" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `filename` (String) The path to the namespace file that will be created. | ||
Missing parent directories will be created. | ||
If the file already exists, it will be overridden with the given content. | ||
- `namespace` (String) The Namespace file namespace. | ||
|
||
### Optional | ||
|
||
- `content` (String) Content to store in the file, expected to be a UTF-8 encoded string. | ||
Conflicts with `source`. | ||
Exactly one of these four arguments must be specified. | ||
- `source` (String) Path to file to use as source for the one we are creating. | ||
Conflicts with `content`. | ||
Exactly one of these four arguments must be specified. | ||
- `tenant_id` (String) The tenant id. | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
terraform import kestra_namespace_file.example {{namespace}}/{{filename}} | ||
``` |
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,4 @@ | ||
data "kestra_namespace_file" "example" { | ||
namespace_ = "io.kestra.mynamespace" | ||
filename = "my-file.yml" | ||
} |
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 @@ | ||
terraform import kestra_namespace_file.example {{namespace}}/{{filename}} |
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,14 @@ | ||
resource "kestra_namespace_file" "example" { | ||
namespace = "io.kestra.mynamespace" | ||
filename = "/path/my-file.sh" | ||
content = <<EOT | ||
#!/bin/bash | ||
echo "Hello World" | ||
EOT | ||
} | ||
|
||
resource "kestra_namespace_file" "withsource" { | ||
namespace = "io.kestra.mynamespace" | ||
filename = "/path/my-file.sh" | ||
content = "./kestra/file.sh" | ||
} |
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,85 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceNamespaceFile() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Use this data source to access information about an existing Namespace File", | ||
|
||
ReadContext: dataSourceNamespaceFileRead, | ||
Schema: map[string]*schema.Schema{ | ||
"tenant_id": { | ||
Description: "The tenant id.", | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
}, | ||
"namespace": { | ||
Description: "The Namespace file namespace.", | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"filename": { | ||
Description: "The path to the namespace file that will be created.\n" + | ||
"Missing parent directories will be created.\n" + | ||
"If the file already exists, it will be overridden with the given content.", | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"content": { | ||
Description: "Content to store in the file, expected to be a UTF-8 encoded string.", | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceNamespaceFileRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
c := meta.(*Client) | ||
var diags diag.Diagnostics | ||
|
||
namespace := d.Get("namespace").(string) | ||
filename := d.Get("filename").(string) | ||
tenantId := d.Get("tenant_id").(string) | ||
|
||
url := c.Url + fmt.Sprintf("%s/files/namespaces/%s?path=%s", apiRoot(tenantId), namespace, filename) | ||
|
||
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf(url), nil) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
statusCode, body, reqErr := c.rawResponseRequest("GET", req) | ||
if reqErr != nil { | ||
if statusCode == http.StatusNotFound { | ||
d.SetId("") | ||
return diags | ||
} | ||
return diag.FromErr(reqErr.Err) | ||
} | ||
|
||
d.SetId(fmt.Sprintf("%s/%s", namespace, filename)) | ||
if err := d.Set("namespace", namespace); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
if err := d.Set("filename", filename); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
if err := d.Set("content", string(body)); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
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,37 @@ | ||
package provider | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceNamespaceFile(t *testing.T) { | ||
resource.UnitTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: providerFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceNamespaceFile("io.kestra.terraform.data", "/flow.py"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr( | ||
"data.kestra_template.new", "filename", "/flow.py", | ||
), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceNamespaceFile(namespace, filename string) string { | ||
return fmt.Sprintf( | ||
` | ||
data "kestra_namespace_file" "new" { | ||
namespace = "%s" | ||
filename = "%s" | ||
}`, | ||
namespace, | ||
filename, | ||
) | ||
} |
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
Oops, something went wrong.