|
| 1 | +/** |
| 2 | + * Copyright 2019 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +resource "google_compute_firewall" "rules" { |
| 18 | + for_each = { for r in var.rules : "${r.name}" => r } |
| 19 | + name = each.value.name |
| 20 | + description = each.value.description |
| 21 | + direction = each.value.direction |
| 22 | + network = var.network_name |
| 23 | + project = var.project_id |
| 24 | + source_ranges = each.value.direction == "INGRESS" ? each.value.ranges : null |
| 25 | + destination_ranges = each.value.direction == "EGRESS" ? each.value.ranges : null |
| 26 | + source_tags = each.value.source_tags |
| 27 | + source_service_accounts = each.value.source_service_accounts |
| 28 | + target_tags = each.value.target_tags |
| 29 | + target_service_accounts = each.value.target_service_accounts |
| 30 | + priority = each.value.priority |
| 31 | + |
| 32 | + dynamic "log_config" { |
| 33 | + for_each = lookup(each.value, "log_config") == null ? [] : [each.value.log_config] |
| 34 | + content { |
| 35 | + metadata = log_config.value.metadata |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + dynamic "allow" { |
| 40 | + for_each = lookup(each.value, "allow", []) |
| 41 | + content { |
| 42 | + protocol = allow.value.protocol |
| 43 | + ports = lookup(allow.value, "ports", null) |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + dynamic "deny" { |
| 48 | + for_each = lookup(each.value, "deny", []) |
| 49 | + content { |
| 50 | + protocol = deny.value.protocol |
| 51 | + ports = lookup(deny.value, "ports", null) |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments