- 
                Notifications
    You must be signed in to change notification settings 
- Fork 6
WAF policy resource, managed WAF rulesets data source, and waf_policy_id in build settings #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
  
     Merged
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -2,6 +2,7 @@ | |
| /swagger_go.json | ||
| /.env | ||
| *.out | ||
| /waf | ||
|  | ||
| *.dll | ||
| *.exe | ||
|  | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| --- | ||
| # generated by https://github.com/hashicorp/terraform-plugin-docs | ||
| page_title: "netlify_managed_waf_rules Data Source - netlify" | ||
| subcategory: "" | ||
| description: |- | ||
| Netlify managed WAF rule sets. This should be used when defining a WAF policy (netlify_waf_policy). | ||
| --- | ||
|  | ||
| # netlify_managed_waf_rules (Data Source) | ||
|  | ||
| Netlify managed WAF rule sets. This should be used when defining a WAF policy (netlify_waf_policy). | ||
|  | ||
| ## Example Usage | ||
|  | ||
| ```terraform | ||
| # Read-only definitions of all managed WAF rules available in Netlify. | ||
| # The team ID is required to query the rules. | ||
| data "netlify_managed_waf_rules" "example" { | ||
| team_id = "6600abcdef1234567890abcd" | ||
| } | ||
| ``` | ||
|  | ||
| <!-- schema generated by tfplugindocs --> | ||
| ## Schema | ||
|  | ||
| ### Required | ||
|  | ||
| - `team_id` (String) | ||
|  | ||
| ### Read-Only | ||
|  | ||
| - `rule_sets` (Attributes Map) (see [below for nested schema](#nestedatt--rule_sets)) | ||
|  | ||
| <a id="nestedatt--rule_sets"></a> | ||
| ### Nested Schema for `rule_sets` | ||
|  | ||
| Read-Only: | ||
|  | ||
| - `definition` (Attributes) (see [below for nested schema](#nestedatt--rule_sets--definition)) | ||
| - `rules` (Attributes List) (see [below for nested schema](#nestedatt--rule_sets--rules)) | ||
|  | ||
| <a id="nestedatt--rule_sets--definition"></a> | ||
| ### Nested Schema for `rule_sets.definition` | ||
|  | ||
| Read-Only: | ||
|  | ||
| - `id` (String) | ||
| - `type` (String) | ||
| - `version` (String) | ||
|  | ||
|  | ||
| <a id="nestedatt--rule_sets--rules"></a> | ||
| ### Nested Schema for `rule_sets.rules` | ||
|  | ||
| Read-Only: | ||
|  | ||
| - `category` (String) | ||
| - `description` (String) | ||
| - `id` (String) | ||
| - `phase` (String) | ||
| - `severity` (String) notice, warning, error, critical | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| --- | ||
| # generated by https://github.com/hashicorp/terraform-plugin-docs | ||
| page_title: "netlify_waf_policy Resource - netlify" | ||
| subcategory: "" | ||
| description: |- | ||
| Netlify Web Application Firewall (WAF) policy. Read more https://docs.netlify.com/security/secure-access-to-sites/web-application-firewall/ | ||
| --- | ||
|  | ||
| # netlify_waf_policy (Resource) | ||
|  | ||
| Netlify Web Application Firewall (WAF) policy. [Read more](https://docs.netlify.com/security/secure-access-to-sites/web-application-firewall/) | ||
|  | ||
| ## Example Usage | ||
|  | ||
| ```terraform | ||
| resource "netlify_waf_policy" "example" { | ||
| team_id = data.netlify_team.team.id | ||
| name = "Terraform Policy" | ||
| description = "This is a test policy through Terraform" | ||
| rule_sets = [ | ||
| { | ||
| managed_id = "crs-basic", | ||
| passive_mode = true, | ||
| overall_threshold = 5, | ||
| category_thresholds = { | ||
| "fixation" = 8, | ||
| }, | ||
| rule_overrides = { | ||
| "920100" = { | ||
| action = "log_only" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } | ||
|  | ||
| # To use this policy in a site, use the netlify_site_build_settings resource: | ||
|  | ||
| resource "netlify_site_build_settings" "example" { | ||
| # other attributes... | ||
| waf_policy_id = netlify_waf_policy.example.id | ||
| } | ||
|  | ||
| # To dynamically define the rule overrides, you can query netlify_managed_waf_rules to get the rule IDs: | ||
|  | ||
| data "netlify_managed_waf_rules" "example" { | ||
| team_id = "6600abcdef1234567890abcd" | ||
| } | ||
|  | ||
| resource "netlify_waf_policy" "example" { | ||
| team_id = "66ae34e11a567e9092e3850f" | ||
| name = "Terraform Policy" | ||
| description = "This is a test policy through Terraform" | ||
| rule_sets = [ | ||
| { | ||
| managed_id = "crs-basic", | ||
| passive_mode = true, | ||
| overall_threshold = 5, | ||
| rule_overrides = { | ||
| for rule in data.netlify_managed_waf_rules.example.rule_sets["crs-basic"].rules : rule.id => { | ||
| action = "log_only" | ||
| } if rule.category == "rce" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|  | ||
| <!-- schema generated by tfplugindocs --> | ||
| ## Schema | ||
|  | ||
| ### Required | ||
|  | ||
| - `description` (String) | ||
| - `name` (String) | ||
| - `rule_sets` (Attributes List) (see [below for nested schema](#nestedatt--rule_sets)) | ||
| - `team_id` (String) | ||
|  | ||
| ### Read-Only | ||
|  | ||
| - `id` (String) The ID of this resource. | ||
| - `last_updated` (String) | ||
|  | ||
| <a id="nestedatt--rule_sets"></a> | ||
| ### Nested Schema for `rule_sets` | ||
|  | ||
| Required: | ||
|  | ||
| - `managed_id` (String) The managed ID of the rule set. Currently, only crs-basic is supported. | ||
| - `overall_threshold` (Number) Recommended default value is 5 | ||
| - `passive_mode` (Boolean) | ||
|  | ||
| Optional: | ||
|  | ||
| - `category_thresholds` (Map of Number) Thresholds for each category, e.g. fixation, injection-generic, injection-java, injection-php, lfi, protocol, rce, reputation-scanner, rfi, sqli, ssrf, xss | ||
| - `excluded_patterns` (List of String) | ||
| - `rule_overrides` (Attributes Map) (see [below for nested schema](#nestedatt--rule_sets--rule_overrides)) | ||
|  | ||
| <a id="nestedatt--rule_sets--rule_overrides"></a> | ||
| ### Nested Schema for `rule_sets.rule_overrides` | ||
|  | ||
| Required: | ||
|  | ||
| - `action` (String) log_only or none | ||
|  | ||
| ## Import | ||
|  | ||
| Import is supported using the following syntax: | ||
|  | ||
| ```shell | ||
| # Import a WAF policy by its team ID and the policy ID | ||
| terraform import netlify_waf_policy.main 6600abcdef1234567890abcd:6600abcdef1234567890abcd | ||
| ``` | ||
        
          
  
    
      
          
            5 changes: 5 additions & 0 deletions
          
          5 
        
  examples/data-sources/netlify_managed_waf_rules/data-source.tf
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Read-only definitions of all managed WAF rules available in Netlify. | ||
| # The team ID is required to query the rules. | ||
| data "netlify_managed_waf_rules" "example" { | ||
| team_id = "6600abcdef1234567890abcd" | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Import a WAF policy by its team ID and the policy ID | ||
| terraform import netlify_waf_policy.main 6600abcdef1234567890abcd:6600abcdef1234567890abcd | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| resource "netlify_waf_policy" "example" { | ||
| team_id = data.netlify_team.team.id | ||
| name = "Terraform Policy" | ||
| description = "This is a test policy through Terraform" | ||
| rule_sets = [ | ||
| { | ||
| managed_id = "crs-basic", | ||
| passive_mode = true, | ||
| overall_threshold = 5, | ||
| category_thresholds = { | ||
| "fixation" = 8, | ||
| }, | ||
| rule_overrides = { | ||
| "920100" = { | ||
| action = "log_only" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } | ||
|  | ||
| # To use this policy in a site, use the netlify_site_build_settings resource: | ||
|  | ||
| resource "netlify_site_build_settings" "example" { | ||
| # other attributes... | ||
| waf_policy_id = netlify_waf_policy.example.id | ||
| } | ||
|  | ||
| # To dynamically define the rule overrides, you can query netlify_managed_waf_rules to get the rule IDs: | ||
|  | ||
| data "netlify_managed_waf_rules" "example" { | ||
| team_id = "6600abcdef1234567890abcd" | ||
| } | ||
|  | ||
| resource "netlify_waf_policy" "example" { | ||
| team_id = "66ae34e11a567e9092e3850f" | ||
| name = "Terraform Policy" | ||
| description = "This is a test policy through Terraform" | ||
| rule_sets = [ | ||
| { | ||
| managed_id = "crs-basic", | ||
| passive_mode = true, | ||
| overall_threshold = 5, | ||
| rule_overrides = { | ||
| for rule in data.netlify_managed_waf_rules.example.rule_sets["crs-basic"].rules : rule.id => { | ||
| action = "log_only" | ||
| } if rule.category == "rce" | ||
| } | ||
| } | ||
| ] | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there some const that we can export? I don't know if terraform has those in general
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will think about that. Worst-case, maybe a hard-coded data source? I'll let you know what I find.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see something in the docs, and ChatGPT also recommended a hard-coded data source - which I don't love. I haven't seen other people doing that.
I will note that there is a static validation on this: https://github.com/netlify/terraform-provider-netlify/pull/77/files#diff-020ba6260ff9fbb79426060f367c74580fbcd04ff8b20c35bbd6345d1acb9157R116
It will fail the
.tffile before trying to apply, and I think smart IDEs might do a red squiggly if you enter an invalid value.