Skip to content

Commit

Permalink
feat: Added a new waf module (in the modules folder). NOTE: This re…
Browse files Browse the repository at this point in the history
…lease only allows user to enable/disable the web application firewall(WAF) protection as domain settings with the default rules and we are not setting/updating any WAF rule. (#410)
  • Loading branch information
iamar7 authored Nov 29, 2023
1 parent fd102c8 commit d06d7a6
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This module provisions an IBM Cloud Internet Services (CIS) instance and configu
* Domain
* DNS records
* Global load balancer (GLB) including load balancers, origin pools and health checks
* Web Application Firewall (WAF)

For more information see, [Getting started with IBM Cloud Internet Services](https://cloud.ibm.com/docs/cis?topic=cis-getting-started).

Expand All @@ -22,6 +23,7 @@ For more information see, [Getting started with IBM Cloud Internet Services](htt
* [dns](./modules/dns)
* [domain](./modules/domain)
* [glb](./modules/glb)
* [waf](./modules/waf)
* [Examples](./examples)
* [End-to-end example](./examples/complete)
* [Contributing](#contributing)
Expand Down
11 changes: 11 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,14 @@ module "cis_glb" {
}
]
}

##############################################################################
# Enables web application firewall(WAF) to CIS instance
##############################################################################

module "cis_domain_settings" {
source = "../../modules/waf"
cis_instance_id = module.cis_instance.cis_instance_id
domain_id = module.cis_instance.cis_domain.domain_id
enable_waf = true
}
5 changes: 5 additions & 0 deletions examples/complete/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ output "cis_glb" {
description = "CIS Global Load Balancer"
value = module.cis_glb
}

output "cis_domain_settings" {
description = "CIS domain settings"
value = module.cis_domain_settings
}
36 changes: 36 additions & 0 deletions modules/waf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# CIS web application firewall (WAF) module

This module enables/disables the web application firewall (WAF) of the domain.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
### Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0, <1.6.0 |
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.49.0 |

### Modules

No modules.

### Resources

| Name | Type |
|------|------|
| [ibm_cis_domain_settings.domain_settings](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/cis_domain_settings) | resource |

### Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_cis_instance_id"></a> [cis\_instance\_id](#input\_cis\_instance\_id) | CRN of the existing CIS instance. | `string` | n/a | yes |
| <a name="input_domain_id"></a> [domain\_id](#input\_domain\_id) | ID of the existing domain to add a DNS record to the CIS instance. | `string` | n/a | yes |
| <a name="input_enable_waf"></a> [enable\_waf](#input\_enable\_waf) | To control whether the web application firewall (WAF) is enabled or disabled for a CIS instance. | `bool` | n/a | yes |

### Outputs

| Name | Description |
|------|-------------|
| <a name="output_cis_domain_settings_details"></a> [cis\_domain\_settings\_details](#output\_cis\_domain\_settings\_details) | CIS Domain settings details |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
10 changes: 10 additions & 0 deletions modules/waf/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
##############################################################################
# To enable/disable Web Application Firewall(WAF) for a domain
##############################################################################

resource "ibm_cis_domain_settings" "domain_settings" {
cis_id = var.cis_instance_id
domain_id = var.domain_id
waf = var.enable_waf ? "on" : "off"
min_tls_version = "1.2" #Temporary fix - The min_tls_version default value (1.2) gets modified to 1.1 while applying domain_settings. This will be reverted back once the provider issue(IBM-Cloud/terraform-provider-ibm#4937) is fixed.
}
5 changes: 5 additions & 0 deletions modules/waf/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

output "cis_domain_settings_details" {
description = "CIS Domain settings details"
value = ibm_cis_domain_settings.domain_settings
}
15 changes: 15 additions & 0 deletions modules/waf/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

variable "cis_instance_id" {
type = string
description = "CRN of the existing CIS instance."
}

variable "domain_id" {
type = string
description = "ID of the existing domain to add a DNS record to the CIS instance."
}

variable "enable_waf" {
type = bool
description = "To control whether the web application firewall (WAF) is enabled or disabled for a CIS instance."
}
10 changes: 10 additions & 0 deletions modules/waf/version.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

terraform {
required_version = ">= 1.3.0, <1.6.0"
required_providers {
ibm = {
source = "IBM-Cloud/ibm"
version = ">= 1.49.0"
}
}
}

0 comments on commit d06d7a6

Please sign in to comment.