@@ -3,13 +3,15 @@ package sentry
3
3
import (
4
4
"context"
5
5
"errors"
6
+ "fmt"
6
7
"net/http"
8
+ "strings"
7
9
10
+ "github.com/hashicorp/go-cty/cty"
8
11
"github.com/hashicorp/go-multierror"
9
12
"github.com/hashicorp/terraform-plugin-log/tflog"
10
13
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
11
14
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
12
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
13
15
"github.com/jianyuan/go-sentry/v2/sentry"
14
16
)
15
17
@@ -64,7 +66,7 @@ func resourceSentryProject() *schema.Resource {
64
66
Type : schema .TypeString ,
65
67
Optional : true ,
66
68
Computed : true ,
67
- ValidateDiagFunc : validation . ToDiagFunc ( validation . StringInSlice ( platformCategories , false )) ,
69
+ ValidateDiagFunc : validatePlatform ,
68
70
},
69
71
"internal_id" : {
70
72
Description : "The internal ID for this project." ,
@@ -344,3 +346,34 @@ func resourceSentryProjectDelete(ctx context.Context, d *schema.ResourceData, me
344
346
345
347
return diag .FromErr (err )
346
348
}
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