@@ -3,13 +3,15 @@ package sentry
33import (
44 "context"
55 "errors"
6+ "fmt"
67 "net/http"
8+ "strings"
79
10+ "github.com/hashicorp/go-cty/cty"
811 "github.com/hashicorp/go-multierror"
912 "github.com/hashicorp/terraform-plugin-log/tflog"
1013 "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1114 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
12- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1315 "github.com/jianyuan/go-sentry/v2/sentry"
1416)
1517
@@ -64,7 +66,7 @@ func resourceSentryProject() *schema.Resource {
6466 Type : schema .TypeString ,
6567 Optional : true ,
6668 Computed : true ,
67- ValidateDiagFunc : validation . ToDiagFunc ( validation . StringInSlice ( platformCategories , false )) ,
69+ ValidateDiagFunc : validatePlatform ,
6870 },
6971 "internal_id" : {
7072 Description : "The internal ID for this project." ,
@@ -344,3 +346,34 @@ func resourceSentryProjectDelete(ctx context.Context, d *schema.ResourceData, me
344346
345347 return diag .FromErr (err )
346348}
349+
350+ func validatePlatform (i interface {}, path cty.Path ) diag.Diagnostics {
351+ var diagnostics diag.Diagnostics
352+
353+ v := i .(string )
354+ url := fmt .Sprintf (
355+ "https://docs.sentry.io/_platforms/%s.json" ,
356+ strings .Replace (v , "-" , "/" , 1 ),
357+ )
358+ resp , err := http .Get (url )
359+
360+ if err != nil {
361+ msg := "could not validate the platform at this time"
362+ diagnostics = append (diagnostics , diag.Diagnostic {
363+ Severity : diag .Error ,
364+ Summary : msg ,
365+ Detail : msg ,
366+ AttributePath : path ,
367+ })
368+ } else if resp .StatusCode != 200 {
369+ msg := fmt .Sprintf ("%s is not a valid platform" , v )
370+ diagnostics = append (diagnostics , diag.Diagnostic {
371+ Severity : diag .Error ,
372+ Summary : msg ,
373+ Detail : msg ,
374+ AttributePath : path ,
375+ })
376+ }
377+
378+ return diagnostics
379+ }
0 commit comments