-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
provider/datadog: Add datadog_downtime resource #10994
provider/datadog: Add datadog_downtime resource #10994
Conversation
"strings" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/zorkian/go-datadog-api" |
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.
Needs to be updated to "gopkg.in/zorkian/go-datadog-api.v2"
Optional: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
ValidateFunc: validateWeekDay, |
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.
Optional, but validateWeekDay be defined here, see this example: https://github.com/hashicorp/terraform/blob/master/builtin/providers/aws/resource_aws_kinesis_firehose_delivery_stream.go#L76:
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if value != "s3" && value != "redshift" && value != "elasticsearch" {
errors = append(errors, fmt.Errorf(
"%q must be one of 's3', 'redshift', 'elasticsearch'", k))
}
return
},
func validateWeekDay(v interface{}, k string) (ws []string, errors []error) { | ||
value := v.(string) | ||
|
||
if value != "Mon" && value != "Tue" && value != "Wed" && value != "Thu" && value != "Fri" && value != "Sat" && value != "Sun" { |
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.
I would use switch here, see https://gobyexample.com/switch
Something like (untested):
switch value {
case "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun":
errors = append(errors, fmt.Errorf(
"%q contains an invalid week day parameter %q. Valid parameters are Mon, Tue, Wed, Thu, Fri, Sat or Sun",
k))
}
return
This is thrown while planning during your test, it is triggered by using a list nested in a map I see it in
Which contains: recurrence {
period = 1
type = "weeks"
week_days = ["Sat", "Sun"]
} The error is not in your code, but the schema, Terraform does not catch this for you, and the error message is not very informative. AFAICS you'll have to work around this, or fix this in Terraform core. Don't have a good solution for you at the moment, but will let you know if I think of something. You'll see you'll be able to use |
@ojongerius thanks for the feedback! I spent some time with this today and got it working as expected (hopefully the right way 😄). PR updates:
Here's what I'm seeing now:
|
Nice work! Looks like the last hurdle is getting
|
const testAccCheckDatadogDowntimeConfigImported = ` | ||
resource "datadog_downtime" "foo" { | ||
scope = ["host:X", "host:Y"] | ||
start = 1483308000 |
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.
These need to be in the future, get fancy and generate them dynamically or plan further ahead ;)
I've adjusted the import test timestamps to be similar to the other tests in the future and its working locally for me:
Please let me know if there are other adjustments you'd like! |
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.
Awesome, thanks!
|
LGTM Thanks for all the work here @bflad and for the review @ojongerius |
* provider/datadog: Initial datadog_downtime resource * provider/datadog: Update datadog_downtime resource to v2 library, fix recurrence handling * provider/datadog: Fix datadog_downtime import test
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Hello! This should hopefully get the ball rolling for adding a
datadog_downtime
resource to the datadog provider, which is used to manage alerting downtimes. References:This appears to be pretty close for an initial implementation, however I am having some issues working with the Terraform schema and Go (first time writing in Go, so apologies in advance!). I used the existing
datadog_monitor
as a reference for writing this resource.Known Working:
Active
attribute (Datadog doesn't actually delete the downtime -- it does disappear from the UI in this state though)Known Issues:
The schema forrecurrence.week_days
should be a validated List of week days -- currently throws* '[week_days]' expected type 'string', got unconvertible type '[]interface {}'
when defined in configurationTherecurrence
state is occasionally unstable for certain attributes (mostlyperiod
), but I'm very unsure why (Go pointers?). Here's an example that testing will not break every run, but almost always in same the way:Any help or feedback is appreciated, thanks!