Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storage): extend application schema for storage flag #492

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
51 changes: 50 additions & 1 deletion internal/provider/resource_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/juju/errors"

"github.com/juju/juju/core/constraints"

"github.com/juju/terraform-provider-juju/internal/juju"
Expand Down Expand Up @@ -164,6 +164,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.",
anvial marked this conversation as resolved.
Show resolved Hide resolved
Optional: true,
anvial marked this conversation as resolved.
Show resolved Hide resolved
Computed: true,
Default: int64default.StaticInt64(int64(1)),
PlanModifiers: []planmodifier.Int64{
int64planmodifier.RequiresReplaceIfConfigured(),
int64planmodifier.UseStateForUnknown(),
},
},
},
anvial marked this conversation as resolved.
Show resolved Hide resolved
},
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
Loading