> For the complete documentation index, see [llms.txt](https://docs.ionos.com/ansible/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ionos.com/ansible/api/nat-gateway/modules/nat_gateway_rule.md).

# NAT Gateway rule

## nat\_gateway\_rule

This is a simple module that supports creating or removing NATGateway rules. This module has a dependency on ionoscloud >= 6.0.2

### Example Syntax

```yaml

name: Create NAT Gateway Rule
ionoscloudsdk.ionoscloud.nat_gateway_rule:
  datacenter: ''
  nat_gateway: ''
  name: 'AnsibleAutoTestNAT'
  type: SNAT
  protocol: TCP
  source_subnet: 10.0.1.0/24
  target_subnet: 10.0.1.0
  target_port_range:
    start: 10000
    end: 20000
  public_ip: ''
  wait: true
register: nat_gateway_rule_response


name: Update NAT Gateway Rule
ionoscloudsdk.ionoscloud.nat_gateway_rule:
  datacenter: ''
  nat_gateway: ''
  nat_gateway_rule: ''
  public_ip: ''
  name: 'AnsibleAutoTestNAT - UPDATED'
  type: SNAT
  protocol: TCP
  source_subnet: 10.0.1.0/24
  wait: true
  state: update
register: nat_gateway_rule_update_response


name: Delete NAT Gateway Rule
ionoscloudsdk.ionoscloud.nat_gateway_rule:
  datacenter: ''
  nat_gateway: ''
  nat_gateway_rule: ''
  state: absent

```

&#x20; &#x20;

### Returned object

```json
{
    "changed": true,
    "failed": false,
    "action": "create",
    "nat_gateway_rule": {
        "href": "https://api.ionos.com/cloudapi/v6/datacenters/0406692b-b25f-4a58-8b41-e3b2d761447c/natgateways/abcc8593-a4a9-4ea0-b63c-04f95f395aa0/rules/42c85463-5b4f-485e-9e97-47dadc6d37ef",
        "id": "42c85463-5b4f-485e-9e97-47dadc6d37ef",
        "metadata": {
            "created_by": "<USER_EMAIL>",
            "created_by_user_id": "<USER_ID>",
            "created_date": "2023-05-31T11:53:14+00:00",
            "etag": "a0caa44599f8ef081cc93343a66c6738",
            "last_modified_by": "<USER_EMAIL>",
            "last_modified_by_user_id": "<USER_ID>",
            "last_modified_date": "2023-05-31T11:53:14+00:00",
            "state": "BUSY"
        },
        "properties": {
            "name": "AnsibleAutoTestNAT",
            "protocol": "TCP",
            "public_ip": "<IP1>",
            "source_subnet": "<SUBNET>",
            "target_port_range": {
                "end": 20000,
                "start": 10000
            },
            "target_subnet": "<SUBNET>",
            "type": "SNAT"
        },
        "type": "natgateway-rule"
    }
}

```

#### For more examples please check out the tests [here](https://github.com/ionos-cloud/module-ansible/tree/master/tests/natgateway).

&#x20;

&#x20;

## state: **present**

```yaml
  
name: Create NAT Gateway Rule
ionoscloudsdk.ionoscloud.nat_gateway_rule:
  datacenter: ''
  nat_gateway: ''
  name: 'AnsibleAutoTestNAT'
  type: SNAT
  protocol: TCP
  source_subnet: 10.0.1.0/24
  target_subnet: 10.0.1.0
  target_port_range:
    start: 10000
    end: 20000
  public_ip: ''
  wait: true
register: nat_gateway_rule_response

```

#### Available parameters for state **present**:

&#x20;

<table data-full-width="true"><thead><tr><th width="70">Name</th><th width="40" align="center">Required</th><th>Description</th></tr></thead><tbody><tr><td>name<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>The name of the NAT Gateway rule.</td></tr><tr><td>type<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>Type of the NAT Gateway rule.</td></tr><tr><td>protocol<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>Protocol of the NAT Gateway rule. Defaults to ALL. If protocol is 'ICMP' then targetPortRange start and end cannot be set.</td></tr><tr><td>source_subnet<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>Source subnet of the NAT Gateway rule. For SNAT rules it specifies which packets this translation rule applies to based on the packets source IP address.</td></tr><tr><td>public_ip<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>Public IP address of the NAT Gateway rule. Specifies the address used for masking outgoing packets source address field. Should be one of the customer reserved IP address already configured on the NAT Gateway resource</td></tr><tr><td>target_subnet<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>Target or destination subnet of the NAT Gateway rule. For SNAT rules it specifies which packets this translation rule applies to based on the packets destination IP address. If none is provided, rule will match any address.</td></tr><tr><td>target_port_range<br><mark style="color:blue;">dict</mark></td><td align="center">False</td><td>Target port range of the NAT Gateway rule. For SNAT rules it specifies which packets this translation rule applies to based on destination port. If none is provided, rule will match any port</td></tr><tr><td>datacenter<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>The ID or name of the datacenter.</td></tr><tr><td>nat_gateway<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>The ID or name of the NAT Gateway.</td></tr><tr><td>api_url<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos API base URL.</td></tr><tr><td>certificate_fingerprint<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos API certificate fingerprint.</td></tr><tr><td>username<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos username. Overrides the IONOS_USERNAME environment variable.</td></tr><tr><td>password<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos password. Overrides the IONOS_PASSWORD environment variable.</td></tr><tr><td>token<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos token. Overrides the IONOS_TOKEN environment variable.</td></tr><tr><td>wait<br><mark style="color:blue;">bool</mark></td><td align="center">False</td><td>Wait for the resource to be created before returning.<br>Default: True<br>Options: [True, False]</td></tr><tr><td>wait_timeout<br><mark style="color:blue;">int</mark></td><td align="center">False</td><td>How long before wait gives up, in seconds.<br>Default: 600</td></tr><tr><td>state<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>Indicate desired state of the resource.<br>Default: present<br>Options: ['present', 'absent', 'update']</td></tr></tbody></table>

&#x20;

&#x20;

## state: **absent**

```yaml
  
name: Delete NAT Gateway Rule
ionoscloudsdk.ionoscloud.nat_gateway_rule:
  datacenter: ''
  nat_gateway: ''
  nat_gateway_rule: ''
  state: absent

```

#### Available parameters for state **absent**:

&#x20;

<table data-full-width="true"><thead><tr><th width="70">Name</th><th width="40" align="center">Required</th><th>Description</th></tr></thead><tbody><tr><td>name<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The name of the NAT Gateway rule.</td></tr><tr><td>datacenter<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>The ID or name of the datacenter.</td></tr><tr><td>nat_gateway<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>The ID or name of the NAT Gateway.</td></tr><tr><td>nat_gateway_rule<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>The ID or name of the NAT Gateway rule.</td></tr><tr><td>api_url<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos API base URL.</td></tr><tr><td>certificate_fingerprint<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos API certificate fingerprint.</td></tr><tr><td>username<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos username. Overrides the IONOS_USERNAME environment variable.</td></tr><tr><td>password<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos password. Overrides the IONOS_PASSWORD environment variable.</td></tr><tr><td>token<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos token. Overrides the IONOS_TOKEN environment variable.</td></tr><tr><td>wait<br><mark style="color:blue;">bool</mark></td><td align="center">False</td><td>Wait for the resource to be created before returning.<br>Default: True<br>Options: [True, False]</td></tr><tr><td>wait_timeout<br><mark style="color:blue;">int</mark></td><td align="center">False</td><td>How long before wait gives up, in seconds.<br>Default: 600</td></tr><tr><td>state<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>Indicate desired state of the resource.<br>Default: present<br>Options: ['present', 'absent', 'update']</td></tr></tbody></table>

&#x20;

&#x20;

## state: **update**

```yaml
  
name: Update NAT Gateway Rule
ionoscloudsdk.ionoscloud.nat_gateway_rule:
  datacenter: ''
  nat_gateway: ''
  nat_gateway_rule: ''
  public_ip: ''
  name: 'AnsibleAutoTestNAT - UPDATED'
  type: SNAT
  protocol: TCP
  source_subnet: 10.0.1.0/24
  wait: true
  state: update
register: nat_gateway_rule_update_response

```

#### Available parameters for state **update**:

&#x20;

<table data-full-width="true"><thead><tr><th width="70">Name</th><th width="40" align="center">Required</th><th>Description</th></tr></thead><tbody><tr><td>name<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The name of the NAT Gateway rule.</td></tr><tr><td>type<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>Type of the NAT Gateway rule.</td></tr><tr><td>protocol<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>Protocol of the NAT Gateway rule. Defaults to ALL. If protocol is 'ICMP' then targetPortRange start and end cannot be set.</td></tr><tr><td>source_subnet<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>Source subnet of the NAT Gateway rule. For SNAT rules it specifies which packets this translation rule applies to based on the packets source IP address.</td></tr><tr><td>public_ip<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>Public IP address of the NAT Gateway rule. Specifies the address used for masking outgoing packets source address field. Should be one of the customer reserved IP address already configured on the NAT Gateway resource</td></tr><tr><td>target_subnet<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>Target or destination subnet of the NAT Gateway rule. For SNAT rules it specifies which packets this translation rule applies to based on the packets destination IP address. If none is provided, rule will match any address.</td></tr><tr><td>target_port_range<br><mark style="color:blue;">dict</mark></td><td align="center">False</td><td>Target port range of the NAT Gateway rule. For SNAT rules it specifies which packets this translation rule applies to based on destination port. If none is provided, rule will match any port</td></tr><tr><td>datacenter<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>The ID or name of the datacenter.</td></tr><tr><td>nat_gateway<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>The ID or name of the NAT Gateway.</td></tr><tr><td>nat_gateway_rule<br><mark style="color:blue;">str</mark></td><td align="center">True</td><td>The ID or name of the NAT Gateway rule.</td></tr><tr><td>api_url<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos API base URL.</td></tr><tr><td>certificate_fingerprint<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos API certificate fingerprint.</td></tr><tr><td>username<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos username. Overrides the IONOS_USERNAME environment variable.</td></tr><tr><td>password<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos password. Overrides the IONOS_PASSWORD environment variable.</td></tr><tr><td>token<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>The Ionos token. Overrides the IONOS_TOKEN environment variable.</td></tr><tr><td>wait<br><mark style="color:blue;">bool</mark></td><td align="center">False</td><td>Wait for the resource to be created before returning.<br>Default: True<br>Options: [True, False]</td></tr><tr><td>wait_timeout<br><mark style="color:blue;">int</mark></td><td align="center">False</td><td>How long before wait gives up, in seconds.<br>Default: 600</td></tr><tr><td>state<br><mark style="color:blue;">str</mark></td><td align="center">False</td><td>Indicate desired state of the resource.<br>Default: present<br>Options: ['present', 'absent', 'update']</td></tr></tbody></table>

&#x20;

&#x20;


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.ionos.com/ansible/api/nat-gateway/modules/nat_gateway_rule.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
