Skip to content

Commit

Permalink
fix: add validation checks for aws_glue_catalog_table resource proper…
Browse files Browse the repository at this point in the history
…ties
  • Loading branch information
drexler committed Mar 25, 2020
1 parent 81c55de commit 583639f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
20 changes: 14 additions & 6 deletions aws/resource_aws_glue_catalog_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,19 @@ func resourceAwsGlueCatalogTable() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateGlueCatalogSerdeInfoProperty,
},
"parameters": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"serialization_library": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateGlueCatalogSerdeInfoProperty,
},
},
},
Expand Down Expand Up @@ -630,9 +632,15 @@ func flattenGlueSerDeInfo(s *glue.SerDeInfo) []map[string]interface{} {
serDeInfos := make([]map[string]interface{}, 1)
serDeInfo := make(map[string]interface{})

serDeInfo["name"] = aws.StringValue(s.Name)
if v := aws.StringValue(s.Name); v != "" {
serDeInfo["name"] = v
}

serDeInfo["parameters"] = aws.StringValueMap(s.Parameters)
serDeInfo["serialization_library"] = aws.StringValue(s.SerializationLibrary)

if v := aws.StringValue(s.SerializationLibrary); v != "" {
serDeInfo["serialization_library"] = v
}

serDeInfos[0] = serDeInfo
return serDeInfos
Expand Down
8 changes: 8 additions & 0 deletions aws/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -2369,3 +2369,11 @@ func validateRoute53ResolverName(v interface{}, k string) (ws []string, errors [

return
}

func validateGlueCatalogSerdeInfoProperty(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if len(value) < 1 {
errors = append(errors, fmt.Errorf("%q cannot be less than 1 character", k))
}
return
}
26 changes: 26 additions & 0 deletions aws/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3018,3 +3018,29 @@ func TestValidateRoute53ResolverName(t *testing.T) {
}
}
}

func TestValidateGlueCatalogSerdeInfoProperty(t *testing.T) {
validValues := []string{
"Name",
"Na",
"n",
}

for _, s := range validValues {
_, errors := validateGlueCatalogSerdeInfoProperty(s, "aws_glue_catalog_table")
if len(errors) > 0 {
t.Fatalf("%q should be a valid AWS Glue Catalog table storage descriptor: %v", s, errors)
}
}

invalidValues := []string{
"",
}

for _, s := range invalidValues {
_, errors := validateGlueCatalogSerdeInfoProperty(s, "aws_glue_catalog_table")
if len(errors) == 0 {
t.Fatalf("%q should not be a valid AWS Glue Catalog table storage descriptor: %v", s, errors)
}
}
}

0 comments on commit 583639f

Please sign in to comment.