|
| 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 | +# Fastly Service Dictionary Items |
| 64 | +resource "fastly_service_dictionary_items" "edge_security_dictionary_items" { |
| 65 | + 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] |
| 68 | + items = { |
| 69 | + Enabled : "100" |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +# 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" |
| 103 | + manage_snippets = false |
| 104 | +} |
| 105 | + |
| 106 | +# NGWAF Edge Deployment on SignalSciences.net |
| 107 | +resource "sigsci_edge_deployment" "ngwaf_edge_site_service" { |
| 108 | + count = var.activate_ngwaf_service ? 1 : 0 |
| 109 | + provider = sigsci.firewall |
| 110 | + site_short_name = var.ngwaf_site_name |
| 111 | +} |
| 112 | + |
| 113 | +resource "sigsci_edge_deployment_service" "ngwaf_edge_service_link" { |
| 114 | + count = var.activate_ngwaf_service ? 1 : 0 |
| 115 | + provider = sigsci.firewall |
| 116 | + site_short_name = var.ngwaf_site_name |
| 117 | + fastly_sid = fastly_service_vcl.ngwaf_service[0].id |
| 118 | + activate_version = var.activate_ngwaf_service |
| 119 | + percent_enabled = 100 |
| 120 | + depends_on = [ |
| 121 | + sigsci_edge_deployment.ngwaf_edge_site_service, |
| 122 | + fastly_service_vcl.ngwaf_service, |
| 123 | + 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, |
| 128 | + ] |
| 129 | +} |
| 130 | + |
| 131 | +resource "sigsci_edge_deployment_service_backend" "ngwaf_edge_service_backend_sync" { |
| 132 | + count = var.activate_ngwaf_service ? 1 : 0 |
| 133 | + provider = sigsci.firewall |
| 134 | + 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 |
| 137 | + depends_on = [ |
| 138 | + sigsci_edge_deployment_service.ngwaf_edge_service_link, |
| 139 | + ] |
| 140 | +} |
0 commit comments