Skip to content
Open
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 stackit/internal/services/telemetrylink/link/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/http"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -172,10 +173,24 @@ func (r *telemetryLinkResource) Schema(_ context.Context, _ resource.SchemaReque
"display_name": schema.StringAttribute{
Description: schemaDescriptions["display_name"],
Required: true,
Validators: []validator.String{
stringvalidator.LengthBetween(1, 32),
stringvalidator.RegexMatches(
regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9 \-]*$`),
"The display name must start with an alphanumeric character and can only contain letters, numbers, spaces, and hyphens.",
),
},
},
"description": schema.StringAttribute{
Description: schemaDescriptions["description"],
Optional: true,
Validators: []validator.String{
stringvalidator.LengthAtMost(1024),
stringvalidator.RegexMatches(
regexp.MustCompile(`^([a-zA-Z0-9][a-zA-Z0-9 \-]*)?$`),
"The description must start with an alphanumeric character and can only contain letters, numbers, spaces, and hyphens.",
),
},
},
"region": schema.StringAttribute{
Description: schemaDescriptions["region"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/http"
"regexp"
"strings"
"time"

Expand All @@ -14,6 +15,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int32planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
Expand Down Expand Up @@ -172,6 +174,13 @@ func (r *telemetryRouterAccessTokenResource) Schema(_ context.Context, _ resourc
"display_name": schema.StringAttribute{
Description: schemaDescriptions["display_name"],
Required: true,
Validators: []validator.String{
stringvalidator.LengthBetween(1, 32),
stringvalidator.RegexMatches(
regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9 \-]*$`),
"must start with an alphanumeric character and contain only alphanumeric characters, spaces, and hyphens",
),
},
},
"region": schema.StringAttribute{
Description: schemaDescriptions["region"],
Expand All @@ -185,6 +194,9 @@ func (r *telemetryRouterAccessTokenResource) Schema(_ context.Context, _ resourc
"description": schema.StringAttribute{
Description: schemaDescriptions["description"],
Optional: true,
Validators: []validator.String{
stringvalidator.LengthAtMost(1024),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to double check: This matches the API Docs so no mismatch here.

For the link description there is a regex but not for the access token description? Is that intended?

},
},
"ttl": schema.Int32Attribute{
Description: schemaDescriptions["ttl"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/http"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -293,6 +294,13 @@ func (r *telemetryRouterDestinationResource) Schema(_ context.Context, _ resourc
"display_name": schema.StringAttribute{
Description: schemaDescriptions["display_name"],
Required: true,
Validators: []validator.String{
stringvalidator.LengthBetween(1, 32),
stringvalidator.RegexMatches(
regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9 \-]*$`),
"must start with an alphanumeric character and contain only alphanumeric characters, spaces, and hyphens",
),
},
},
"config": schema.SingleNestedAttribute{
Description: schemaDescriptions["config"],
Expand Down Expand Up @@ -420,6 +428,9 @@ func (r *telemetryRouterDestinationResource) Schema(_ context.Context, _ resourc
"description": schema.StringAttribute{
Description: schemaDescriptions["description"],
Optional: true,
Validators: []validator.String{
stringvalidator.LengthAtMost(1024),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here

},
},
"creation_time": schema.StringAttribute{
Description: schemaDescriptions["creation_time"],
Expand Down
11 changes: 11 additions & 0 deletions stackit/internal/services/telemetryrouter/instance/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/http"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -195,6 +196,13 @@ func (r *telemetryRouterInstanceResource) Schema(_ context.Context, _ resource.S
"display_name": schema.StringAttribute{
Description: schemaDescriptions["display_name"],
Required: true,
Validators: []validator.String{
stringvalidator.LengthBetween(1, 32),
stringvalidator.RegexMatches(
regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9 \-]*$`),
"must start with an alphanumeric character and contain only alphanumeric characters, spaces, and hyphens",
),
},
},
"region": schema.StringAttribute{
Description: schemaDescriptions["region"],
Expand All @@ -208,6 +216,9 @@ func (r *telemetryRouterInstanceResource) Schema(_ context.Context, _ resource.S
"description": schema.StringAttribute{
Description: schemaDescriptions["description"],
Optional: true,
Validators: []validator.String{
stringvalidator.LengthAtMost(1024),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

},
},
"filter": schema.SingleNestedAttribute{
Description: schemaDescriptions["filter"],
Expand Down