Skip to content

Commit

Permalink
chore(all): Update ValidateFunct for all resources
Browse files Browse the repository at this point in the history
These new version should provide better diagnostics.
  • Loading branch information
tete17 committed Apr 24, 2024
1 parent c374288 commit a351503
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 86 deletions.
8 changes: 4 additions & 4 deletions cloudamqp/data_source_cloudamqp_alarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ func dataSourceAlarm() *schema.Resource {
Description: "Alarm identifier",
},
"type": {
Type: schema.TypeString,
Optional: true,
Description: "Type of the alarm",
ValidateFunc: validateAlarmType(),
Type: schema.TypeString,
Optional: true,
Description: "Type of the alarm",
ValidateDiagFunc: validateAlarmType(),
},
"enabled": {
Type: schema.TypeBool,
Expand Down
16 changes: 8 additions & 8 deletions cloudamqp/resource_cloudamqp_account_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ func resourceAccountAction() *schema.Resource {
Description: "Instance identifier",
},
"action": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The action to perform on the node",
ValidateFunc: validateAccountAction(),
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The action to perform on the node",
ValidateDiagFunc: validateAccountAction(),
},
},
}
Expand Down Expand Up @@ -62,9 +62,9 @@ func resourceAccountActionRemove(d *schema.ResourceData, meta interface{}) error
return nil
}

func validateAccountAction() schema.SchemaValidateFunc {
return validation.StringInSlice([]string{
func validateAccountAction() schema.SchemaValidateDiagFunc {
return validation.ToDiagFunc(validation.StringInSlice([]string{
"rotate-password",
"rotate-apikey",
}, true)
}, true))
}
42 changes: 21 additions & 21 deletions cloudamqp/resource_cloudamqp_alarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ func resourceAlarm() *schema.Resource {
Description: "Instance identifier",
},
"type": {
Type: schema.TypeString,
Required: true,
Description: "Type of the alarm, valid options are: cpu, memory, disk_usage, queue_length, connection_count, consumers_count, net_split",
ValidateFunc: validateAlarmType(),
Type: schema.TypeString,
Required: true,
Description: "Type of the alarm, valid options are: cpu, memory, disk_usage, queue_length, connection_count, consumers_count, net_split",
ValidateDiagFunc: validateAlarmType(),
},
"enabled": {
Type: schema.TypeBool,
Expand All @@ -51,10 +51,10 @@ func resourceAlarm() *schema.Resource {
Description: "What value to trigger the alarm for",
},
"value_calculation": {
Type: schema.TypeString,
Optional: true,
Description: "Disk value threshold calculation. Fixed or percentage of disk space remaining",
ValidateFunc: validateValueCalculation(),
Type: schema.TypeString,
Optional: true,
Description: "Disk value threshold calculation. Fixed or percentage of disk space remaining",
ValidateDiagFunc: validateValueCalculation(),
},
"time_threshold": {
Type: schema.TypeInt,
Expand All @@ -72,10 +72,10 @@ func resourceAlarm() *schema.Resource {
Description: "Regex for which queues to check",
},
"message_type": {
Type: schema.TypeString,
Optional: true,
Description: "Message types (total, unacked, ready) of the queue to trigger the alarm",
ValidateFunc: validateMessageType(),
Type: schema.TypeString,
Optional: true,
Description: "Message types (total, unacked, ready) of the queue to trigger the alarm",
ValidateDiagFunc: validateMessageType(),
},
"recipients": {
Type: schema.TypeList,
Expand Down Expand Up @@ -199,8 +199,8 @@ func resourceAlarmDelete(d *schema.ResourceData, meta interface{}) error {
return api.DeleteAlarm(d.Get("instance_id").(int), params)
}

func validateAlarmType() schema.SchemaValidateFunc {
return validation.StringInSlice([]string{
func validateAlarmType() schema.SchemaValidateDiagFunc {
return validation.ToDiagFunc(validation.StringInSlice([]string{
"cpu",
"memory",
"disk",
Expand All @@ -212,7 +212,7 @@ func validateAlarmType() schema.SchemaValidateFunc {
"ssh",
"notice",
"server_unreachable",
}, true)
}, true))
}

func validateAlarmSchemaAttribute(key string) bool {
Expand All @@ -232,19 +232,19 @@ func validateAlarmSchemaAttribute(key string) bool {
return false
}

func validateMessageType() schema.SchemaValidateFunc {
return validation.StringInSlice([]string{
func validateMessageType() schema.SchemaValidateDiagFunc {
return validation.ToDiagFunc(validation.StringInSlice([]string{
"total",
"unacked",
"ready",
}, true)
}, true))
}

func validateValueCalculation() schema.SchemaValidateFunc {
return validation.StringInSlice([]string{
func validateValueCalculation() schema.SchemaValidateDiagFunc {
return validation.ToDiagFunc(validation.StringInSlice([]string{
"fixed",
"percentage",
}, true)
}, true))
}

func alarmAttributeKeys() []string {
Expand Down
10 changes: 5 additions & 5 deletions cloudamqp/resource_cloudamqp_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ func resourceInstance() *schema.Resource {
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validateCopySettings(),
Type: schema.TypeString,
ValidateDiagFunc: validateCopySettings(),
},
Description: "Settings to be copied. [alarms, config, definitions, firewall, logs, metrics, plugins]",
},
Expand Down Expand Up @@ -354,14 +354,14 @@ func instanceCreateAttributeKeys() []string {
}
}

func validateCopySettings() schema.SchemaValidateFunc {
return validation.StringInSlice([]string{
func validateCopySettings() schema.SchemaValidateDiagFunc {
return validation.ToDiagFunc(validation.StringInSlice([]string{
"alarms",
"config",
"definitions",
"firewall",
"logs",
"metrics",
"plugins",
}, true)
}, true))
}
28 changes: 14 additions & 14 deletions cloudamqp/resource_cloudamqp_integration_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ func resourceIntegrationLog() *schema.Resource {
Description: "Instance identifier used to make proxy calls",
},
"name": {
Type: schema.TypeString,
Required: true,
Description: "The name of log integration",
ValidateFunc: validateIntegrationLogName(),
Type: schema.TypeString,
Required: true,
Description: "The name of log integration",
ValidateDiagFunc: validateIntegrationLogName(),
},
"url": {
Type: schema.TypeString,
Expand Down Expand Up @@ -99,10 +99,10 @@ func resourceIntegrationLog() *schema.Resource {
Description: "The client email. (Stackdriver)",
},
"host": {
Type: schema.TypeString,
Optional: true,
Description: "The host information. (Scalyr)",
ValidateFunc: validateIntegrationLogScalyrHost(),
Type: schema.TypeString,
Optional: true,
Description: "The host information. (Scalyr)",
ValidateDiagFunc: validateIntegrationLogScalyrHost(),
},
"sourcetype": {
Type: schema.TypeString,
Expand Down Expand Up @@ -288,8 +288,8 @@ func resourceIntegrationLogDelete(d *schema.ResourceData, meta interface{}) erro
return api.DeleteIntegration(d.Get("instance_id").(int), "logs", d.Id())
}

func validateIntegrationLogName() schema.SchemaValidateFunc {
return validation.StringInSlice([]string{
func validateIntegrationLogName() schema.SchemaValidateDiagFunc {
return validation.ToDiagFunc(validation.StringInSlice([]string{
"azure_monitor",
"cloudwatchlog",
"coralogix",
Expand All @@ -300,14 +300,14 @@ func validateIntegrationLogName() schema.SchemaValidateFunc {
"scalyr",
"splunk",
"stackdriver",
}, true)
}, true))
}

func validateIntegrationLogScalyrHost() schema.SchemaValidateFunc {
return validation.StringInSlice([]string{
func validateIntegrationLogScalyrHost() schema.SchemaValidateDiagFunc {
return validation.ToDiagFunc(validation.StringInSlice([]string{
"app.scalyr.com",
"app.eu.scalyr.com",
}, true)
}, true))
}

func validateIntegrationLogsSchemaAttribute(key string) bool {
Expand Down
14 changes: 7 additions & 7 deletions cloudamqp/resource_cloudamqp_integration_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ func resourceIntegrationMetric() *schema.Resource {
Description: "Instance identifier",
},
"name": {
Type: schema.TypeString,
Required: true,
Description: "The name of metrics integration",
ValidateFunc: validateIntegrationMetricName(),
Type: schema.TypeString,
Required: true,
Description: "The name of metrics integration",
ValidateDiagFunc: validateIntegrationMetricName(),
},
"region": {
Type: schema.TypeString,
Expand Down Expand Up @@ -298,8 +298,8 @@ func resourceIntegrationMetricDelete(d *schema.ResourceData, meta interface{}) e
return api.DeleteIntegration(d.Get("instance_id").(int), "metrics", d.Id())
}

func validateIntegrationMetricName() schema.SchemaValidateFunc {
return validation.StringInSlice([]string{
func validateIntegrationMetricName() schema.SchemaValidateDiagFunc {
return validation.ToDiagFunc(validation.StringInSlice([]string{
"cloudwatch",
"cloudwatch_v2",
"librato",
Expand All @@ -308,7 +308,7 @@ func validateIntegrationMetricName() schema.SchemaValidateFunc {
"newrelic",
"newrelic_v2",
"stackdriver",
}, true)
}, true))
}

func validateIntegrationMetricSchemaAttribute(key string) bool {
Expand Down
14 changes: 7 additions & 7 deletions cloudamqp/resource_cloudamqp_node_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ func resourceNodeAction() *schema.Resource {
Description: "The name of the node",
},
"action": {
Type: schema.TypeString,
Required: true,
Description: "The action to perform on the node",
ValidateFunc: validateNodeAction(),
Type: schema.TypeString,
Required: true,
Description: "The action to perform on the node",
ValidateDiagFunc: validateNodeAction(),
},
"running": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -64,12 +64,12 @@ func resourceNodeActionRemove(d *schema.ResourceData, meta interface{}) error {
return nil
}

func validateNodeAction() schema.SchemaValidateFunc {
return validation.StringInSlice([]string{
func validateNodeAction() schema.SchemaValidateDiagFunc {
return validation.ToDiagFunc(validation.StringInSlice([]string{
"start",
"stop",
"restart",
"reboot",
"mgmt.restart",
}, true)
}, true))
}
22 changes: 11 additions & 11 deletions cloudamqp/resource_cloudamqp_notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func resourceNotification() *schema.Resource {
Required: true,
Description: "Type of the notification, valid options are: email, opsgenie, opsgenie-eu," +
"pagerduty, slack, signl4, teams, victorops, webhook",
ValidateFunc: validateNotificationType(),
ValidateDiagFunc: validateNotificationType(),
},
"value": {
Type: schema.TypeString,
Expand All @@ -58,10 +58,10 @@ func resourceNotification() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Required: true,
Description: "Responder type, valid options are: team, user, escalation, schedule",
ValidateFunc: validateOpsgenieRespondersType(),
Type: schema.TypeString,
Required: true,
Description: "Responder type, valid options are: team, user, escalation, schedule",
ValidateDiagFunc: validateOpsgenieRespondersType(),
},
"id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -199,8 +199,8 @@ func resourceNotificationDelete(d *schema.ResourceData, meta interface{}) error
return api.DeleteNotification(instanceID, recipientID)
}

func validateNotificationType() schema.SchemaValidateFunc {
return validation.StringInSlice([]string{
func validateNotificationType() schema.SchemaValidateDiagFunc {
return validation.ToDiagFunc(validation.StringInSlice([]string{
"email",
"opsgenie",
"opsgenie-eu",
Expand All @@ -210,7 +210,7 @@ func validateNotificationType() schema.SchemaValidateFunc {
"teams",
"victorops",
"webhook",
}, true)
}, true))
}

func validateRecipientAttribute(key string) bool {
Expand All @@ -225,13 +225,13 @@ func validateRecipientAttribute(key string) bool {
return false
}

func validateOpsgenieRespondersType() schema.SchemaValidateFunc {
return validation.StringInSlice([]string{
func validateOpsgenieRespondersType() schema.SchemaValidateDiagFunc {
return validation.ToDiagFunc(validation.StringInSlice([]string{
"escalation",
"schedule",
"team",
"user",
}, true)
}, true))
}

func opsGenieRespondersParameter(responders []interface{}) map[string]interface{} {
Expand Down
8 changes: 4 additions & 4 deletions cloudamqp/resource_cloudamqp_rabbitmq_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func resourceRabbitMqConfiguration() *schema.Resource {
Optional: true,
Description: "Log level for the logger used for log integrations and the CloudAMQP Console log view. " +
"Does not affect the file logger. Requires a RabbitMQ restart to be applied.",
ValidateFunc: validateLogLevel(),
ValidateDiagFunc: validateLogLevel(),
},
"cluster_partition_handling": {
Type: schema.TypeString,
Expand Down Expand Up @@ -257,16 +257,16 @@ func validateRabbitMqConfigurationJSONField(key string) bool {
return false
}

func validateLogLevel() schema.SchemaValidateFunc {
return validation.StringInSlice([]string{
func validateLogLevel() schema.SchemaValidateDiagFunc {
return validation.ToDiagFunc(validation.StringInSlice([]string{
"debug",
"info",
"warning",
"error",
"critical",
"critical",
"none",
}, true)
}, true))
}

func rabbitMqConfigurationWriteAttributeKeys() []string {
Expand Down
Loading

0 comments on commit a351503

Please sign in to comment.