Skip to content
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

[dashboards] Add new Dashboard resource #249

Merged
merged 14 commits into from
Jul 24, 2019
37 changes: 31 additions & 6 deletions datadog/resource_datadog_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ func resourceDatadogDashboard() *schema.Resource {
},
},
"layout_type": {
Type: schema.TypeString,
Required: true,
Description: "The layout type of the dashboard, either 'free' or 'ordered'.",
Type: schema.TypeString,
Required: true,
Description: "The layout type of the dashboard, either 'free' or 'ordered'.",
ValidateFunc: validateDashboardLayoutType,
},
"description": {
Type: schema.TypeString,
Expand Down Expand Up @@ -815,9 +816,10 @@ func getGroupDefinitionSchema() map[string]*schema.Schema {
},
},
"layout_type": {
Type: schema.TypeString,
Required: true,
Description: "The layout type of the group, only 'ordered' for now.",
Type: schema.TypeString,
Required: true,
Description: "The layout type of the group, only 'ordered' for now.",
ValidateFunc: validateGroupWidgetLayoutType,
},
"title": {
Type: schema.TypeString,
Expand Down Expand Up @@ -3850,3 +3852,26 @@ func buildTerraformWidgetAxis(datadogWidgetAxis datadog.WidgetAxis) map[string]i
}
return terraformWidgetAxis
}

func validateDashboardLayoutType(val interface{}, key string) (warns []string, errs []error) {
value := val.(string)
switch value {
case "free", "ordered":
break
default:
errs = append(errs, fmt.Errorf(
"%q contains an invalid value %q. Valid values are `free` or `ordered`", key, value))
}
return
}
func validateGroupWidgetLayoutType(val interface{}, key string) (warns []string, errs []error) {
value := val.(string)
switch value {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a switch despite this being one value only because we plan to support more layout types in the future.

case "ordered":
break
default:
errs = append(errs, fmt.Errorf(
"%q contains an invalid value %q. Only `ordered` is a valid value", key, value))
}
return
}