-
-
Notifications
You must be signed in to change notification settings - Fork 42
Description
The current structure MetricAlertTriggerAction has a field SentryAppID that is supposed to be an integer while currently it's a string.
type MetricAlertTriggerAction struct {
ID *string `json:"id,omitempty"`
AlertRuleTriggerID *string `json:"alertRuleTriggerId,omitempty"`
Type *string `json:"type,omitempty"`
TargetType *string `json:"targetType,omitempty"`
TargetIdentifier *Int64OrString `json:"targetIdentifier,omitempty"`
InputChannelID *string `json:"inputChannelId,omitempty"`
IntegrationID *int `json:"integrationId,omitempty"`
SentryAppID *string `json:"sentryAppId,omitempty"`
DateCreated *time.Time `json:"dateCreated,omitempty"`
Description *string `json:"desc,omitempty"`
}I get the following error when running a terraform plan using https://github.com/jianyuan/terraform-provider-sentry at version 0.14.3.
cannot unmarshal number into Go struct field MetricAlertTriggerAction.triggers.actions.sentryAppId of type string
I expect the problem to be affecting the latest release as well since I was able to solve it just by changing the type of SentryAppID from *string to *int.
While all tests in my fork of this repo (and in the terraform provider using this code change) are passing and it does't seem to be any other change necessary, I would suggest to add one or more tests to cover this use case.
While this field is not directly referenced anywhere in the terraform provider code, it causes an exception when trying to unmarshall the body of a list/get request.
More info on how to track the error:
1. Starting Point (Terraform Provider):
- sentry/resource_sentry_metric_alert.go:256 - resourceSentryMetricAlertRead() calls client.MetricAlerts.Get()
2. Go-Sentry SDK Service Layer:
- sentry/metric_alerts.go:98 -
MetricAlertsService.Get() calls s.client.Do(ctx, req, alert)
3. HTTP Client Layer (where unmarshalling happens):
- sentry/sentry.go:272-295 - Client.Do() method
- Specifically at line 284-286:
dec := json.NewDecoder(resp.Body)
dec.UseNumber()
decErr := dec.Decode(v) // <-- THIS IS WHERE THE ERROR OCCURS
The dec.Decode(v) is trying to decode the JSON response body into the alert variable (which is of type *MetricAlert), and when it encounters the sentryAppId field in the JSON with a number value, it fails because the struct field is defined as *string.