Skip to content

Commit

Permalink
feat(application): define schema for storage flag in application reso…
Browse files Browse the repository at this point in the history
…urce

This commit extends the application schema to support the storage flag in the Terraform provider for Juju.
The schema now includes varios attributes for configuring the storage constraints of a Juju application.
  • Loading branch information
anvial committed Jun 14, 2024
1 parent d4909b8 commit 7ba2ac6
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/resources/application.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ resource "juju_application" "placement_example" {
latest revision.
* If the charm revision or channel are not updated, then no changes will take
place (juju does not have an "un-attach" command for resources).
- `storage` (Attributes Set) Configure storage constraints for the juju application. (see [below for nested schema](#nestedatt--storage))
- `trust` (Boolean) Set the trust for the application.
- `units` (Number) The number of application units to deploy for the charm.

Expand Down Expand Up @@ -122,6 +123,20 @@ Optional:
- `endpoints` (String) Expose only the ports that charms have opened for this comma-delimited list of endpoints
- `spaces` (String) A comma-delimited list of spaces that should be able to access the application ports once exposed.


<a id="nestedatt--storage"></a>
### Nested Schema for `storage`

Required:

- `label` (String) The specific storage option defined in the charm.

Optional:

- `count` (Number) The number of volumes.
- `pool` (String) Name of the storage pool to use. E.g. ebs on aws.
- `size` (String) The size of each volume. E.g. 100G.

## Import

Import is supported using the following syntax:
Expand Down
50 changes: 50 additions & 0 deletions internal/provider/resource_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package provider
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
"strings"

"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
Expand Down Expand Up @@ -164,6 +165,55 @@ func (r *applicationResource) Schema(_ context.Context, _ resource.SchemaRequest
stringplanmodifier.UseStateForUnknown(),
},
},
"storage": schema.SetNestedAttribute{
Description: "Configure storage constraints for the juju application.",
Optional: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"label": schema.StringAttribute{
Description: "The specific storage option defined in the charm.",
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplaceIfConfigured(),
stringplanmodifier.UseStateForUnknown(),
},
},
"size": schema.StringAttribute{
Description: "The size of each volume. E.g. 100G.",
Optional: true,
Computed: true,
Default: stringdefault.StaticString("1G"),
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplaceIfConfigured(),
stringplanmodifier.UseStateForUnknown(),
},
},
"pool": schema.StringAttribute{
Description: "Name of the storage pool to use. E.g. ebs on aws.",
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplaceIfConfigured(),
stringplanmodifier.UseStateForUnknown(),
},
},
"count": schema.Int64Attribute{
Description: "The number of volumes.",
Optional: true,
Computed: true,
Default: int64default.StaticInt64(int64(1)),
PlanModifiers: []planmodifier.Int64{
int64planmodifier.RequiresReplaceIfConfigured(),
int64planmodifier.UseStateForUnknown(),
},
},
},
},
Validators: []validator.Set{
setNestedIsAttributeUniqueValidator{
PathExpressions: path.MatchRelative().AtAnySetValue().MergeExpressions(path.MatchRelative().AtName("label")),
},
},
},
"trust": schema.BoolAttribute{
Description: "Set the trust for the application.",
Optional: true,
Expand Down

0 comments on commit 7ba2ac6

Please sign in to comment.