Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/flaconi/terraform-cloudflare-firewall

Terraform module for Cloudflare firewall rules
https://github.com/flaconi/terraform-cloudflare-firewall

cloudflare terraform terraform-module

Last synced: about 4 hours ago
JSON representation

Terraform module for Cloudflare firewall rules

Awesome Lists containing this project

README

        

# Terraform module: Cloudflare Firewall rules

[![lint](https://github.com/flaconi/terraform-cloudflare-firewall/workflows/lint/badge.svg)](https://github.com/flaconi/terraform-cloudflare-firewall/actions?query=workflow%3Alint)
[![test](https://github.com/flaconi/terraform-cloudflare-firewall/workflows/test/badge.svg)](https://github.com/flaconi/terraform-cloudflare-firewall/actions?query=workflow%3Atest)
[![Tag](https://img.shields.io/github/tag/flaconi/terraform-cloudflare-firewall.svg)](https://github.com/flaconi/terraform-cloudflare-firewall/releases)
[![Terraform](https://img.shields.io/badge/Terraform--registry-cloudflare--firewall-brightgreen.svg)](https://registry.terraform.io/modules/flaconi/firewall/cloudflare/)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)

This Terraform module manages Cloudflare Firewall rules to its full extend (even for Enterprise customers).

## Behaviour

When deleting Cloudflare firewall rules and recreating them with the same expression, Terraform is too fast for the Cloudflare API and will fail with an error, that the rule already exists.

To overcome this limitation, all rules in this module are indexed by their corresponding firewall expression (see [locals.tf](locals.tf)). Firewall expressions must be unique in Cloudflare anyway, so the index will never duplicate.
This also means that whenever the expression changes, the rule will be recreated. Changes in all other values will not trigger a recreated.

## Priority of rules

This module omits the `priority` key for rulesets and auto-calculates those by the order they appear in the `rules` list.

## Example

`terraform.tfvars`:
```hcl
domain = "domain.tld"

rules = [
{
description = "Test (WAF Bypass)"
paused = false
action = "bypass"
expression = "(http.user_agent contains \"UA-TEST/\" and ip.src eq 1.2.3.4 and http.request.uri.path eq \"/api/endpoint\")"
products = ["waf"]
},
{
description = "Test"
paused = false
action = "allow"
expression = "(http.user_agent contains \"UA-TEST1\" and ip.src eq 1.2.3.4 and http.request.uri.path eq \"/api/endpoint\")"
products = []
},
]
```

## Providers

| Name | Version |
|------|---------|
| [cloudflare](#provider\_cloudflare) | ~> 4.29 |

## Requirements

| Name | Version |
|------|---------|
| [terraform](#requirement\_terraform) | >= 1.5 |
| [cloudflare](#requirement\_cloudflare) | ~> 4.29 |

## Required Inputs

The following input variables are required:

### [api\_token](#input\_api\_token)

Description: The Cloudflare API token.

Type: `string`

### [domain](#input\_domain)

Description: Cloudflare domain to apply rules for.

Type: `string`

## Optional Inputs

The following input variables are optional (have default values):

### [rules](#input\_rules)

Description: List of Cloudflare firewall rule objects.

Type:

```hcl
list(object({
description = string
enabled = bool
action = string
expression = string
products = list(string)
}))
```

Default: `[]`

## Outputs

| Name | Description |
|------|-------------|
| [domain](#output\_domain) | Current zone information. |
| [rules](#output\_rules) | Created Cloudflare rules for the current zone. |

## License

**[MIT License](LICENSE)**

Copyright (c) 2021 **[flaconi](https://github.com/flaconi)**