Add Firewall Rule to Virtual Machine
POST https://infrahub-api.nexgencloud.com/v1/core/virtual-machines/{id}/sg-rules
Creates a firewall rule and applies it to a virtual machine. Include the virtual machine ID in the path, and provide the firewall rule configuration in the request body, as detailed below. For additional information on firewall rules, click here.
Path parameters
id integer
Required
The ID of the virtual machine for which a firewall rule is being created.
Request body parameters
direction string
Required
The direction of traffic that the firewall rule applies to.
Possible values: one of ingress
(incoming traffic) or egress
(outgoing traffic).
protocol string
Required
The network protocol associated with the rule.
Possible values: Any one of the protocol
values retrieved by calling the GET /core/sg-rules-protocols
endpoint.
ethertype string
Required
The Ethernet type associated with the rule.
Possible values: one of IPv4
or IPv6
.
remote_ip_prefix string
Required
The IP address range that is allowed to access the specified port.
port_range_min integer
optional
The minimum port number in the range of ports to be allowed by the firewall rule. Values 1-65535 are accepted.
Exclude the port_range_min
and port_range_max
fields from the body of the request to allow all ports.
port_range_max integer
optional
The maximum port number in the range of ports to be allowed by the firewall rule. Values 1-65535 are accepted.
Exclude the port_range_min
and port_range_max
fields from the body of the request to allow all ports.
Attributes
status boolean
Indicates the result of the request to create virtual machines. true
signifies success, while false
indicates an error.
message string
A description of the status of the request.
security_rule object
Provides the firewall rule configuration that was sent in the request, along with additional information such as the time of rule creation, rule ID, and the status
of the firewall rule that was created.
curl -X POST "https://infrahub-api.nexgencloud.com/v1/core/virtual-machines/{id}/sg-rules" \
-H "accept: application/json"\
-H "api_key: YOUR API KEY"\
-H "content-type: application/json" \
-d '{
"direction": "string",
"protocol": "string",
"ethertype": "string",
"remote_ip_prefix": "string"
"port_range_min": 0,
"port_range_max": 0,
}'
{
"status": true,
"message": "string",
"security_rule": {
"id": 0,
"direction": "string",
"protocol": "string",
"port_range_min": 0,
"port_range_max": 0,
"ethertype": "string",
"remote_ip_prefix": "string",
"status": "SUCCESS",
"created_at": "2023-12-18T18:45:28.137Z"
}
}
Returns
Returns the configuration of the firewall rule that was sent in the request with additional information: time of rule creation, rule ID, and the status
of the firewall rule being created. A security_rule_status
value of SUCCESS
indicates the firewall rule has been applied to the VM successfully.