From cbfb29cd8f52065ef3ef0361c3a2a254d7f185bc Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Sat, 11 Mar 2017 18:59:18 -0800 Subject: [PATCH] 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`. --- builtin/providers/circonus/resource_circonus_rule_set.go | 6 +++--- builtin/providers/circonus/validators.go | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/builtin/providers/circonus/resource_circonus_rule_set.go b/builtin/providers/circonus/resource_circonus_rule_set.go index 767dd0337..c98ff2da9 100644 --- a/builtin/providers/circonus/resource_circonus_rule_set.go +++ b/builtin/providers/circonus/resource_circonus_rule_set.go @@ -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) } diff --git a/builtin/providers/circonus/validators.go b/builtin/providers/circonus/validators.go index 7fd5e85a3..dca2de36c 100644 --- a/builtin/providers/circonus/validators.go +++ b/builtin/providers/circonus/validators.go @@ -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: