-
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 #42 from mittwald/feature/vhosts
Add `mittwald_virtualhost` resource
- Loading branch information
Showing
14 changed files
with
471 additions
and
63 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,71 @@ | ||
package mittwaldv2 | ||
|
||
import ( | ||
"context" | ||
"github.com/google/uuid" | ||
) | ||
|
||
type DomainClient interface { | ||
GetIngress(ctx context.Context, ingressID string) (*DeMittwaldV1IngressIngress, error) | ||
CreateIngress(ctx context.Context, projectID string, body IngressCreateIngressJSONRequestBody) (string, error) | ||
UpdateIngressPaths(ctx context.Context, ingressID string, body IngressUpdateIngressPathsJSONRequestBody) error | ||
DeleteIngress(ctx context.Context, ingressID string) error | ||
} | ||
|
||
type domainClient struct { | ||
client ClientWithResponsesInterface | ||
} | ||
|
||
func (c *domainClient) GetIngress(ctx context.Context, ingressID string) (*DeMittwaldV1IngressIngress, error) { | ||
resp, err := c.client.IngressGetIngressWithResponse(ctx, uuid.MustParse(ingressID)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if resp.JSON200 == nil { | ||
return nil, errUnexpectedStatus(resp.StatusCode(), resp.Body) | ||
} | ||
|
||
return resp.JSON200, nil | ||
} | ||
|
||
func (c *domainClient) CreateIngress(ctx context.Context, projectID string, body IngressCreateIngressJSONRequestBody) (string, error) { | ||
resp, err := c.client.IngressCreateIngressWithResponse(ctx, body) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
body.ProjectId = uuid.MustParse(projectID) | ||
|
||
if resp.JSON201 == nil { | ||
return "", errUnexpectedStatus(resp.StatusCode(), resp.Body) | ||
} | ||
|
||
return resp.JSON201.Id.String(), nil | ||
} | ||
|
||
func (c *domainClient) UpdateIngressPaths(ctx context.Context, ingressID string, body IngressUpdateIngressPathsJSONRequestBody) error { | ||
resp, err := c.client.IngressUpdateIngressPathsWithResponse(ctx, uuid.MustParse(ingressID), body) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if resp.StatusCode() != 204 { | ||
return errUnexpectedStatus(resp.StatusCode(), resp.Body) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *domainClient) DeleteIngress(ctx context.Context, ingressID string) error { | ||
resp, err := c.client.IngressDeleteIngressWithResponse(ctx, uuid.MustParse(ingressID)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if resp.StatusCode() != 204 { | ||
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
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,34 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "mittwald_virtualhost Resource - terraform-provider-mittwald" | ||
subcategory: "" | ||
description: |- | ||
This resource models a virtualhost. | ||
--- | ||
|
||
# mittwald_virtualhost (Resource) | ||
|
||
This resource models a virtualhost. | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `hostname` (String) The desired hostname for the virtualhost. | ||
- `paths` (Attributes Map) The desired paths for the virtualhost. (see [below for nested schema](#nestedatt--paths)) | ||
- `project_id` (String) The ID of the project the virtualhost belongs to | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The generated virtualhost ID | ||
|
||
<a id="nestedatt--paths"></a> | ||
### Nested Schema for `paths` | ||
|
||
Optional: | ||
|
||
- `app` (String) The ID of an app installation that this path should point to. | ||
- `redirect` (String) The URL to redirect to. |
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,55 @@ | ||
package common | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" | ||
) | ||
|
||
type AttributeBuilder struct { | ||
resourceName string | ||
} | ||
|
||
func AttributeBuilderFor(name string) *AttributeBuilder { | ||
return &AttributeBuilder{ | ||
resourceName: name, | ||
} | ||
} | ||
|
||
func (b *AttributeBuilder) Id() schema.Attribute { | ||
return schema.StringAttribute{ | ||
Computed: true, | ||
MarkdownDescription: fmt.Sprintf("The generated %s ID", b.resourceName), | ||
PlanModifiers: []planmodifier.String{ | ||
stringplanmodifier.UseStateForUnknown(), | ||
}, | ||
} | ||
} | ||
|
||
func (b *AttributeBuilder) ProjectId() schema.Attribute { | ||
return schema.StringAttribute{ | ||
MarkdownDescription: fmt.Sprintf("The ID of the project the %s belongs to", b.resourceName), | ||
Required: true, | ||
PlanModifiers: []planmodifier.String{ | ||
stringplanmodifier.RequiresReplace(), | ||
}, | ||
} | ||
} | ||
|
||
func (b *AttributeBuilder) AppId() schema.Attribute { | ||
return schema.StringAttribute{ | ||
MarkdownDescription: fmt.Sprintf("The ID of the app the %s belongs to", b.resourceName), | ||
Required: true, | ||
PlanModifiers: []planmodifier.String{ | ||
stringplanmodifier.RequiresReplace(), | ||
}, | ||
} | ||
} | ||
|
||
func (b *AttributeBuilder) Description() schema.Attribute { | ||
return schema.StringAttribute{ | ||
Required: true, | ||
MarkdownDescription: fmt.Sprintf("Description for your %s", b.resourceName), | ||
} | ||
} |
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
Oops, something went wrong.