-
Notifications
You must be signed in to change notification settings - Fork 605
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
Fix unexpected crashes when using cloudflare_notification_policy
with a filters
attribute
#1520
Closed
0gajun
wants to merge
3
commits into
cloudflare:master
from
0gajun:dont_use_map_for_non_primitive_values
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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,3 @@ | ||
```release-note:bug | ||
resource/cloudflare_notification_policy: Fix unexpected crashes when using cloudflare_notification_policy with a filters attribute | ||
``` |
This file contains 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 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 |
---|---|---|
|
@@ -8,7 +8,7 @@ import ( | |
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccCloudflareNotificationPolicy(t *testing.T) { | ||
func TestAccCloudflareNotificationPolicy_Basic(t *testing.T) { | ||
// Temporarily unset CLOUDFLARE_API_TOKEN if it is set as the notification | ||
// service does not yet support the API tokens and it results in | ||
// misleading state error messages. | ||
|
@@ -84,3 +84,103 @@ func testCheckCloudflareNotificationPolicyUpdated(resName, policyName, policyDes | |
} | ||
}`, resName, policyName, policyDesc, accountID) | ||
} | ||
|
||
func TestAccCloudflareNotificationPolicy_WithFiltersAttribute(t *testing.T) { | ||
// Temporarily unset CLOUDFLARE_API_TOKEN if it is set as the notification | ||
// service does not yet support the API tokens and it results in | ||
// misleading state error messages. | ||
if os.Getenv("CLOUDFLARE_API_TOKEN") != "" { | ||
defer func(apiToken string) { | ||
os.Setenv("CLOUDFLARE_API_TOKEN", apiToken) | ||
}(os.Getenv("CLOUDFLARE_API_TOKEN")) | ||
os.Setenv("CLOUDFLARE_API_TOKEN", "") | ||
} | ||
|
||
rnd := generateRandomResourceName() | ||
resourceName := "cloudflare_notification_policy." + rnd | ||
updatedPolicyName := "updated Advanced Security Events Alert from terraform provider" | ||
updatedPolicyDesc := "updated description" | ||
accountID := os.Getenv("CLOUDFLARE_ACCOUNT_ID") | ||
zoneID := os.Getenv("CLOUDFLARE_ZONE_ID") | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheckAccount(t) | ||
}, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testCheckCloudflareNotificationPolicyWithFiltersAttribute(rnd, accountID, zoneID), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(resourceName, "name", "test Advanced Security Events Alert from terraform provider"), | ||
resource.TestCheckResourceAttr(resourceName, "description", "test description"), | ||
resource.TestCheckResourceAttr(resourceName, "enabled", "true"), | ||
resource.TestCheckResourceAttr(resourceName, "alert_type", "clickhouse_alert_fw_ent_anomaly"), | ||
resource.TestCheckResourceAttr(resourceName, "account_id", accountID), | ||
resource.TestCheckResourceAttr(resourceName, "filters.0.services.#", "1"), | ||
resource.TestCheckResourceAttr(resourceName, "filters.0.services.0", "waf"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
resource.TestCheckResourceAttr(resourceName, "filters.0.zones.#", "1"), | ||
resource.TestCheckResourceAttr(resourceName, "filters.0.zones.0", zoneID), | ||
), | ||
}, | ||
{ | ||
Config: testCheckCloudflareNotificationPolicyWithFiltersAttributeUpdated(rnd, updatedPolicyName, updatedPolicyDesc, accountID, zoneID), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(resourceName, "name", updatedPolicyName), | ||
resource.TestCheckResourceAttr(resourceName, "description", updatedPolicyDesc), | ||
resource.TestCheckResourceAttr(resourceName, "enabled", "true"), | ||
resource.TestCheckResourceAttr(resourceName, "alert_type", "clickhouse_alert_fw_ent_anomaly"), | ||
resource.TestCheckResourceAttr(resourceName, "account_id", accountID), | ||
resource.TestCheckResourceAttr(resourceName, "filters.0.services.#", "2"), | ||
resource.TestCheckResourceAttr(resourceName, "filters.0.services.0", "waf"), | ||
resource.TestCheckResourceAttr(resourceName, "filters.0.services.1", "firewallrules"), | ||
resource.TestCheckResourceAttr(resourceName, "filters.0.zones.#", "1"), | ||
resource.TestCheckResourceAttr(resourceName, "filters.0.zones.0", zoneID), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testCheckCloudflareNotificationPolicyWithFiltersAttribute(name, accountID, zoneID string) string { | ||
return fmt.Sprintf(` | ||
resource "cloudflare_notification_policy" "%[1]s" { | ||
name = "test Advanced Security Events Alert from terraform provider" | ||
account_id = "%[2]s" | ||
description = "test description" | ||
enabled = true | ||
alert_type = "clickhouse_alert_fw_ent_anomaly" | ||
email_integration { | ||
name = "" | ||
id = "[email protected]" | ||
} | ||
filters { | ||
services = [ | ||
"waf", | ||
] | ||
zones = ["%[3]s"] | ||
} | ||
}`, name, accountID, zoneID) | ||
} | ||
|
||
func testCheckCloudflareNotificationPolicyWithFiltersAttributeUpdated(resName, policyName, policyDesc, accountID, zoneID string) string { | ||
return fmt.Sprintf(` | ||
resource "cloudflare_notification_policy" "%[1]s" { | ||
name = "%[2]s" | ||
account_id = "%[4]s" | ||
description = "%[3]s" | ||
enabled = true | ||
alert_type = "clickhouse_alert_fw_ent_anomaly" | ||
email_integration { | ||
name = "" | ||
id = "[email protected]" | ||
} | ||
filters { | ||
services = [ | ||
"waf", | ||
"firewallrules", | ||
] | ||
zones = ["%[5]s"] | ||
} | ||
}`, resName, policyName, policyDesc, accountID, zoneID) | ||
} |
This file contains 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
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.
if i'm understanding this correctly, you'll need to build this
map[string][]string
instead of casting it. looping overfilters
and appending should do it.