Skip to content
Docs

    Create Firewall Rule

    client.Networking.FirewallRules.New(ctx, vpcID, body) (*Operation, error)
    POST/v1/networking/vpcs/{vpc_id}/firewall_rules

    Create a firewall rule

    ParametersExpand Collapse
    vpcID string
    body FirewallRuleNewParams
    DestinationAddress param.Field[string]

    Destination address of the Firewall Rule. Either VPC CIDR or VM in VPC. Must be in network-aligned/canonical form.

    DestinationPorts param.Field[[]string]

    Destination ports of the Firewall Rule.

    Name param.Field[string]

    Name of the Firewall Rule.

    Protocol param.Field[FirewallRuleNewParamsProtocol]

    Protocol of the Firewall Rule.

    const FirewallRuleNewParamsProtocolTcp FirewallRuleNewParamsProtocol = "tcp"
    const FirewallRuleNewParamsProtocolUdp FirewallRuleNewParamsProtocol = "udp"
    SourceAddress param.Field[string]

    Source address of the Firewall Rule. Address of 0.0.0.0 requires a CIDR mask of 0. Must be in network-aligned/canonical form.

    Tags param.Field[[]string]Optional

    Tags to attach to the Firewall Rule.

    ReturnsExpand Collapse
    type Operation struct{…}

    Operation details.

    ID string

    Unique identifier for the Operation.

    CreatedAt Time

    When the Operation was created.

    formatdate-time

    Structured details about what an operation is changing.

    Map of changed field names to their from/to diffs. Keys depend on the parent operation’s kind+type.

    From OperationFieldDiffFromUnion

    Previous value.

    One of the following:
    string
    float64
    bool
    type OperationFieldDiffFromArray []string
    To OperationFieldDiffToUnion

    New value.

    One of the following:
    string
    float64
    bool
    type OperationFieldDiffToArray []string

    Kind of Operation.

    One of the following:
    const OperationKindVM OperationKind = "vm"
    const OperationKindVolume OperationKind = "volume"
    const OperationKindVPC OperationKind = "vpc"
    const OperationKindFirewallRule OperationKind = "firewall_rule"
    const OperationKindNKSCluster OperationKind = "nks_cluster"
    const OperationKindNKSNodePool OperationKind = "nks_node_pool"
    ProjectID string

    Project ID the Operation belongs to.

    ResourceID string

    ID of the resource that the Operation is acting on.

    Status of the Operation.

    One of the following:
    const OperationStatusPending OperationStatus = "pending"
    const OperationStatusRunning OperationStatus = "running"
    const OperationStatusDone OperationStatus = "done"
    const OperationStatusFailed OperationStatus = "failed"
    const OperationStatusUnknown OperationStatus = "unknown"

    Type of Operation.

    One of the following:
    const OperationTypeCreate OperationType = "create"
    const OperationTypeUpdate OperationType = "update"
    const OperationTypeDelete OperationType = "delete"
    const OperationTypeRestart OperationType = "restart"
    UpdatedAt Time

    When the Operation was updated.

    formatdate-time

    Create Firewall Rule

    package main
    
    import (
      "context"
      "fmt"
    
      "github.com/nirvana-labs/nirvana-go"
      "github.com/nirvana-labs/nirvana-go/networking"
      "github.com/nirvana-labs/nirvana-go/option"
    )
    
    func main() {
      client := nirvana.NewClient(
        option.WithAPIKey("My API Key"),
      )
      operation, err := client.Networking.FirewallRules.New(
        context.TODO(),
        "vpc_id",
        networking.FirewallRuleNewParams{
          DestinationAddress: "10.0.0.0/25",
          DestinationPorts: []string{"22", "80", "443"},
          Name: "my-firewall-rule",
          Protocol: networking.FirewallRuleNewParamsProtocolTcp,
          SourceAddress: "0.0.0.0/0",
        },
      )
      if err != nil {
        panic(err.Error())
      }
      fmt.Printf("%+v\n", operation.ID)
    }
    
    {
      "id": "123e4567-e89b-12d3-a456-426614174000",
      "created_at": "2025-01-01T00:00:00Z",
      "details": {
        "changes": {
          "foo": {
            "from": "string",
            "to": "string"
          }
        }
      },
      "kind": "vm",
      "project_id": "123e4567-e89b-12d3-a456-426614174000",
      "resource_id": "123e4567-e89b-12d3-a456-426614174000",
      "status": "pending",
      "type": "create",
      "updated_at": "2025-01-01T00:00:00Z"
    }
    Returns Examples
    {
      "id": "123e4567-e89b-12d3-a456-426614174000",
      "created_at": "2025-01-01T00:00:00Z",
      "details": {
        "changes": {
          "foo": {
            "from": "string",
            "to": "string"
          }
        }
      },
      "kind": "vm",
      "project_id": "123e4567-e89b-12d3-a456-426614174000",
      "resource_id": "123e4567-e89b-12d3-a456-426614174000",
      "status": "pending",
      "type": "create",
      "updated_at": "2025-01-01T00:00:00Z"
    }