Add read-only data sources for all three Terraform resources
Mechanical, low-risk follow-up -- no new architectural question, no new
external service, no new write path. Each of sentry_dashboard,
sentry_alert_rule, and sentry_notification_target gets a matching data
source: a single Required id attribute in, every other attribute
Computed out, backed by the exact same getDashboard/getRule/
getNotificationTarget client methods and dashboardModelFromAPI/
alertRuleModelFromAPI/notificationTargetModelFromAPI conversion
functions the resources already use and already have tests for -- these
data sources add no new client code at all, just a thin
datasource.DataSource wrapper reusing what Create/Read/Update/Delete
already exercise.
sentry_notification_target's data source carries the same secret
caveat its resource does (Sensitive, but alerting's GET /targets/{id}
returns it unredacted, so it's a real plaintext value in Terraform
state) -- named again here rather than assumed obvious from the
resource's own docs.
Verified: provider_test.go's new schema-validation tests confirm each
data source's id is Required and everything else Computed, no
Terraform binary needed. Three new real acceptance tests
(TestAccDashboardDataSource_basic and its two siblings) each create a
resource then look it up via the matching data source, using
resource.TestCheckResourceAttrPair to prove the data source's Read
actually agrees with what the resource wrote -- not just that both
compile. Skip-gated by TF_ACC same as the existing six acceptance
tests, and needs the same live api/alerting services this environment
has no Docker access to bring up, so not run here -- same disclosed gap
as everything else Docker-gated in this repo.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/provider"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
)
|
||||
@@ -133,3 +134,75 @@ func TestNotificationTargetResourceMetadataSetsTypeName(t *testing.T) {
|
||||
t.Fatalf("TypeName = %q, want sentry_notification_target", resp.TypeName)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDashboardDataSourceSchemaValid(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
req := datasource.SchemaRequest{}
|
||||
resp := &datasource.SchemaResponse{}
|
||||
|
||||
newDashboardDataSource().Schema(ctx, req, resp)
|
||||
|
||||
if resp.Diagnostics.HasError() {
|
||||
t.Fatalf("sentry_dashboard data source schema has errors: %v", resp.Diagnostics)
|
||||
}
|
||||
if !resp.Schema.Attributes["id"].IsRequired() {
|
||||
t.Error(`"id" must be Required -- a data source needs it to know what to look up`)
|
||||
}
|
||||
if !resp.Schema.Attributes["name"].IsComputed() {
|
||||
t.Error(`"name" must be Computed`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAlertRuleDataSourceSchemaValid(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
req := datasource.SchemaRequest{}
|
||||
resp := &datasource.SchemaResponse{}
|
||||
|
||||
newAlertRuleDataSource().Schema(ctx, req, resp)
|
||||
|
||||
if resp.Diagnostics.HasError() {
|
||||
t.Fatalf("sentry_alert_rule data source schema has errors: %v", resp.Diagnostics)
|
||||
}
|
||||
if !resp.Schema.Attributes["id"].IsRequired() {
|
||||
t.Error(`"id" must be Required`)
|
||||
}
|
||||
if !resp.Schema.Attributes["query"].IsComputed() {
|
||||
t.Error(`"query" must be Computed`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotificationTargetDataSourceSchemaValid(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
req := datasource.SchemaRequest{}
|
||||
resp := &datasource.SchemaResponse{}
|
||||
|
||||
newNotificationTargetDataSource().Schema(ctx, req, resp)
|
||||
|
||||
if resp.Diagnostics.HasError() {
|
||||
t.Fatalf("sentry_notification_target data source schema has errors: %v", resp.Diagnostics)
|
||||
}
|
||||
if !resp.Schema.Attributes["id"].IsRequired() {
|
||||
t.Error(`"id" must be Required`)
|
||||
}
|
||||
if !resp.Schema.Attributes["secret"].IsSensitive() {
|
||||
t.Error(`"secret" must be Sensitive`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDataSourcesMetadataSetTypeNames(t *testing.T) {
|
||||
cases := []struct {
|
||||
newDS func() datasource.DataSource
|
||||
wantType string
|
||||
}{
|
||||
{newDashboardDataSource, "sentry_dashboard"},
|
||||
{newAlertRuleDataSource, "sentry_alert_rule"},
|
||||
{newNotificationTargetDataSource, "sentry_notification_target"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
resp := &datasource.MetadataResponse{}
|
||||
c.newDS().Metadata(context.Background(), datasource.MetadataRequest{ProviderTypeName: "sentry"}, resp)
|
||||
if resp.TypeName != c.wantType {
|
||||
t.Errorf("TypeName = %q, want %q", resp.TypeName, c.wantType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user