-
Notifications
You must be signed in to change notification settings - Fork 385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[datadog_monitor] Allow default_tags values to contain colons. #2703
Conversation
af4f4e5
to
e58ffb0
Compare
datadog/provider.go
Outdated
@@ -470,12 +470,14 @@ func tagDiff(ctx context.Context, d *schema.ResourceDiff, meta interface{}) erro | |||
kv := strings.Split(tag.(string), ":") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could probably use strings.Cut
(or even strings.SplitN
) and avoid having to strings.Join
afterwards. This would probably allow to simplify the whole check logic!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like so:
tagStr := tag.(string)
if tagStr == "" {
return fmt.Errorf("invalid tag: '%s'", tag)
}
key, value, found := strings.Cut(tagStr, ":")
if !found {
value = ""
}
tags[key] = value
Or even omit the check if !found
given that the default value of a string is ""
anyway!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point - I always forget about this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done - I've even removed the special case for empty tags because it does not break the code.
Only separate the key before the first colon, all subsequent colons are considered to be part of the value as stated in datadog docs.
da8db65
to
1a580f5
Compare
Only separate the key before the first colon, all subsequent colons are
considered to be part of the value as stated in datadog docs.