Fix circonus)_rule_sets for optional links. (#12614)

* Add a `validateHTTPURL` flag to allow URLs in `circonus_rule_set`s to be optional.

* Fix reading `circonus_rule_set` `criteria`.
This commit is contained in:
Sean Chittenden 2017-03-11 18:59:18 -08:00 committed by GitHub
parent 1daac2f5c7
commit cbfb29cd8f
2 changed files with 10 additions and 4 deletions

View File

@ -270,7 +270,7 @@ func resourceRuleSet() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validateHTTPURL(ruleSetLinkAttr, urlIsAbs),
ValidateFunc: validateHTTPURL(ruleSetLinkAttr, urlIsAbs|urlOptional),
},
ruleSetMetricTypeAttr: &schema.Schema{
Type: schema.TypeString,
@ -369,9 +369,9 @@ func ruleSetRead(d *schema.ResourceData, meta interface{}) error {
case apiRuleSetMinValue:
valueAttrs[string(ruleSetMinValueAttr)] = rule.Value
case apiRuleSetNotContains:
valueAttrs[string(ruleSetNotMatchAttr)] = rule.Value
case apiRuleSetNotMatch:
valueAttrs[string(ruleSetNotContainAttr)] = rule.Value
case apiRuleSetNotMatch:
valueAttrs[string(ruleSetNotMatchAttr)] = rule.Value
default:
return fmt.Errorf("PROVIDER BUG: Unsupported criteria %q", rule.Criteria)
}

View File

@ -313,14 +313,20 @@ type urlParseFlags int
const (
urlIsAbs urlParseFlags = 1 << iota
urlWithoutSchema
urlOptional
urlWithoutPort
urlWithoutSchema
)
const urlBasicCheck urlParseFlags = 0
func validateHTTPURL(attrName schemaAttr, checkFlags urlParseFlags) func(v interface{}, key string) (warnings []string, errors []error) {
return func(v interface{}, key string) (warnings []string, errors []error) {
s := v.(string)
if checkFlags&urlOptional != 0 && s == "" {
return warnings, errors
}
u, err := url.Parse(v.(string))
switch {
case err != nil: