forked from cloudflare/terraform-provider-cloudflare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema_cloudflare_access_application.go
1524 lines (1417 loc) · 56.4 KB
/
schema_cloudflare_access_application.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package sdkv2provider
import (
"fmt"
"regexp"
"time"
"github.com/cloudflare/cloudflare-go"
"github.com/cloudflare/terraform-provider-cloudflare/internal/consts"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/pkg/errors"
)
func resourceCloudflareAccessApplicationSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
consts.AccountIDSchemaKey: {
Description: consts.AccountIDSchemaDescription,
Type: schema.TypeString,
Optional: true,
Computed: true,
ConflictsWith: []string{consts.ZoneIDSchemaKey},
},
consts.ZoneIDSchemaKey: {
Description: consts.ZoneIDSchemaDescription,
Type: schema.TypeString,
Optional: true,
Computed: true,
ConflictsWith: []string{consts.AccountIDSchemaKey},
},
"aud": {
Type: schema.TypeString,
Computed: true,
Description: "Application Audience (AUD) Tag of the application.",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Friendly name of the Access Application.",
Optional: true,
},
"domain": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The primary hostname and path that Access will secure. If the app is visible in the App Launcher dashboard, this is the domain that will be displayed.",
DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool {
appType := d.Get("type").(string)
// Suppress the diff if it's an app type that doesn't need a `domain` value.
if appType == "infrastructure" {
return true
}
return oldValue == newValue
},
},
"domain_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{"public", "private"}, false),
Description: fmt.Sprintf("The type of the primary domain. %s", renderAvailableDocumentationValuesStringSlice([]string{"public", "private"})),
DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool {
appType := d.Get("type").(string)
// Suppress the diff if it's an app type that doesn't need a `domain` value.
if appType == "infrastructure" {
return true
}
return oldValue == newValue
},
},
"destinations": {
Type: schema.TypeList,
Optional: true,
ConflictsWith: []string{"self_hosted_domains"},
Description: "A destination secured by Access. Only present for self_hosted, vnc, and ssh applications. Always includes the value set as `domain`. Supersedes `self_hosted_domains` to allow for more flexibility in defining different types of destinations.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Default: "public",
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"public", "private"}, false),
Description: fmt.Sprintf("The destination type. %s", renderAvailableDocumentationValuesStringSlice([]string{"public", "private"})),
},
"uri": {
Type: schema.TypeString,
Required: true,
Description: "The URI of the destination. Public destinations can include a domain and path with wildcards. Private destinations are an early access feature and gated behind a feature flag. Private destinations support private IPv4, IPv6, and Server Name Indications (SNI) with optional port ranges.",
},
},
},
},
"self_hosted_domains": {
Type: schema.TypeSet,
Optional: true,
ConflictsWith: []string{"destinations"},
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "List of public domains secured by Access. Only present for self_hosted, vnc, and ssh applications. Always includes the value set as `domain`. Deprecated in favor of `destinations` and will be removed in the next major version.",
Deprecated: "Use `destinations` instead",
},
"type": {
Type: schema.TypeString,
Optional: true,
Default: "self_hosted",
ValidateFunc: validation.StringInSlice([]string{"app_launcher", "bookmark", "biso", "dash_sso", "saas", "self_hosted", "ssh", "vnc", "warp", "infrastructure"}, false),
Description: fmt.Sprintf("The application type. %s", renderAvailableDocumentationValuesStringSlice([]string{"app_launcher", "bookmark", "biso", "dash_sso", "saas", "self_hosted", "ssh", "vnc", "warp", "infrastructure"})),
},
"policies": {
Type: schema.TypeList,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Optional: true,
Description: "The policies associated with the application, in ascending order of precedence." +
" Warning: Do not use this field while you still have this application ID referenced as `application_id`" +
" in any `cloudflare_access_policy` resource, as it can result in an inconsistent state.",
},
"session_duration": {
Type: schema.TypeString,
Optional: true,
Default: "24h",
DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool {
appType := d.Get("type").(string)
// Suppress the diff if it's an app type that doesn't need a `session_duration` value.
if appType == "bookmark" || appType == "infrastructure" {
return true
}
return oldValue == newValue
},
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) {
v := val.(string)
_, err := time.ParseDuration(v)
if err != nil {
errs = append(errs, fmt.Errorf(`%q only supports "ns", "us" (or "µs"), "ms", "s", "m", or "h" as valid units`, key))
}
return
},
Description: "How often a user will be forced to re-authorise. Must be in the format `48h` or `2h45m`",
},
"cors_headers": {
Type: schema.TypeList,
Optional: true,
Description: "CORS configuration for the Access Application. See below for reference structure.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"allowed_methods": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "List of methods to expose via CORS.",
},
"allowed_origins": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "List of origins permitted to make CORS requests.",
},
"allowed_headers": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "List of HTTP headers to expose via CORS.",
},
"allow_all_methods": {
Type: schema.TypeBool,
Optional: true,
Description: "Value to determine whether all methods are exposed.",
},
"allow_all_origins": {
Type: schema.TypeBool,
Optional: true,
Description: "Value to determine whether all origins are permitted to make CORS requests.",
},
"allow_all_headers": {
Type: schema.TypeBool,
Optional: true,
Description: "Value to determine whether all HTTP headers are exposed.",
},
"allow_credentials": {
Type: schema.TypeBool,
Optional: true,
Description: "Value to determine if credentials (cookies, authorization headers, or TLS client certificates) are included with requests.",
},
"max_age": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(-1, 86400),
Description: "The maximum time a preflight request will be cached.",
},
},
},
},
"saas_app": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "SaaS configuration for the Access Application.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
// shared values
"auth_type": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"oidc", "saml"}, false),
Description: "",
ForceNew: true,
},
"public_key": {
Type: schema.TypeString,
Computed: true,
Description: "The public certificate that will be used to verify identities.",
},
// OIDC options
"client_id": {
Type: schema.TypeString,
Computed: true,
Description: "The application client id",
},
"client_secret": {
Type: schema.TypeString,
Computed: true,
Description: "The application client secret, only returned on initial apply",
Sensitive: true,
},
"redirect_uris": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "The permitted URL's for Cloudflare to return Authorization codes and Access/ID tokens",
},
"grant_types": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "The OIDC flows supported by this application",
},
"scopes": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "Define the user information shared with access",
},
"app_launcher_url": {
Type: schema.TypeString,
Optional: true,
Description: "The URL where this applications tile redirects users",
},
"group_filter_regex": {
Type: schema.TypeString,
Optional: true,
Description: "A regex to filter Cloudflare groups returned in ID token and userinfo endpoint",
},
"access_token_lifetime": {
Type: schema.TypeString,
Optional: true,
Description: "The lifetime of the Access Token after creation. Valid units are `m` and `h`. Must be greater than or equal to 1m and less than or equal to 24h.",
},
"allow_pkce_without_client_secret": {
Type: schema.TypeBool,
Optional: true,
Description: "Allow PKCE flow without a client secret",
},
"refresh_token_options": {
Type: schema.TypeList,
Optional: true,
Description: "Refresh token grant options",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"lifetime": {
Type: schema.TypeString,
Optional: true,
Description: "How long a refresh token will be valid for after creation. Valid units are `m`, `h` and `d`. Must be longer than 1m.",
},
},
},
},
"custom_claim": {
Type: schema.TypeList,
Optional: true,
Description: "Custom claim mapped from IDPs.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
Description: "The name of the attribute as provided to the SaaS app.",
},
"scope": {
Type: schema.TypeString,
Optional: true,
Description: "The scope of the claim.",
},
"required": {
Type: schema.TypeBool,
Optional: true,
Description: "True if the attribute must be always present.",
},
"source": {
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "The name of the attribute as provided by the IDP.",
},
"name_by_idp": {
Type: schema.TypeMap,
Optional: true,
Description: "A mapping from IdP ID to claim name.",
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
},
},
},
"hybrid_and_implicit_options": {
Type: schema.TypeList,
Optional: true,
Description: "Hybrid and Implicit Flow options",
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"return_access_token_from_authorization_endpoint": {
Type: schema.TypeBool,
Optional: true,
Description: "If true, the authorization endpoint will return an access token",
},
"return_id_token_from_authorization_endpoint": {
Type: schema.TypeBool,
Optional: true,
Description: "If true, the authorization endpoint will return an id token",
},
},
},
},
// SAML options
"sp_entity_id": {
Type: schema.TypeString,
Optional: true,
Description: "A globally unique name for an identity or service provider.",
},
"consumer_service_url": {
Type: schema.TypeString,
Optional: true,
Description: "The service provider's endpoint that is responsible for receiving and parsing a SAML assertion.",
},
"name_id_format": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"email", "id"}, false),
Description: "The format of the name identifier sent to the SaaS application.",
},
"custom_attribute": {
Type: schema.TypeList,
Optional: true,
Description: "Custom attribute mapped from IDPs.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
Description: "The name of the attribute as provided to the SaaS app.",
},
"name_format": {
Type: schema.TypeString,
Optional: true,
Description: "A globally unique name for an identity or service provider.",
},
"friendly_name": {
Type: schema.TypeString,
Optional: true,
Description: "A friendly name for the attribute as provided to the SaaS app.",
},
"required": {
Type: schema.TypeBool,
Optional: true,
Description: "True if the attribute must be always present.",
},
"source": {
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "The name of the attribute as provided by the IDP.",
},
"name_by_idp": {
Type: schema.TypeMap,
Optional: true,
Description: "A mapping from IdP ID to claim name.",
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
},
},
},
"idp_entity_id": {
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for the SaaS application.",
},
"sso_endpoint": {
Type: schema.TypeString,
Computed: true,
Description: "The endpoint where the SaaS application will send login requests.",
},
"default_relay_state": {
Type: schema.TypeString,
Optional: true,
Description: "The relay state used if not provided by the identity provider.",
},
"name_id_transform_jsonata": {
Type: schema.TypeString,
Optional: true,
Description: "A [JSONata](https://jsonata.org/) expression that transforms an application's user identities into a NameID value for its SAML assertion. This expression should evaluate to a singular string. The output of this expression can override the `name_id_format` setting.",
},
"saml_attribute_transform_jsonata": {
Type: schema.TypeString,
Optional: true,
Description: "A [JSONata](https://jsonata.org/) expression that transforms an application's user identities into attribute assertions in the SAML response. The expression can transform id, email, name, and groups values. It can also transform fields listed in the saml_attributes or oidc_fields of the identity provider used to authenticate. The output of this expression must be a JSON object.",
},
},
},
},
"target_criteria": {
Type: schema.TypeList,
Optional: true,
Description: "The payload for an infrastructure application which defines the port, protocol, and target attributes. Only applicable to Infrastructure Applications, in which case this field is required.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"port": {
Type: schema.TypeInt,
Required: true,
Description: "The port that the targets use for the chosen communication protocol. A port cannot be assigned to multiple protocols.",
},
"protocol": {
Type: schema.TypeString,
Required: true,
Description: "The communication protocol your application secures.",
},
"target_attributes": {
Type: schema.TypeList,
Required: true,
Description: "Contains a map of target attribute keys to target attribute values.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "The key of the attribute.",
},
"values": {
Type: schema.TypeList,
Required: true,
Description: "The values of the attribute.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
},
},
},
"auto_redirect_to_identity": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Option to skip identity provider selection if only one is configured in `allowed_idps`.",
},
"enable_binding_cookie": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Option to provide increased security against compromised authorization tokens and CSRF attacks by requiring an additional \"binding\" cookie on requests.",
},
"allowed_idps": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "The identity providers selected for the application.",
},
"custom_deny_message": {
Type: schema.TypeString,
Optional: true,
Description: "Option that returns a custom error message when a user is denied access to the application.",
},
"custom_deny_url": {
Type: schema.TypeString,
Optional: true,
Description: "Option that redirects to a custom URL when a user is denied access to the application via identity based rules.",
},
"custom_non_identity_deny_url": {
Type: schema.TypeString,
Optional: true,
Description: "Option that redirects to a custom URL when a user is denied access to the application via non identity rules.",
},
"http_only_cookie_attribute": {
Type: schema.TypeBool,
Optional: true,
Description: "Option to add the `HttpOnly` cookie flag to access tokens.",
},
"same_site_cookie_attribute": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"none", "lax", "strict"}, false),
Description: fmt.Sprintf("Defines the same-site cookie setting for access tokens. %s", renderAvailableDocumentationValuesStringSlice(([]string{"none", "lax", "strict"}))),
},
"logo_url": {
Type: schema.TypeString,
Optional: true,
Description: "Image URL for the logo shown in the app launcher dashboard.",
},
"skip_interstitial": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Option to skip the authorization interstitial when using the CLI.",
},
"app_launcher_visible": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Option to show/hide applications in App Launcher.",
DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool {
appType := d.Get("type").(string)
// Suppress the diff if it's an app type that doesn't need a `app_launcher_visible`
// value.
if appType == "infrastructure" {
return true
}
return oldValue == newValue
},
},
"service_auth_401_redirect": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Option to return a 401 status code in service authentication rules on failed requests.",
},
"custom_pages": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "The custom pages selected for the application.",
},
"tags": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "The itags associated with the application.",
},
"app_launcher_logo_url": {
Type: schema.TypeString,
Optional: true,
Description: "The logo URL of the app launcher.",
},
"header_bg_color": {
Type: schema.TypeString,
Optional: true,
Description: "The background color of the header bar in the app launcher.",
},
"bg_color": {
Type: schema.TypeString,
Optional: true,
Description: "The background color of the app launcher.",
},
"footer_links": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
Description: "The name of the footer link.",
},
"url": {
Type: schema.TypeString,
Optional: true,
Description: "The URL of the footer link.",
},
},
},
Description: "The footer links of the app launcher.",
},
"landing_page_design": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "The landing page design of the app launcher.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"title": {
Type: schema.TypeString,
Optional: true,
Description: "The title of the landing page.",
},
"message": {
Type: schema.TypeString,
Optional: true,
Description: "The message of the landing page.",
},
"button_text_color": {
Type: schema.TypeString,
Optional: true,
Description: "The button text color of the landing page.",
},
"button_color": {
Type: schema.TypeString,
Optional: true,
Description: "The button color of the landing page.",
},
"image_url": {
Type: schema.TypeString,
Optional: true,
Description: "The URL of the image to be displayed in the landing page.",
},
},
},
},
"skip_app_launcher_login_page": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Option to skip the App Launcher landing page.",
},
"allow_authenticate_via_warp": {
Type: schema.TypeBool,
Optional: true,
Description: "When set to true, users can authenticate to this application using their WARP session. When set to false this application will always require direct IdP authentication. This setting always overrides the organization setting for WARP authentication.",
},
"options_preflight_bypass": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Allows options preflight requests to bypass Access authentication and go directly to the origin. Cannot turn on if cors_headers is set.",
},
"scim_config": {
Type: schema.TypeList,
Optional: true,
Description: "Configuration for provisioning to this application via SCIM. This is currently in closed beta.",
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Optional: true,
Description: "Whether SCIM provisioning is turned on for this application.",
},
"remote_uri": {
Type: schema.TypeString,
Required: true,
Description: "The base URI for the application's SCIM-compatible API.",
},
"idp_uid": {
Type: schema.TypeString,
Required: true,
Description: "The UIDs of the IdP to use as the source for SCIM resources to provision to this application.",
},
"deactivate_on_delete": {
Type: schema.TypeBool,
Optional: true,
Description: "If false, propagates DELETE requests to the target application for SCIM resources. If true, sets 'active' to false on the SCIM resource. Note: Some targets do not support DELETE operations.",
},
"authentication": {
Type: schema.TypeList,
Optional: true,
Description: "Attributes for configuring HTTP Basic, OAuth Bearer token, or OAuth 2 authentication schemes for SCIM provisioning to an application.",
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
// Common Attributes
"scheme": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"httpbasic", "oauthbearertoken", "oauth2"}, false),
Description: "The authentication scheme to use when making SCIM requests to this application.",
},
// HTTP Basic Authentication Attributes
"user": {
Type: schema.TypeString,
Optional: true,
RequiredWith: []string{"scim_config.0.authentication.0.password"},
ConflictsWith: []string{"scim_config.0.authentication.0.token", "scim_config.0.authentication.0.client_id", "scim_config.0.authentication.0.client_secret", "scim_config.0.authentication.0.authorization_url", "scim_config.0.authentication.0.token_url", "scim_config.0.authentication.0.scopes"},
Description: "User name used to authenticate with the remote SCIM service.",
},
"password": {
Type: schema.TypeString,
Optional: true,
RequiredWith: []string{"scim_config.0.authentication.0.user"},
ConflictsWith: []string{"scim_config.0.authentication.0.token", "scim_config.0.authentication.0.client_id", "scim_config.0.authentication.0.client_secret", "scim_config.0.authentication.0.authorization_url", "scim_config.0.authentication.0.token_url", "scim_config.0.authentication.0.scopes"},
StateFunc: func(val interface{}) string {
return CONCEALED_STRING
},
},
// OAuth Bearer Token Authentication Attributes
"token": {
Type: schema.TypeString,
Optional: true,
Description: "Token used to authenticate with the remote SCIM service.",
ConflictsWith: []string{"scim_config.0.authentication.0.user", "scim_config.0.authentication.0.password", "scim_config.0.authentication.0.client_id", "scim_config.0.authentication.0.client_secret", "scim_config.0.authentication.0.authorization_url", "scim_config.0.authentication.0.token_url", "scim_config.0.authentication.0.scopes"},
StateFunc: func(val interface{}) string {
return CONCEALED_STRING
},
},
// OAuth 2 Authentication Attributes
"client_id": {
Type: schema.TypeString,
Optional: true,
Description: "Client ID used to authenticate when generating a token for authenticating with the remote SCIM service.",
RequiredWith: []string{"scim_config.0.authentication.0.client_secret", "scim_config.0.authentication.0.authorization_url", "scim_config.0.authentication.0.token_url"},
ConflictsWith: []string{"scim_config.0.authentication.0.user", "scim_config.0.authentication.0.password", "scim_config.0.authentication.0.token"},
},
"client_secret": {
Type: schema.TypeString,
Optional: true,
Description: "Secret used to authenticate when generating a token for authenticating with the remove SCIM service.",
RequiredWith: []string{"scim_config.0.authentication.0.client_id", "scim_config.0.authentication.0.authorization_url", "scim_config.0.authentication.0.token_url"},
ConflictsWith: []string{"scim_config.0.authentication.0.user", "scim_config.0.authentication.0.password", "scim_config.0.authentication.0.token"},
StateFunc: func(val interface{}) string {
return CONCEALED_STRING
},
},
"authorization_url": {
Type: schema.TypeString,
Optional: true,
Description: "URL used to generate the auth code used during token generation.",
RequiredWith: []string{"scim_config.0.authentication.0.client_secret", "scim_config.0.authentication.0.client_id", "scim_config.0.authentication.0.token_url"},
ConflictsWith: []string{"scim_config.0.authentication.0.user", "scim_config.0.authentication.0.password", "scim_config.0.authentication.0.token"},
},
"token_url": {
Type: schema.TypeString,
Optional: true,
Description: "URL used to generate the token used to authenticate with the remote SCIM service.",
RequiredWith: []string{"scim_config.0.authentication.0.client_secret", "scim_config.0.authentication.0.authorization_url", "scim_config.0.authentication.0.client_id"},
ConflictsWith: []string{"scim_config.0.authentication.0.user", "scim_config.0.authentication.0.password", "scim_config.0.authentication.0.token"},
},
"scopes": {
Type: schema.TypeSet,
Description: "The authorization scopes to request when generating the token used to authenticate with the remove SCIM service.",
Optional: true,
ConflictsWith: []string{"scim_config.0.authentication.0.user", "scim_config.0.authentication.0.password", "scim_config.0.authentication.0.token"},
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"mappings": {
Type: schema.TypeList,
Optional: true,
Description: "A list of mappings to apply to SCIM resources before provisioning them in this application. These can transform or filter the resources to be provisioned.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"schema": {
Type: schema.TypeString,
Required: true,
Description: "Which SCIM resource type this mapping applies to.",
ValidateFunc: validation.StringMatch(regexp.MustCompile(`urn:.*`), "schema must begin with \"urn:\""),
},
"enabled": {
Type: schema.TypeBool,
Optional: true,
Description: "Whether or not this mapping is enabled.",
},
"filter": {
Type: schema.TypeString,
Optional: true,
Description: "A [SCIM filter expression](https://datatracker.ietf.org/doc/html/rfc7644#section-3.4.2.2) that matches resources that should be provisioned to this application.",
},
"transform_jsonata": {
Type: schema.TypeString,
Optional: true,
Description: "A [JSONata](https://jsonata.org/) expression that transforms the resource before provisioning it in the application.",
},
"operations": {
Type: schema.TypeList,
Optional: true,
Description: "Whether or not this mapping applies to creates, updates, or deletes.",
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"create": {
Type: schema.TypeBool,
Optional: true,
Description: "Whether or not this mapping applies to create (POST) operations.",
},
"update": {
Type: schema.TypeBool,
Optional: true,
Description: "Whether or not this mapping applies to update (PATCH/PUT) operations.",
},
"delete": {
Type: schema.TypeBool,
Optional: true,
Description: "Whether or not this mapping applies to DELETE operations.",
},
},
},
},
"strictness": {
Type: schema.TypeString,
Optional: true,
Description: "How strictly to adhere to outbound resource schemas when provisioning to this mapping. \"strict\" will remove unknown values when provisioning, while \"passthrough\" will pass unknown values to the target.",
},
},
},
},
},
},
},
}
}
func convertCORSSchemaToStruct(d *schema.ResourceData) (*cloudflare.AccessApplicationCorsHeaders, error) {
CORSConfig := cloudflare.AccessApplicationCorsHeaders{}
if _, ok := d.GetOk("cors_headers"); ok {
if allowedMethods, ok := d.GetOk("cors_headers.0.allowed_methods"); ok {
CORSConfig.AllowedMethods = expandInterfaceToStringList(allowedMethods.(*schema.Set).List())
}
if allowedHeaders, ok := d.GetOk("cors_headers.0.allowed_headers"); ok {
CORSConfig.AllowedHeaders = expandInterfaceToStringList(allowedHeaders.(*schema.Set).List())
}
if allowedOrigins, ok := d.GetOk("cors_headers.0.allowed_origins"); ok {
CORSConfig.AllowedOrigins = expandInterfaceToStringList(allowedOrigins.(*schema.Set).List())
}
CORSConfig.AllowAllMethods = d.Get("cors_headers.0.allow_all_methods").(bool)
CORSConfig.AllowAllHeaders = d.Get("cors_headers.0.allow_all_headers").(bool)
CORSConfig.AllowAllOrigins = d.Get("cors_headers.0.allow_all_origins").(bool)
CORSConfig.AllowCredentials = d.Get("cors_headers.0.allow_credentials").(bool)
CORSConfig.MaxAge = d.Get("cors_headers.0.max_age").(int)
// Prevent misconfigurations of CORS when `Access-Control-Allow-Origin` is
// a wildcard (aka all origins) and using credentials.
// See https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSNotSupportingCredentials
if CORSConfig.AllowCredentials {
if contains(CORSConfig.AllowedOrigins, "*") || CORSConfig.AllowAllOrigins {
return nil, errors.New("CORS credentials are not permitted when all origins are allowed")
}
}
// Ensure that should someone forget to set allowed methods (either
// individually or *), we throw an error to prevent getting into an
// unrecoverable state.
if CORSConfig.AllowAllOrigins || len(CORSConfig.AllowedOrigins) > 1 {
if CORSConfig.AllowAllMethods == false && len(CORSConfig.AllowedMethods) == 0 {
return nil, errors.New("must set allowed_methods or allow_all_methods")
}
}
// Ensure that should someone forget to set allowed origins (either
// individually or *), we throw an error to prevent getting into an
// unrecoverable state.
if CORSConfig.AllowAllMethods || len(CORSConfig.AllowedMethods) > 1 {
if CORSConfig.AllowAllOrigins == false && len(CORSConfig.AllowedOrigins) == 0 {
return nil, errors.New("must set allowed_origins or allow_all_origins")
}
}
}
return &CORSConfig, nil
}
func convertCORSStructToSchema(d *schema.ResourceData, headers *cloudflare.AccessApplicationCorsHeaders) []interface{} {
if _, ok := d.GetOk("cors_headers"); !ok {
return []interface{}{}
}
if headers == nil {
return []interface{}{}
}
m := map[string]interface{}{
"allow_all_methods": headers.AllowAllMethods,
"allow_all_headers": headers.AllowAllHeaders,
"allow_all_origins": headers.AllowAllOrigins,
"allow_credentials": headers.AllowCredentials,
"max_age": headers.MaxAge,
}
m["allowed_methods"] = flattenStringList(headers.AllowedMethods)
m["allowed_headers"] = flattenStringList(headers.AllowedHeaders)
m["allowed_origins"] = flattenStringList(headers.AllowedOrigins)
return []interface{}{m}
}
func convertNameByIDP(source map[string]interface{}) map[string]string {
nameByIDP := make(map[string]string)
for k, v := range source {
nameByIDP[k] = v.(string)
}
return nameByIDP
}
func convertSAMLAttributeSchemaToStruct(data map[string]interface{}) cloudflare.SAMLAttributeConfig {
var cfg cloudflare.SAMLAttributeConfig
cfg.Name, _ = data["name"].(string)
cfg.NameFormat, _ = data["name_format"].(string)
cfg.Required, _ = data["required"].(bool)
cfg.FriendlyName, _ = data["friendly_name"].(string)
sourcesSlice, _ := data["source"].([]interface{})
if len(sourcesSlice) != 0 {
sourceMap, ok := sourcesSlice[0].(map[string]interface{})
if ok {
cfg.Source.Name, _ = sourceMap["name"].(string)
nameByIDPInterface, _ := sourceMap["name_by_idp"].(map[string]interface{})
cfg.Source.NameByIDP = convertNameByIDP(nameByIDPInterface)
}
}
return cfg
}
func convertOIDCClaimSchemaToStruct(data map[string]interface{}) cloudflare.OIDCClaimConfig {
var cfg cloudflare.OIDCClaimConfig
cfg.Name, _ = data["name"].(string)
cfg.Scope, _ = data["scope"].(string)
cfg.Required = cloudflare.BoolPtr(data["required"].(bool))
sourcesSlice, _ := data["source"].([]interface{})
if len(sourcesSlice) != 0 {
sourceMap, ok := sourcesSlice[0].(map[string]interface{})
if ok {
cfg.Source.Name, _ = sourceMap["name"].(string)
nameByIDPInterface, _ := sourceMap["name_by_idp"].(map[string]interface{})
cfg.Source.NameByIDP = convertNameByIDP(nameByIDPInterface)
}
}
return cfg
}
func convertSaasSchemaToStruct(d *schema.ResourceData) *cloudflare.SaasApplication {
SaasConfig := cloudflare.SaasApplication{}
if _, ok := d.GetOk("saas_app"); ok {
authType := "saml"
if rawAuthType, ok := d.GetOk("saas_app.0.auth_type"); ok {
authType = rawAuthType.(string)
}
SaasConfig.AuthType = authType
if authType == "oidc" {
SaasConfig.ClientID = d.Get("saas_app.0.client_id").(string)
SaasConfig.AppLauncherURL = d.Get("saas_app.0.app_launcher_url").(string)
SaasConfig.RedirectURIs = expandInterfaceToStringList(d.Get("saas_app.0.redirect_uris").(*schema.Set).List())
SaasConfig.GrantTypes = expandInterfaceToStringList(d.Get("saas_app.0.grant_types").(*schema.Set).List())
SaasConfig.Scopes = expandInterfaceToStringList(d.Get("saas_app.0.scopes").(*schema.Set).List())
SaasConfig.GroupFilterRegex = d.Get("saas_app.0.group_filter_regex").(string)
SaasConfig.AccessTokenLifetime = d.Get("saas_app.0.access_token_lifetime").(string)
SaasConfig.AllowPKCEWithoutClientSecret = cloudflare.BoolPtr(d.Get("saas_app.0.allow_pkce_without_client_secret").(bool))
if _, ok := d.GetOk("saas_app.0.refresh_token_options"); ok {
SaasConfig.RefreshTokenOptions = &cloudflare.RefreshTokenOptions{
Lifetime: d.Get("saas_app.0.refresh_token_options.0.lifetime").(string),
}
}
if d.HasChange("saas_app.0.custom_claim") {