Skip to content

Commit

Permalink
Merge pull request #19172 from DrFaust92/r/glue_connection_validations
Browse files Browse the repository at this point in the history
r/glue_connection - validations
  • Loading branch information
ewbankkit authored May 6, 2021
2 parents 4c842ed + 46616fe commit cdcfab0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .changelog/19172.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_glue_connection: Add plan time validation for `connection_properties`, `description`, `match_criteria`, `name`, and `physical_connection_requirements.security_group_id_list`
```
23 changes: 15 additions & 8 deletions aws/resource_aws_glue_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ func resourceAwsGlueConnection() *schema.Resource {
Computed: true,
},
"connection_properties": {
Type: schema.TypeMap,
Required: true,
Sensitive: true,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeMap,
Required: true,
Sensitive: true,
ValidateFunc: MapKeyInSlice(glue.ConnectionPropertyKey_Values(), false),
Elem: &schema.Schema{Type: schema.TypeString},
},
"connection_type": {
Type: schema.TypeString,
Expand All @@ -46,19 +47,24 @@ func resourceAwsGlueConnection() *schema.Resource {
ValidateFunc: validation.StringInSlice(glue.ConnectionType_Values(), false),
},
"description": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringLenBetween(0, 2048),
},
"match_criteria": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
MaxItems: 10,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringLenBetween(1, 255),
},
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.NoZeroValues,
ValidateFunc: validation.StringLenBetween(1, 255),
},
"physical_connection_requirements": {
Type: schema.TypeList,
Expand All @@ -73,6 +79,7 @@ func resourceAwsGlueConnection() *schema.Resource {
"security_group_id_list": {
Type: schema.TypeSet,
Optional: true,
MaxItems: 50,
Elem: &schema.Schema{Type: schema.TypeString},
},
"subnet_id": {
Expand Down
23 changes: 23 additions & 0 deletions aws/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -2463,6 +2463,29 @@ func MapKeysDoNotMatch(r *regexp.Regexp, message string) schema.SchemaValidateFu
}
}

func MapKeyInSlice(valid []string, ignoreCase bool) schema.SchemaValidateFunc {
return func(i interface{}, k string) (warnings []string, errors []error) {
v, ok := i.(map[string]interface{})
if !ok {
errors = append(errors, fmt.Errorf("expected type of %[1]q to be Map, got %[1]T", k))
return warnings, errors
}

for key := range v {
for _, str := range valid {
if key == str || (ignoreCase && strings.EqualFold(key, str)) {
return warnings, errors
}
}

errors = append(errors, fmt.Errorf("expected %s to be one of %v, got %s", k, valid, key))
return warnings, errors
}

return warnings, errors
}
}

var validateTypeStringIsDateOrPositiveInt = validation.Any(
validation.IsRFC3339Time,
validation.StringMatch(regexp.MustCompile(`^\d+$`), "must be a positive integer value"),
Expand Down

0 comments on commit cdcfab0

Please sign in to comment.