-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Add GuardDuty filter resource #14876
Conversation
Merging master into feature branch
# Conflicts: # aws/provider.go # website/aws.erb
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.
Just some minor items to consider, otherwise looking good! 🚀
Output from acceptance testing:
--- PASS: TestAccAWSGuardDuty_serial/Filter (102.51s)
--- PASS: TestAccAWSGuardDuty_serial/Filter/update (26.72s)
--- PASS: TestAccAWSGuardDuty_serial/Filter/tags (33.67s)
--- PASS: TestAccAWSGuardDuty_serial/Filter/disappears (16.50s)
--- PASS: TestAccAWSGuardDuty_serial/Filter/basic (25.62s)
aws/resource_aws_guardduty_filter.go
Outdated
input := guardduty.UpdateFilterInput{ | ||
Action: aws.String(d.Get("action").(string)), | ||
Description: aws.String(d.Get("description").(string)), | ||
DetectorId: aws.String(d.Get("detector_id").(string)), | ||
FilterName: aws.String(d.Get("name").(string)), | ||
Rank: aws.Int64(int64(d.Get("rank").(int))), | ||
} | ||
|
||
var err error | ||
input.FindingCriteria, err = expandFindingCriteria(d.Get("finding_criteria").([]interface{})) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Printf("[DEBUG] Updating GuardDuty Filter: %s", input) | ||
|
||
_, err = conn.UpdateFilter(&input) | ||
if err != nil { | ||
return fmt.Errorf("error updating GuardDuty Filter %s: %w", d.Id(), err) | ||
} |
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.
To prevent the UpdateFilter
API call when only tags are updated, this logic should be wrapped with d.HasChanges()
:
input := guardduty.UpdateFilterInput{ | |
Action: aws.String(d.Get("action").(string)), | |
Description: aws.String(d.Get("description").(string)), | |
DetectorId: aws.String(d.Get("detector_id").(string)), | |
FilterName: aws.String(d.Get("name").(string)), | |
Rank: aws.Int64(int64(d.Get("rank").(int))), | |
} | |
var err error | |
input.FindingCriteria, err = expandFindingCriteria(d.Get("finding_criteria").([]interface{})) | |
if err != nil { | |
return err | |
} | |
log.Printf("[DEBUG] Updating GuardDuty Filter: %s", input) | |
_, err = conn.UpdateFilter(&input) | |
if err != nil { | |
return fmt.Errorf("error updating GuardDuty Filter %s: %w", d.Id(), err) | |
} | |
if d.HasChanges("action", "description", "finding_criteria", "rank") { | |
input := guardduty.UpdateFilterInput{ | |
Action: aws.String(d.Get("action").(string)), | |
Description: aws.String(d.Get("description").(string)), | |
DetectorId: aws.String(d.Get("detector_id").(string)), | |
FilterName: aws.String(d.Get("name").(string)), | |
Rank: aws.Int64(int64(d.Get("rank").(int))), | |
} | |
var err error | |
input.FindingCriteria, err = expandFindingCriteria(d.Get("finding_criteria").([]interface{})) | |
if err != nil { | |
return err | |
} | |
log.Printf("[DEBUG] Updating GuardDuty Filter: %s", input) | |
_, err = conn.UpdateFilter(&input) | |
if err != nil { | |
return fmt.Errorf("error updating GuardDuty Filter %s: %w", d.Id(), err) | |
} | |
} |
aws/resource_aws_guardduty_filter.go
Outdated
} | ||
|
||
func joinGuardDutyFilterID(detectorID, filterName string) string { | ||
return detectorID + "_" + filterName |
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 we would like consistency with the other GuardDuty resources, they use the colon (:
) separator. 👍 e.g.
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/guardduty_ipset#import
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/guardduty_publishing_destination#import
func testAccGuardDutyFilterConfig_full(startDate, endDate string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_guardduty_filter" "test" { | ||
detector_id = "${aws_guardduty_detector.test.id}" |
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.
Nit: Terraform 0.12 syntax
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.
That's embarrassing…
This has been released in version 3.5.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Completes work done in #10676 by @graffzon and @suzuki-shunsuke to add GuardDuty filter resource
Community Note
Closes #9647
Closes #10676
Release note for CHANGELOG:
Output from acceptance testing: