Skip to content

Commit

Permalink
Improving the documentation for firewall resource (#326)
Browse files Browse the repository at this point in the history
Co-authored-by: Fernando Villalba <[email protected]>
  • Loading branch information
fernando-villalba and Fernando Villalba authored Aug 20, 2024
1 parent d47a094 commit fe53836
Showing 1 changed file with 79 additions and 33 deletions.
112 changes: 79 additions & 33 deletions docs/resources/firewall.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,47 @@ Provides a Civo firewall resource. This can be used to create, modify, and delet

## Example Usage

* View firewalls after creation on the [CLI](https://www.civo.com/docs/overview/civo-cli):
```
civo firewall ls
```
* View firewalls after creation on the [Dashboard](https://dashboard.civo.com/firewalls)
* View firewall rules on [CLI](https://www.civo.com/docs/overview/civo-cli):
```
civo firewall rule ls example-firewall
```

### Custom ingress and egress rules firewall


```terraform
# Create a network
resource "civo_network" "custom_net" {
label = "my-custom-network"
provider "civo" {
region = "LON1"
}
# Create a firewall
resource "civo_firewall" "www" {
name = "www"
network_id = civo_network.custom_net.id
}
# Create a firewall with the default rules
resource "civo_firewall" "www" {
name = "www"
network_id = civo_network.custom_net.id
create_default_rules = true
resource "civo_network" "example" {
label = "example-network"
}
# Create a firewall withouth the default rules but with a custom rule
resource "civo_firewall" "www" {
name = "www"
network_id = civo_network.custom_net.id
create_default_rules = false
resource "civo_firewall" "example" {
name = "example-firewall"
network_id = civo_network.example.id
create_default_rules = false # Needs to be false when custom rules are applied.
ingress_rule {
label = "k8s"
label = "http"
protocol = "tcp"
port_range = "6443"
cidr = ["192.168.1.1/32", "192.168.10.4/32", "192.168.10.10/32"]
port_range = "80"
cidr = ["0.0.0.0"]
action = "allow"
}
ingress_rule {
label = "https"
protocol = "tcp"
port_range = "443"
cidr = ["0.0.0.0"]
action = "allow"
}
Expand All @@ -60,29 +72,58 @@ resource "civo_firewall" "www" {
action = "allow"
}
}
data "civo_disk_image" "debian" {
filter {
key = "name"
values = ["debian-10"]
}
}
# Create a new instance
resource "civo_instance" "example" {
hostname = "example"
notes = "This is an example instance"
firewall_id = civo_firewall.example.id
network_id = civo_network.example.id
size = "g3.xsmall"
disk_image = data.civo_disk_image.debian.diskimages[0].id
}
```

### Simple firewall

This the minimum amount of code to create a firewall with default rules:

```terraform
# ...
resource "civo_firewall" "example" {
name = "example-firewall"
network_id = civo_network.example.id
}
```

<!-- schema generated by tfplugindocs -->
## Schema


## Argument Reference

### Required

- `name` (String) The firewall name

### Optional

- `create_default_rules` (Boolean) The create rules flag is used to create the default firewall rules, if is not defined will be set to true, and if you set to false you need to define at least one ingress or egress rule
- `create_default_rules` (Boolean) The create rules flag is used to create the default firewall rules, if is not defined will be set to true, and if you set to false you need to define at least one ingress or egress rule. Needs to be false if custom rules are set.
- `egress_rule` (Block Set) The egress rules, this is a list of rules that will be applied to the firewall (see [below for nested schema](#nestedblock--egress_rule))
- `ingress_rule` (Block Set) The ingress rules, this is a list of rules that will be applied to the firewall (see [below for nested schema](#nestedblock--ingress_rule))
- `network_id` (String) The firewall network, if is not defined we use the default network
- `region` (String) The firewall region, if is not defined we use the global defined in the provider

### Read-Only

- `id` (String) The ID of this resource.

<a id="nestedblock--egress_rule"></a>
### Nested Schema for `egress_rule`
<a id="nestedblock--ingress_rule"></a>
### Nested Schema for `ingress_rule`

Required:

Expand All @@ -99,9 +140,8 @@ Read-Only:

- `id` (String) The ID of the firewall rule. This is only set when the rule is created by terraform.


<a id="nestedblock--ingress_rule"></a>
### Nested Schema for `ingress_rule`
<a id="nestedblock--egress_rule"></a>
### Nested Schema for `egress_rule`

Required:

Expand All @@ -118,6 +158,12 @@ Read-Only:

- `id` (String) The ID of the firewall rule. This is only set when the rule is created by terraform.


## Attributes Reference

- `id` (String) The ID of this resource.


## Import

Import is supported using the following syntax:
Expand Down

0 comments on commit fe53836

Please sign in to comment.