Skip to content
This repository has been archived by the owner on Aug 6, 2021. It is now read-only.

Commit

Permalink
Fix icmp rule in security group when reading
Browse files Browse the repository at this point in the history
When you have an icmp rule, during reading by the cf cli type and code for icmp are in go type Float64 but we expect an integer.
This is causing crash to terraform, it has been fixed by converting those value to the correct expected type.
  • Loading branch information
ArthurHlt committed Jan 5, 2017
1 parent 41c6a6f commit 74be0b1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions resources/security_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ func (c CfSecurityGroupResource) unSanitizeRule(rule map[string]interface{}) map
unSanitizedRule := make(map[string]interface{})
if _, ok := rule["code"]; !ok {
unSanitizedRule["code"] = -1
} else {
rule["code"] = c.convertRuleParamFloatToInt(rule["code"])
}
if _, ok := rule["log"]; !ok {
unSanitizedRule["log"] = false
}
if _, ok := rule["type"]; !ok {
unSanitizedRule["type"] = -1
} else {
rule["type"] = c.convertRuleParamFloatToInt(rule["type"])
}
if _, ok := rule["ports"]; !ok {
unSanitizedRule["ports"] = ""
Expand All @@ -63,6 +67,16 @@ func (c CfSecurityGroupResource) unSanitizeRule(rule map[string]interface{}) map
}
return unSanitizedRule
}
func (c CfSecurityGroupResource) convertRuleParamFloatToInt(param interface{}) int {
kindParam := reflect.TypeOf(param).Kind()
if kindParam == reflect.Float32 {
return int(param.(float32))
}
if kindParam == reflect.Float64 {
return int(param.(float64))
}
return param.(int)
}
func (c CfSecurityGroupResource) sanitizeRule(rule map[string]interface{}) map[string]interface{} {
sanitizedRule := make(map[string]interface{})

Expand Down

0 comments on commit 74be0b1

Please sign in to comment.