Skip to content

Commit

Permalink
add validation for start/end maintanence
Browse files Browse the repository at this point in the history
print server error
  • Loading branch information
Dean Oren committed Jul 17, 2023
1 parent 8e48f85 commit bf0c71f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions stackit/internal/resources/kubernetes/cluster/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cluster

import (
"context"
"encoding/json"
"fmt"
"net/http"
"strings"
Expand Down Expand Up @@ -95,6 +96,12 @@ func (r Resource) createOrUpdateCluster(ctx context.Context, diags *diag.Diagnos
},
)
if agg := validate.Response(resp, err); agg != nil {
if resp != nil && resp.JSON400 != nil {
b, err := json.MarshalIndent(*resp.JSON400, "", " ")
if err == nil {
diags.AddError("server response", string(b))
}
}
diags.AddError("failed during SKE create/update", agg.Error())
return
}
Expand Down
12 changes: 10 additions & 2 deletions stackit/internal/resources/kubernetes/cluster/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package cluster
import (
"context"
"fmt"
"regexp"

"github.com/SchwarzIT/community-stackit-go-client/pkg/services/kubernetes/v1.0/cluster"
clientValidate "github.com/SchwarzIT/community-stackit-go-client/pkg/validate"
"github.com/SchwarzIT/terraform-provider-stackit/stackit/internal/common"
"github.com/SchwarzIT/terraform-provider-stackit/stackit/pkg/validate"
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
Expand Down Expand Up @@ -265,12 +267,18 @@ func (r *Resource) Schema(ctx context.Context, req resource.SchemaRequest, resp
Required: true,
},
"start": schema.StringAttribute{
Description: "RFC3339 Date time for maintenance window start. i.e. `2019-08-24T23:00:00Z`",
Description: "RFC3339 Date time for maintenance window start. i.e. `0000-01-01T23:00:00Z`",
Required: true,
Validators: []validator.String{
stringvalidator.RegexMatches(regexp.MustCompile(`^(0000-01-01T\d{2}:\d{2}:\d{2}Z)$`), "validate RFC3339 date time that starts with 0000-01-01"),
},
},
"end": schema.StringAttribute{
Description: "RFC3339 Date time for maintenance window end. i.e. `2019-08-24T23:30:00Z`",
Description: "RFC3339 Date time for maintenance window end. i.e. `0000-01-01T23:30:00Z`",
Required: true,
Validators: []validator.String{
stringvalidator.RegexMatches(regexp.MustCompile(`^(0000-01-01T\d{2}:\d{2}:\d{2}Z)$`), "validate RFC3339 date time that starts with 0000-01-01"),
},
},
},
},
Expand Down

0 comments on commit bf0c71f

Please sign in to comment.