create_dfw_rule
Create a distributed firewall rule under an existing NSX DFW security policy, specifying action, sources, destinations, and priority.
Instructions
[WRITE] Create a firewall rule under an existing DFW security policy.
Creates via PUT, so calling again with the same rule_id replaces that rule's definition. The rule is enforced on the NSX data plane immediately unless disabled=True. Pick the policy_id with list_dfw_policies first; to change selected fields of an existing rule prefer update_dfw_rule, and to remove one use delete_dfw_rule. Calls are pre-checked by the vmware-policy engine (risk level: medium) and audited to ~/.vmware/audit.db.
Returns the created rule dict from the NSX API (id, path, action, sequence_number, ...). On failure returns {"error", "hint"}; an invalid action/direction/ip_protocol returns an error listing the valid values.
Args: policy_id: Parent policy ID (alphanumeric and hyphens), as returned by list_dfw_policies. rule_id: Unique rule ID within the policy (alphanumeric and hyphens). Reusing an existing ID overwrites that rule. display_name: Human-readable rule name. action: Firewall action — ALLOW, DROP, REJECT, or JUMP_TO_APPLICATION (default: ALLOW). JUMP_TO_APPLICATION is only valid in policies whose category is Environment. sources: Source group policy paths, e.g. ['/infra/domains/default/groups/web']. Use ['ANY'] or omit for any source (default: ANY). destinations: Destination group policy paths, same format as sources. Use ['ANY'] or omit for any destination (default: ANY). services: Service policy paths, e.g. ['/infra/services/HTTPS']. Use ['ANY'] or omit for all services (default: ANY). scope: Applied-to group/segment paths limiting where the rule is enforced. Omit to apply to the entire DFW. direction: Traffic direction — IN, OUT, or IN_OUT (default: IN_OUT). ip_protocol: IP version — IPV4, IPV6, or IPV4_IPV6 (default: IPV4_IPV6). logged: Log matched traffic (default: False). disabled: Create the rule disabled so it is not enforced (default: False). sequence_number: Rule priority within the policy; lower values match first (default: 10). description: Optional free-text description. target: Optional NSX Manager target name from config. Uses the default target if omitted.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| policy_id | Yes | ||
| rule_id | Yes | ||
| display_name | Yes | ||
| action | No | ALLOW | |
| sources | No | ||
| destinations | No | ||
| services | No | ||
| scope | No | ||
| direction | No | IN_OUT | |
| ip_protocol | No | IPV4_IPV6 | |
| logged | No | ||
| disabled | No | ||
| sequence_number | No | ||
| description | No | ||
| target | No |