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

r/route53profiles_association: Validate name field against regex #39798

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
11 changes: 11 additions & 0 deletions internal/service/route53profiles/association.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ import (
"fmt"
"time"

"github.com/YakDriver/regexache"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/route53profiles"
awstypes "github.com/aws/aws-sdk-go-v2/service/route53profiles/types"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"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"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-provider-aws/internal/create"
Expand Down Expand Up @@ -48,6 +51,11 @@ const (
ResNameAssociation = "Association"
)

var (
// Converted from (?!^[0-9]+$)([a-zA-Z0-9\-_' ']+) because of the negative lookahead.
resourceAssociationNameRegex = regexache.MustCompile("(^[^0-9][a-zA-Z0-9\\-_' ']+$)")
)

type resourceAssociation struct {
framework.ResourceWithConfigure
framework.WithNoOpUpdate[associationResourceModel]
Expand All @@ -66,6 +74,9 @@ func (r *resourceAssociation) Schema(ctx context.Context, req resource.SchemaReq
names.AttrID: framework.IDAttribute(),
names.AttrName: schema.StringAttribute{
Required: true,
Validators: []validator.String{
stringvalidator.RegexMatches(resourceAssociationNameRegex, ""),
},
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/route53profiles_association.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ resource "aws_route53profiles_association" "example" {

The following arguments are required:

* `name` - (Required) Name of the Profile Association.
* `name` - (Required) Name of the Profile Association. Must match a regex of `(?!^[0-9]+$)([a-zA-Z0-9\\-_' ']+)`

* `profile_id` - (Required) ID of the profile associated with the VPC.

Expand Down