sentry_alert_rule.notification_target_id could previously only point at
a target created outside Terraform (sentryctl/curl/the web UI) --
without this resource, "manage alert rules as code" was only half true.
Same create/destroy-only shape as sentry_alert_rule and for the same
reason: alerting has no PUT /targets/{id} either, confirmed down to
notifystore.Store (Create/List/Get/Delete, no Update).
client.go's notificationTarget type mirrors notifystore.Target's JSON
shape. headers stays raw JSON bytes end to end -- the client has no
opinion about its shape (neither does alerting's own Target type,
json.RawMessage), and the resource layer round-trips it as a plain
JSON-text string a caller provides via Terraform's jsonencode().
secret is marked Sensitive in the schema, but alerting's own
GET /targets/{id} returns it unredacted (confirmed in
notifystore/store.go -- no redaction at the store or handler layer, an
existing property of alerting's API, not something this provider
introduces). A new client test
(TestGetNotificationTargetReturnsSecretUnredacted) documents that real
behavior so a future change to it would be caught here, not discovered
by surprise. Sensitive keeps the value out of plan/apply console output;
it does not keep it out of Terraform state, the standard caveat for any
sensitive attribute, named explicitly in the schema description and
README rather than left implicit.
Examples updated end to end: sentry_alert_rule's example now creates a
real sentry_notification_target and references its .id, instead of a
placeholder string.
Verified: client tests are real httptest.Server round trips. Schema
validation needs no Terraform binary.
TestAccNotificationTargetResource_basic is a real acceptance test,
skip-gated by TF_ACC same as the other two, including a
plancheck.ExpectResourceAction assertion that a config change actually
plans destroy-then-create, and (since secret really does round-trip
unredacted) a real ImportStateVerify on the secret attribute rather than
one papered over with ImportStateVerifyIgnore. Not run against a live
stack in this environment, same disclosed gap as everything else
Docker-gated in this repo.
136 lines
4.5 KiB
Go
136 lines
4.5 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform-plugin-framework/provider"
|
|
"github.com/hashicorp/terraform-plugin-framework/resource"
|
|
)
|
|
|
|
// TestProviderSchemaValid and TestDashboardResourceSchemaValid don't
|
|
// need a Terraform binary or a live api service -- ValidateImplementation
|
|
// runs the same internal consistency checks
|
|
// terraform-plugin-framework's own protocol layer would (attribute
|
|
// names are valid identifiers, no Optional+Required conflicts, etc.),
|
|
// catching a broken schema before it ever reaches an acceptance test.
|
|
func TestProviderSchemaValid(t *testing.T) {
|
|
ctx := context.Background()
|
|
req := provider.SchemaRequest{}
|
|
resp := &provider.SchemaResponse{}
|
|
|
|
New("test")().Schema(ctx, req, resp)
|
|
|
|
if resp.Diagnostics.HasError() {
|
|
t.Fatalf("provider schema has errors: %v", resp.Diagnostics)
|
|
}
|
|
for _, attr := range []string{"endpoint", "alerting_endpoint", "token"} {
|
|
if _, ok := resp.Schema.Attributes[attr]; !ok {
|
|
t.Errorf("provider schema missing expected attribute %q", attr)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDashboardResourceSchemaValid(t *testing.T) {
|
|
ctx := context.Background()
|
|
req := resource.SchemaRequest{}
|
|
resp := &resource.SchemaResponse{}
|
|
|
|
newDashboardResource().Schema(ctx, req, resp)
|
|
|
|
if resp.Diagnostics.HasError() {
|
|
t.Fatalf("sentry_dashboard schema has errors: %v", resp.Diagnostics)
|
|
}
|
|
for _, attr := range []string{
|
|
"id", "tenant_id", "name", "description",
|
|
"default_earliest", "default_latest", "created_by", "created_at", "updated_at",
|
|
} {
|
|
if _, ok := resp.Schema.Attributes[attr]; !ok {
|
|
t.Errorf("sentry_dashboard schema missing expected attribute %q", attr)
|
|
}
|
|
}
|
|
if !resp.Schema.Attributes["name"].IsRequired() {
|
|
t.Error(`"name" must be Required`)
|
|
}
|
|
if !resp.Schema.Attributes["id"].IsComputed() {
|
|
t.Error(`"id" must be Computed`)
|
|
}
|
|
}
|
|
|
|
func TestDashboardResourceMetadataSetsTypeName(t *testing.T) {
|
|
resp := &resource.MetadataResponse{}
|
|
newDashboardResource().Metadata(context.Background(), resource.MetadataRequest{ProviderTypeName: "sentry"}, resp)
|
|
if resp.TypeName != "sentry_dashboard" {
|
|
t.Fatalf("TypeName = %q, want sentry_dashboard", resp.TypeName)
|
|
}
|
|
}
|
|
|
|
func TestAlertRuleResourceSchemaValid(t *testing.T) {
|
|
ctx := context.Background()
|
|
req := resource.SchemaRequest{}
|
|
resp := &resource.SchemaResponse{}
|
|
|
|
newAlertRuleResource().Schema(ctx, req, resp)
|
|
|
|
if resp.Diagnostics.HasError() {
|
|
t.Fatalf("sentry_alert_rule schema has errors: %v", resp.Diagnostics)
|
|
}
|
|
for _, attr := range []string{
|
|
"id", "tenant_id", "name", "description", "query", "query_language",
|
|
"condition_type", "comparator", "threshold_value", "eval_interval_seconds",
|
|
"for_minutes", "renotify_interval_minutes", "notification_target_id", "enabled", "created_by",
|
|
} {
|
|
if _, ok := resp.Schema.Attributes[attr]; !ok {
|
|
t.Errorf("sentry_alert_rule schema missing expected attribute %q", attr)
|
|
}
|
|
}
|
|
if !resp.Schema.Attributes["name"].IsRequired() {
|
|
t.Error(`"name" must be Required`)
|
|
}
|
|
if !resp.Schema.Attributes["id"].IsComputed() {
|
|
t.Error(`"id" must be Computed`)
|
|
}
|
|
}
|
|
|
|
func TestAlertRuleResourceMetadataSetsTypeName(t *testing.T) {
|
|
resp := &resource.MetadataResponse{}
|
|
newAlertRuleResource().Metadata(context.Background(), resource.MetadataRequest{ProviderTypeName: "sentry"}, resp)
|
|
if resp.TypeName != "sentry_alert_rule" {
|
|
t.Fatalf("TypeName = %q, want sentry_alert_rule", resp.TypeName)
|
|
}
|
|
}
|
|
|
|
func TestNotificationTargetResourceSchemaValid(t *testing.T) {
|
|
ctx := context.Background()
|
|
req := resource.SchemaRequest{}
|
|
resp := &resource.SchemaResponse{}
|
|
|
|
newNotificationTargetResource().Schema(ctx, req, resp)
|
|
|
|
if resp.Diagnostics.HasError() {
|
|
t.Fatalf("sentry_notification_target schema has errors: %v", resp.Diagnostics)
|
|
}
|
|
for _, attr := range []string{
|
|
"id", "tenant_id", "name", "kind", "webhook_url",
|
|
"payload_template", "headers", "secret", "created_by",
|
|
} {
|
|
if _, ok := resp.Schema.Attributes[attr]; !ok {
|
|
t.Errorf("sentry_notification_target schema missing expected attribute %q", attr)
|
|
}
|
|
}
|
|
if !resp.Schema.Attributes["name"].IsRequired() {
|
|
t.Error(`"name" must be Required`)
|
|
}
|
|
if !resp.Schema.Attributes["secret"].IsSensitive() {
|
|
t.Error(`"secret" must be Sensitive`)
|
|
}
|
|
}
|
|
|
|
func TestNotificationTargetResourceMetadataSetsTypeName(t *testing.T) {
|
|
resp := &resource.MetadataResponse{}
|
|
newNotificationTargetResource().Metadata(context.Background(), resource.MetadataRequest{ProviderTypeName: "sentry"}, resp)
|
|
if resp.TypeName != "sentry_notification_target" {
|
|
t.Fatalf("TypeName = %q, want sentry_notification_target", resp.TypeName)
|
|
}
|
|
}
|