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:
parent
1daac2f5c7
commit
cbfb29cd8f
|
@ -270,7 +270,7 @@ func resourceRuleSet() *schema.Resource {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
ValidateFunc: validateHTTPURL(ruleSetLinkAttr, urlIsAbs),
|
ValidateFunc: validateHTTPURL(ruleSetLinkAttr, urlIsAbs|urlOptional),
|
||||||
},
|
},
|
||||||
ruleSetMetricTypeAttr: &schema.Schema{
|
ruleSetMetricTypeAttr: &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
@ -369,9 +369,9 @@ func ruleSetRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
case apiRuleSetMinValue:
|
case apiRuleSetMinValue:
|
||||||
valueAttrs[string(ruleSetMinValueAttr)] = rule.Value
|
valueAttrs[string(ruleSetMinValueAttr)] = rule.Value
|
||||||
case apiRuleSetNotContains:
|
case apiRuleSetNotContains:
|
||||||
valueAttrs[string(ruleSetNotMatchAttr)] = rule.Value
|
|
||||||
case apiRuleSetNotMatch:
|
|
||||||
valueAttrs[string(ruleSetNotContainAttr)] = rule.Value
|
valueAttrs[string(ruleSetNotContainAttr)] = rule.Value
|
||||||
|
case apiRuleSetNotMatch:
|
||||||
|
valueAttrs[string(ruleSetNotMatchAttr)] = rule.Value
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("PROVIDER BUG: Unsupported criteria %q", rule.Criteria)
|
return fmt.Errorf("PROVIDER BUG: Unsupported criteria %q", rule.Criteria)
|
||||||
}
|
}
|
||||||
|
|
|
@ -313,14 +313,20 @@ type urlParseFlags int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
urlIsAbs urlParseFlags = 1 << iota
|
urlIsAbs urlParseFlags = 1 << iota
|
||||||
urlWithoutSchema
|
urlOptional
|
||||||
urlWithoutPort
|
urlWithoutPort
|
||||||
|
urlWithoutSchema
|
||||||
)
|
)
|
||||||
|
|
||||||
const urlBasicCheck urlParseFlags = 0
|
const urlBasicCheck urlParseFlags = 0
|
||||||
|
|
||||||
func validateHTTPURL(attrName schemaAttr, checkFlags urlParseFlags) func(v interface{}, key string) (warnings []string, errors []error) {
|
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) {
|
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))
|
u, err := url.Parse(v.(string))
|
||||||
switch {
|
switch {
|
||||||
case err != nil:
|
case err != nil:
|
||||||
|
|
Loading…
Reference in New Issue