Skip to content

Commit

Permalink
Add validation functions to autoscaling lifecycle hook arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
jphuynh committed Aug 22, 2020
1 parent 116a671 commit 5e80237
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions aws/resource_aws_autoscaling_lifecycle_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"fmt"
"log"
"regexp"
"strings"
"time"

Expand All @@ -11,6 +12,7 @@ import (
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

func resourceAwsAutoscalingLifecycleHook() *schema.Resource {
Expand All @@ -29,35 +31,45 @@ func resourceAwsAutoscalingLifecycleHook() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.All(
validation.StringLenBetween(1, 255),
validation.StringMatch(regexp.MustCompile(`[A-Za-z0-9\-_\/]+`),
`must satisfy regular expression pattern: [A-Za-z0-9\-_\/]+`),
),
},
"autoscaling_group_name": {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringLenBetween(1, 1600),
},
"default_result": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{"CONTINUE", "ABANDON"}, false),
},
"heartbeat_timeout": {
Type: schema.TypeInt,
Optional: true,
},
"lifecycle_transition": {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"autoscaling:EC2_INSTANCE_LAUNCHING", "autoscaling:EC2_INSTANCE_TERMINATING"}, false),
},
"notification_metadata": {
Type: schema.TypeString,
Optional: true,
},
"notification_target_arn": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateArn,
},
"role_arn": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateArn,
},
},
}
Expand Down

0 comments on commit 5e80237

Please sign in to comment.