-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from mittwald/feature/cronjob
Add support for "mittwald_cronjob" resource
- Loading branch information
Showing
17 changed files
with
714 additions
and
1 deletion.
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,70 @@ | ||
package mittwaldv2 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/google/uuid" | ||
) | ||
|
||
type CronjobClient interface { | ||
GetCronjob(ctx context.Context, cronjobID string) (*DeMittwaldV1CronjobCronjob, error) | ||
CreateCronjob(ctx context.Context, projectID string, body CronjobCreateCronjobJSONRequestBody) (string, error) | ||
UpdateCronjob(ctx context.Context, cronjobID string, body CronjobUpdateCronjobJSONRequestBody) error | ||
DeleteCronjob(ctx context.Context, cronjobID string) error | ||
} | ||
|
||
type cronjobClient struct { | ||
client ClientWithResponsesInterface | ||
} | ||
|
||
func (c *cronjobClient) GetCronjob(ctx context.Context, cronjobID string) (*DeMittwaldV1CronjobCronjob, error) { | ||
resp, err := c.client.CronjobGetCronjobWithResponse(ctx, uuid.MustParse(cronjobID)) | ||
if err != nil { | ||
return nil, fmt.Errorf("error getting cronjob: %w", err) | ||
} | ||
|
||
if resp.JSON200 == nil { | ||
return nil, errUnexpectedStatus(resp.StatusCode(), resp.Body) | ||
} | ||
|
||
return resp.JSON200, nil | ||
} | ||
|
||
func (c *cronjobClient) CreateCronjob(ctx context.Context, projectID string, body CronjobCreateCronjobJSONRequestBody) (string, error) { | ||
resp, err := c.client.CronjobCreateCronjobWithResponse(ctx, uuid.MustParse(projectID), body) | ||
if err != nil { | ||
return "", fmt.Errorf("error creating cronjob: %w", err) | ||
} | ||
|
||
if resp.JSON201 == nil { | ||
return "", errUnexpectedStatus(resp.StatusCode(), resp.Body) | ||
} | ||
|
||
return resp.JSON201.Id.String(), nil | ||
} | ||
|
||
func (c *cronjobClient) DeleteCronjob(ctx context.Context, cronjobID string) error { | ||
resp, err := c.client.CronjobDeleteCronjobWithResponse(ctx, uuid.MustParse(cronjobID)) | ||
if err != nil { | ||
return fmt.Errorf("error deleting cronjob: %w", err) | ||
} | ||
|
||
if resp.StatusCode() != 204 { | ||
return errUnexpectedStatus(resp.StatusCode(), resp.Body) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *cronjobClient) UpdateCronjob(ctx context.Context, cronjobID string, body CronjobUpdateCronjobJSONRequestBody) error { | ||
resp, err := c.client.CronjobUpdateCronjobWithResponse(ctx, uuid.MustParse(cronjobID), body) | ||
if err != nil { | ||
return fmt.Errorf("error updating cronjob: %w", err) | ||
} | ||
|
||
if resp.JSON200 == nil { | ||
return errUnexpectedStatus(resp.StatusCode(), resp.Body) | ||
} | ||
|
||
return nil | ||
} |
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,70 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "mittwald_cronjob Resource - terraform-provider-mittwald" | ||
subcategory: "" | ||
description: |- | ||
This resource models a cron job. | ||
--- | ||
|
||
# mittwald_cronjob (Resource) | ||
|
||
This resource models a cron job. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "mittwald_cronjob" "demo" { | ||
project_id = mittwald_project.foobar.id | ||
app_id = mittwald_app.wordpress.id | ||
interval = "*/5 * * * *" | ||
description = "Demo Cronjob" | ||
destination = { | ||
command = { | ||
interpreter = "php" | ||
path = "/html" | ||
arguments = ["-r", "echo 'Hello World';"] | ||
} | ||
} | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `app_id` (String) The ID of the app the cron job belongs to | ||
- `description` (String) Description for your cron job | ||
- `destination` (Attributes) Models the action to be executed by the cron job. Exactly one of `url` or `command` must be set. (see [below for nested schema](#nestedatt--destination)) | ||
- `interval` (String) The interval of the cron job; this should be a cron expression | ||
- `project_id` (String) The ID of the project the cron job belongs to | ||
|
||
### Optional | ||
|
||
- `email` (String) The email address to send the cron job's output to | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The generated cron job ID | ||
|
||
<a id="nestedatt--destination"></a> | ||
### Nested Schema for `destination` | ||
|
||
Optional: | ||
|
||
- `command` (Attributes) (see [below for nested schema](#nestedatt--destination--command)) | ||
- `url` (String) The URL that should be requested by the cron job | ||
|
||
<a id="nestedatt--destination--command"></a> | ||
### Nested Schema for `destination.command` | ||
|
||
Required: | ||
|
||
- `interpreter` (String) The interpreter to use for the command. Must be a valid path to an executable within the project environment (typically, `/bin/bash` or `/usr/bin/php` should work). | ||
- `path` (String) The path to the file to run. Must be a valid path to an executable file within the project environment. | ||
|
||
Optional: | ||
|
||
- `parameters` (List of String) A list of parameters to pass to the command. Each parameter must be a valid string. |
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,15 @@ | ||
resource "mittwald_cronjob" "demo" { | ||
project_id = mittwald_project.foobar.id | ||
app_id = mittwald_app.wordpress.id | ||
|
||
interval = "*/5 * * * *" | ||
description = "Demo Cronjob" | ||
|
||
destination = { | ||
command = { | ||
interpreter = "php" | ||
path = "/html" | ||
arguments = ["-r", "echo 'Hello World';"] | ||
} | ||
} | ||
} |
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
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,11 @@ | ||
package providerutil | ||
|
||
import ( | ||
"github.com/google/uuid" | ||
"github.com/hashicorp/terraform-plugin-framework/diag" | ||
) | ||
|
||
func ParseUUID(in string, d *diag.Diagnostics) uuid.UUID { | ||
return Try[uuid.UUID](d, "Invalid app ID"). | ||
DoVal(uuid.Parse(in)) | ||
} |
Oops, something went wrong.