1
- resource "fastly_service_vcl" "ngwaf_service" {
2
- count = var. activate_ngwaf_service ? 1 : 0
3
- name = " ${ var . name } -ngwaf"
4
- activate = var. activate_ngwaf_service
5
-
6
- domain {
7
- name = var. domain
8
- comment = " NGWAF domain"
9
- }
10
-
11
- backend {
12
- address = var. backend_address
13
- name = " ngwaf_backend"
14
- port = 443
15
- use_ssl = true
16
- ssl_cert_hostname = var. backend_address
17
- ssl_sni_hostname = var. backend_address
18
- override_host = var. backend_address
19
- }
20
-
21
- # NGWAF Dynamic Snippets
22
- dynamicsnippet {
23
- name = " ngwaf_config_init"
24
- type = " init"
25
- priority = 0
26
- }
27
-
28
- dynamicsnippet {
29
- name = " ngwaf_config_miss"
30
- type = " miss"
31
- priority = 9000
32
- }
33
-
34
- dynamicsnippet {
35
- name = " ngwaf_config_pass"
36
- type = " pass"
37
- priority = 9000
38
- }
39
-
40
- dynamicsnippet {
41
- name = " ngwaf_config_deliver"
42
- type = " deliver"
43
- priority = 9000
44
- }
45
-
46
- dictionary {
47
- name = var. edge_security_dictionary
48
- }
49
-
50
- product_enablement {
51
- bot_management = true
52
- }
53
-
54
- lifecycle {
55
- ignore_changes = [product_enablement ]
56
- }
57
- }
58
-
59
- output "ngwaf_service_id" {
60
- value = var. activate_ngwaf_service ? fastly_service_vcl. ngwaf_service [0 ]. id : null
61
- }
62
-
63
1
# Fastly Service Dictionary Items
64
2
resource "fastly_service_dictionary_items" "edge_security_dictionary_items" {
65
3
count = var. activate_ngwaf_service ? 1 : 0
66
- service_id = fastly_service_vcl. ngwaf_service [ 0 ] . id
67
- dictionary_id = [for d in fastly_service_vcl . ngwaf_service [ 0 ] . dictionary : d . dictionary_id if d . name == var . edge_security_dictionary ][ 0 ]
4
+ service_id = fastly_service_vcl. python_org . id
5
+ dictionary_id = one ( [for d in fastly_service_vcl . python_org . dictionary : d . dictionary_id if d . name == var . edge_security_dictionary ])
68
6
items = {
69
7
Enabled : " 100"
70
8
}
71
9
}
72
10
73
11
# Fastly Service Dynamic Snippet Contents
74
- resource "fastly_service_dynamic_snippet_content" "ngwaf_config_init" {
75
- count = var. activate_ngwaf_service ? 1 : 0
76
- service_id = fastly_service_vcl. ngwaf_service [0 ]. id
77
- snippet_id = [for d in fastly_service_vcl . ngwaf_service [0 ]. dynamicsnippet : d . snippet_id if d . name == " ngwaf_config_init" ][0 ]
78
- content = " ### Fastly managed ngwaf_config_init"
79
- manage_snippets = false
80
- }
81
-
82
- resource "fastly_service_dynamic_snippet_content" "ngwaf_config_miss" {
83
- count = var. activate_ngwaf_service ? 1 : 0
84
- service_id = fastly_service_vcl. ngwaf_service [0 ]. id
85
- snippet_id = [for d in fastly_service_vcl . ngwaf_service [0 ]. dynamicsnippet : d . snippet_id if d . name == " ngwaf_config_miss" ][0 ]
86
- content = " ### Fastly managed ngwaf_config_miss"
87
- manage_snippets = false
88
- }
89
-
90
- resource "fastly_service_dynamic_snippet_content" "ngwaf_config_pass" {
91
- count = var. activate_ngwaf_service ? 1 : 0
92
- service_id = fastly_service_vcl. ngwaf_service [0 ]. id
93
- snippet_id = [for d in fastly_service_vcl . ngwaf_service [0 ]. dynamicsnippet : d . snippet_id if d . name == " ngwaf_config_pass" ][0 ]
94
- content = " ### Fastly managed ngwaf_config_pass"
95
- manage_snippets = false
96
- }
97
-
98
- resource "fastly_service_dynamic_snippet_content" "ngwaf_config_deliver" {
99
- count = var. activate_ngwaf_service ? 1 : 0
100
- service_id = fastly_service_vcl. ngwaf_service [0 ]. id
101
- snippet_id = [for d in fastly_service_vcl . ngwaf_service [0 ]. dynamicsnippet : d . snippet_id if d . name == " ngwaf_config_deliver" ][0 ]
102
- content = " ### Fastly managed ngwaf_config_deliver"
12
+ resource "fastly_service_dynamic_snippet_content" "ngwaf_config_snippets" {
13
+ for_each = var. activate_ngwaf_service ? toset ([" init" , " miss" , " pass" , " deliver" ]) : []
14
+ service_id = fastly_service_vcl. python_org . id
15
+ snippet_id = one ([for d in fastly_service_vcl . python_org . dynamicsnippet : d . snippet_id if d . name == " ngwaf_config_${ each . key } " ])
16
+ content = " ### Terraform managed ngwaf_config_${ each . key } "
103
17
manage_snippets = false
104
18
}
105
19
@@ -114,26 +28,23 @@ resource "sigsci_edge_deployment_service" "ngwaf_edge_service_link" {
114
28
count = var. activate_ngwaf_service ? 1 : 0
115
29
provider = sigsci. firewall
116
30
site_short_name = var. ngwaf_site_name
117
- fastly_sid = fastly_service_vcl. ngwaf_service [ 0 ] . id
118
- activate_version = var . activate_ngwaf_service
31
+ fastly_sid = fastly_service_vcl. python_org . id
32
+ activate_version = true
119
33
percent_enabled = 100
120
34
depends_on = [
121
35
sigsci_edge_deployment . ngwaf_edge_site_service ,
122
- fastly_service_vcl . ngwaf_service ,
36
+ fastly_service_vcl . python_org ,
123
37
fastly_service_dictionary_items . edge_security_dictionary_items ,
124
- fastly_service_dynamic_snippet_content . ngwaf_config_init ,
125
- fastly_service_dynamic_snippet_content . ngwaf_config_miss ,
126
- fastly_service_dynamic_snippet_content . ngwaf_config_pass ,
127
- fastly_service_dynamic_snippet_content . ngwaf_config_deliver ,
38
+ fastly_service_dynamic_snippet_content . ngwaf_config_snippets ,
128
39
]
129
40
}
130
41
131
42
resource "sigsci_edge_deployment_service_backend" "ngwaf_edge_service_backend_sync" {
132
43
count = var. activate_ngwaf_service ? 1 : 0
133
44
provider = sigsci. firewall
134
45
site_short_name = var. ngwaf_site_name
135
- fastly_sid = fastly_service_vcl. ngwaf_service [ 0 ] . id
136
- fastly_service_vcl_active_version = fastly_service_vcl. ngwaf_service [ 0 ] . active_version
46
+ fastly_sid = fastly_service_vcl. python_org . id
47
+ fastly_service_vcl_active_version = fastly_service_vcl. python_org . active_version
137
48
depends_on = [
138
49
sigsci_edge_deployment_service . ngwaf_edge_service_link ,
139
50
]
0 commit comments