Firewalls

Create a Firewall

Create a Firewall.

Operation specific errors

StatusCodeDescription
422server_already_addedThe Server was applied more than once.
422incompatible_network_typeThe resources network type is not supported by Firewalls.
422firewall_resource_not_foundThe resource the Firewall should be attached to was not found.
post/firewalls

Request

  • Base URL: https://api.hetzner.cloud/v1
  • URL: https://api.hetzner.cloud/v1/firewalls
  • Auth: HTTP bearer

Request body

namestring required

Name of the Firewall.

Must be unique per Project.

labelsobject

User-defined labels (key/value pairs) for the Resource. For more information, see "Labels".

Example request

{
  "name": "new-name",
  "labels": {
    "environment": "prod",
    "example.com/my": "label",
    "just-a-key": ""
  },
  "rules": [
    {
      "direction": "in",
      "source_ips": [
        "192.0.2.2/32",
        "192.0.2.0/24",
        "2001:0db8:9a3b:ee58:5ca:990c:8bc9:c03b/128"
      ],
      "protocol": "tcp",
      "port": "80"
    }
  ],
  "apply_to": [
    {
      "label_selector": {
        "selector": "env=prod"
      }
    }
  ]
}

Response

Request succeeded.

Example response

{
  "firewall": {
    "id": 42,
    "name": "new-name",
    "labels": {
      "environment": "prod",
      "example.com/my": "label",
      "just-a-key": ""
    },
    "created": "2016-01-30T23:55:00Z",
    "rules": [
      {
        "direction": "in",
        "source_ips": [
          "192.0.2.2/32",
          "192.0.2.0/24",
          "2001:0db8:9a3b:ee58:5ca:990c:8bc9:c03b/128"
        ],
        "destination_ips": [],
        "port": "80"
      }
    ],
    "applied_to": [
      {
        "type": "server",
        "server": {
          "id": 42
        },
        "label_selector": {
          "selector": "env=prod"
        },
        "applied_to_resources": [
          {
            "type": "server",
            "server": {
              "id": 42
            }
          }
        ]
      }
    ]
  },
  "actions": [
    {
      "id": 13,
      "command": "set_firewall_rules",
      "status": "success",
      "progress": 100,
      "started": "2016-01-30T23:55:00Z",
      "finished": "2016-01-30T23:56:00Z",
      "resources": [
        {
          "id": 38,
          "type": "firewall"
        }
      ],
      "error": {
        "code": "action_failed",
        "message": "Action failed"
      }
    },
    {
      "id": 14,
      "command": "apply_firewall",
      "status": "success",
      "progress": 100,
      "started": "2016-01-30T23:55:00Z",
      "finished": "2016-01-30T23:56:00Z",
      "resources": [
        {
          "id": 42,
          "type": "server"
        },
        {
          "id": 38,
          "type": "firewall"
        }
      ],
      "error": {
        "code": "action_failed",
        "message": "Action failed"
      }
    }
  ]
}

Changes

No recorded changes to this operation across all 1 revision of this API.