Skip to content

Commit

Permalink
Merge pull request #39798 from jandersen-plaid/jandersen-plaid-route5…
Browse files Browse the repository at this point in the history
…3-profiles-profile

r/route53profiles_association: Validate name field against regex
  • Loading branch information
jar-b authored Oct 23, 2024
2 parents 9002b22 + 60e4572 commit bc57122
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changelog/39798.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_route53profiles_association: Add regex and string length validation for `name` argument
```
16 changes: 14 additions & 2 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 All @@ -38,7 +41,7 @@ func newResourceAssociation(_ context.Context) (resource.ResourceWithConfigure,
r := &resourceAssociation{}

r.SetDefaultCreateTimeout(30 * time.Minute)
r.SetDefaultUpdateTimeout(30 * time.Minute)
r.SetDefaultUpdateTimeout(5 * time.Minute) // tags only
r.SetDefaultDeleteTimeout(30 * time.Minute)

return r, nil
Expand All @@ -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,10 @@ 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, ""),
stringvalidator.LengthBetween(0, 64),
},
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Expand Down Expand Up @@ -107,7 +119,7 @@ func (r *resourceAssociation) Schema(ctx context.Context, req resource.SchemaReq
Blocks: map[string]schema.Block{
names.AttrTimeouts: timeouts.Block(ctx, timeouts.Opts{
Create: true,
Read: true,
Update: true,
Delete: true,
}),
},
Expand Down
8 changes: 3 additions & 5 deletions website/docs/r/route53profiles_association.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,24 @@ 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.

* `resource_id` - (Required) Resource ID of the VPC the profile to be associated with.

## Attribute Reference

This resource exports the following attributes in addition to the arguments above:

* `id` - ID of the Profile Association.
* `name` - Name of the Profile Association.
* `status` - Status of the Profile Association. Valid values [AWS docs](https://docs.aws.amazon.com/Route53/latest/APIReference/API_route53profiles_Profile.html)
* `status` - Status of the Profile Association. See the [AWS docs](https://docs.aws.amazon.com/Route53/latest/APIReference/API_route53profiles_Profile.html) for valid values.
* `status_message` - Status message of the Profile Association.

## Timeouts

[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts):

* `create` - (Default `30m`)
* `update` - (Default `5m`)
* `delete` - (Default `30m`)

## Import
Expand Down

0 comments on commit bc57122

Please sign in to comment.