diff --git a/internal/service/route53profiles/association.go b/internal/service/route53profiles/association.go index bb460f3268d6..7b5d8750e318 100644 --- a/internal/service/route53profiles/association.go +++ b/internal/service/route53profiles/association.go @@ -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" @@ -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] @@ -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(), }, diff --git a/website/docs/r/route53profiles_association.html.markdown b/website/docs/r/route53profiles_association.html.markdown index 44b83e661751..554952b762b9 100644 --- a/website/docs/r/route53profiles_association.html.markdown +++ b/website/docs/r/route53profiles_association.html.markdown @@ -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.