-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
google_compute_security_policy preconfigured_waf_config and recaptcha_options blocks are appearing during terraform plan and apply when not used #18596
Comments
Hi @a-ls-100 I tried to replicate this issue with the shared terraform version, Google provider version and the next configuration since you only provided an incomplete fraction of the code:
The result with After a 2nd Finally checking the documentation you can find in terraform registry for If you have a different code and want to test it please share it simplified, or you could include the values of the locals, variables and so on. For sensitive information you could replace the values with examples like: project = "my-project" |
Here is the generalized code from our module. variable "modsecurity_sqli" {
type = object({
preview = bool
exceptions = optional(list(string), [])
sensitivity = optional(number, 4)
})
default = {
preview = false
}
validation {
condition = var.modsecurity_sqli.sensitivity >= 1 && var.modsecurity_sqli.sensitivity <= 4
error_message = "Sensitivity level may be only integer >= 1 and <= 4."
}
description = "Tuning the modsecurity SQLi rule."
}
locals {
sqli = length(var.modsecurity_sqli.exceptions) > 0 ? "evaluatePreconfiguredWaf('sqli-${var.ruleset_version}', {'sensitivity': ${var.modsecurity_sqli.sensitivity}, 'opt_out_rule_ids': [${join(",", [for e in var.modsecurity_sqli.exceptions : "'${e}'"])}]})" : "evaluatePreconfiguredWaf('sqli-${var.ruleset_version}', {'sensitivity': ${var.modsecurity_sqli.sensitivity}})"
}
resource "google_compute_security_policy" "security-policy" {
provider = google-beta
lifecycle {
ignore_changes = [
adaptive_protection_config[0].layer_7_ddos_defense_config[0].rule_visibility
]
}
project = var.project_id
name = var.name
description = "ModSecurity CRSv3 rules for protection against various attacks"
dynamic "adaptive_protection_config" {
for_each = var.adaptive_protection ? [0] : []
content {
layer_7_ddos_defense_config {
enable = true
rule_visibility = "PREMIUM"
}
}
}
advanced_options_config {
json_parsing = var.enable_json_parsing ? "STANDARD" : "DISABLED"
}
rule {
priority = 11
action = "deny(${var.deny_status_code})"
match {
expr {
expression = local.modsecurity_expressions.sqli
}
}
preview = var.modsecurity_sqli.preview
description = "ModSecurity CRS SQLi attack rules"
}
}
|
@a-ls-100 Once again there is data which we do not have in the code you are sharing and it is not possible to replicate the scenario without that information but there is a base example like the one we shared with you in the previous answer. We need the value of the next variables:
Or you could send us a simplified version of the code without these variables with already defined values. The use of variables, locals and so on in general is a good practice, but for us we don't have access is necessary to send that information or a simplified code version. |
Same issue here. In our case, the Although the environment is almost the same, the issue sometimes occurs and sometimes doesn't, so we investigated it in more detail. It seems that there are cases where there are empty // A project where perma-diff is always shown
% gcloud compute security-policies rules describe --security-policy security-policy 4000
---
action: deny(403)
description: WAF rule for XSS
headerAction: {}
kind: compute#securityPolicyRule
match:
expr:
expression: <REDACTED>
exprOptions:
recaptchaOptions: {}
preconfiguredWafConfig: {}
preview: false
priority: 4000 // A project where perma-diff is not shown
% gcloud compute security-policies rules describe --security-policy security-policy 4000
---
action: deny(403)
description: WAF rule for XSS
headerAction: {}
kind: compute#securityPolicyRule
match:
expr:
expression: <REDACTED>
preview: false
priority: 4000 I'm not sure under what conditions this occurs, but if this is a valid response pattern for the API, I believe that Terraform should recognize both of these as the same value. |
After some attempts it is not possible to reproduce this issue, users commented that this issue happens sometimes but not always. It is necessary to check what is causing it at the code level, since at the terraform configuration level it is unpredictable. |
Hello Guys we have similar issue here. If the [expr_options] (https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_security_policy#expr_options) |
I am facing the same issue. We do not (and never have) set
Versions:
|
I have find a work around, if you want terraform to stop showing the difference on every apply at the block and assign it null values:
|
Same issue here, in a security policy with 10 rules only one was having this issue. @CristianCamilo98's workaround did not work for us, simply chose to ignore changes in the |
preconfigured_waf_config issue resolved. match.expr_options.recaptcha_options is still causing recreation of the rule.It is blocking this issue |
It seems that recreating the rule can fix the perma-diff issue. In my case, the issue started when I did some manual edit on the rule object on google cloud console |
Community Note
Terraform Version & Provider Version(s)
Terraform v1.4
provider registry.terraform.io/hashicorp/google v5.35.0
provider registry.terraform.io/hashicorp/google-beta v5.35.0
provider registry.terraform.io/hashicorp/google v4.84.0
provider registry.terraform.io/hashicorp/google-beta v4.84.0
Affected Resource(s)
Terraform Configuration
Debug Output
No response
Expected Behavior
Actual Behavior
Steps to reproduce
While we are not using the blocks like below in our module. Terraform is somehow adding this and this always conflicts with the state showing false positives
expr_options case
While looking at the source code, the expr_options is set to be an optional value,
But recaptcha_options is set to Required,
I believe this is the reason why terraform state always displays conflicting information.
preconfigured_waf_config's case
Really not sure with this case, as we do not use this code block, but we see the preconfigured_waf_config is being set as an empty map for all our rules.
Important Factoids
No response
References
No response
b/353545374
The text was updated successfully, but these errors were encountered: