{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Firewall Rules",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "egress": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[a-z0-9_-]+$": {
          "$ref": "#/$defs/rule"
        }
      }
    },
    "ingress": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[a-z0-9_-]+$": {
          "$ref": "#/$defs/rule"
        }
      }
    }
  },
  "$defs": {
    "rule": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "deny": {
          "type": "boolean"
        },
        "description": {
          "type": "string"
        },
        "destination_ranges": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "disabled": {
          "type": "boolean"
        },
        "enable_logging": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "include_metadata": {
              "type": "boolean"
            }
          }
        },
        "priority": {
          "type": "number"
        },
        "source_ranges": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "sources": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "targets": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "use_service_accounts": {
          "type": "boolean"
        },
        "rules": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "protocol": {
                "type": "string"
              },
              "ports": {
                "type": "array",
                "items": {
                  "type": [
                    "integer",
                    "string"
                  ],
                  "pattern": "^[0-9]+(?:-[0-9]+)?$"
                }
              }
            }
          }
        }
      }
    }
  }
}
