# ionoscloud\_natgateway\_rule

The **NAT Gateway Rule data source** can be used to search for and return existing NAT Gateway Rules. If a single match is found, it will be returned. If your search results in multiple matches, an error will be returned. When this happens, please refine your search string so that it is specific enough to return only one result.

## Example Usage

### By ID

```hcl
data "ionoscloud_natgateway_rule" "example" {
  datacenter_id = "datacenter_id"
  natgateway_id = "natgateway_id"
  id			= "natgateway_rule_id"
}
```

### By Name

```hcl
data "ionoscloud_natgateway_rule" "example" {
  datacenter_id = "datacenter_id"
  natgateway_id = "natgateway_id"
  name			= "NAT Gateway Rule Example"
}
```

## Argument Reference

* `datacenter_id` - (Required) Datacenter's UUID.
* `natgateway_id` - (Required) Nat Gateway's UUID.
* `name` - (Optional) Name of an existing NAT gateway rule that you want to search for.
* `id` - (Optional) ID of the NAT gateway rule you want to search for.

Both `datacenter_id` and `natgateway_id` and either `name` or `id` must be provided. If none, or both of `name` and `id` are provided, the datasource will return an error.

## Attributes Reference

The following attributes are returned by the datasource:

* `id` - Id of the NAT gateway rule
* `name` - Name of the NAT gateway rule
* `type` - ype of the NAT gateway rule.
* `protocol` - Protocol of the NAT gateway rule. Defaults to ALL. If protocol is 'ICMP' then targetPortRange start and end cannot be set.
* `source_subnet` - 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.
* `public_ip` - 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
* `target_subnet` - 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.
* `target_port_range` - 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
  * `start`
  * `end`


---

# Agent Instructions: 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:

```
GET https://docs.ionos.com/terraform-provider/data-sources/natgateway_rule.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
