Skip to content
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

Amazon GuardDuty supports exporting findings to an Amazon S3 bucket #10920 #12398

Closed

Conversation

shaepe-nc
Copy link
Contributor

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Closes #10920

Release note for CHANGELOG:

**New Resource**: `aws_guardduty_publishing_destination` (#10920)

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccAwsGuardDutyPublishingDestination'

==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -count 1 -parallel 20 -run=TestAccAwsGuardDutyPublishingDestination -timeout 120m
?       github.com/terraform-providers/terraform-provider-aws   [no test files]
=== RUN   TestAccAwsGuardDutyPublishingDestination_basic
--- PASS: TestAccAwsGuardDutyPublishingDestination_basic (105.17s)
=== RUN   TestAccAwsGuardDutyPublishingDestination_import
--- PASS: TestAccAwsGuardDutyPublishingDestination_import (106.17s)
PASS
...

@shaepe-nc shaepe-nc requested a review from a team March 15, 2020 15:35
@ghost ghost added size/XL Managed by automation to categorize the size of a PR. needs-triage Waiting for first response or review from a maintainer. documentation Introduces or discusses updates to documentation. provider Pertains to the provider itself, rather than any interaction with AWS. service/guardduty Issues and PRs that pertain to the guardduty service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Mar 15, 2020
},
"destination_arn": {
Type: schema.TypeString,
Required: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add ValidateFunc: validateArn,?

},
"kms_key_arn": {
Type: schema.TypeString,
Required: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add ValidateFunc: validateArn,?

"destination_type": {
Type: schema.TypeString,
Optional: true,
Default: "S3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use AWS SDK-provided constant guardduty.DestinationTypeS3.

}
resp, err := conn.DescribePublishingDestination(input)
if err != nil {
return nil, "failed", err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add as

// Constants not currently provided by the AWS Go SDK
const (
	guardDutyPublishingStatusFailed  = "FAILED"
)

at top of file?

func resourceAwsGuardDutyPublishingDestinationRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).guarddutyconn

destination_id, detector_id, err_state_read := decodeGuardDutyPublishDestinationID(d.Id())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer camelCase over snake_case here (and others).

}

log.Printf("[DEBUG] Delete GuardDuty publishing destination: %s", input)
_, err := conn.DeletePublishingDestination(&input)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the PublishingDestination has been deleted outside Terraform?
Do we need the if isAWSErr(err, guardduty.ErrCodeBadRequestException,... check here?

@miguelaferreira
Copy link
Contributor

Hi @shaepe. Thanks for this PR, my team is looking to use this resource and I'm wondering if you will have the time to address the review from @ewbankkit, otherwise we could do that to make progress on your PR.

* Merged latest master changes and resolved conflicts
@ghost ghost added size/XXL Managed by automation to categorize the size of a PR. and removed size/XL Managed by automation to categorize the size of a PR. labels Jun 14, 2020
@ghost ghost added the dependencies Used to indicate dependency changes. label Jun 14, 2020
@ghost ghost removed the size/XXL Managed by automation to categorize the size of a PR. label Jun 14, 2020
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Jun 14, 2020
Type: schema.TypeString,
Optional: true,
Default: guardduty.DestinationTypeS3,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add

ValidateFunc: validation.StringInSlice([]string{
  guardduty.DestinationTypeS3,
}, false),

guardduty.PublishingStatusPublishing, err)
}

d.SetId(fmt.Sprintf("%s:%s", d.Get("detector_id"), *output.DestinationId))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d.SetId(fmt.Sprintf("%s:%s", d.Get("detector_id"), aws.StringValue(output.DestinationId)))

return fmt.Errorf("Creating GuardDuty publishing destination failed: %s", err.Error())
}

stateConf := &resource.StateChangeConf{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please move this code to aws/internal/service/guardduty/waiter and follow the pattern there?
See #12840.

@bflad bflad added new-resource Introduces a new resource. and removed dependencies Used to indicate dependency changes. needs-triage Waiting for first response or review from a maintainer. labels Jun 15, 2020
@bendehaan
Copy link
Contributor

@ewbankkit moved to new PR since original author is unresponsive: #13894

@ewbankkit
Copy link
Contributor

Closing in favour of #13894.
@shaepe Thanks for your work on this.

@ewbankkit ewbankkit closed this Aug 4, 2020
@ghost
Copy link

ghost commented Sep 4, 2020

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!

@ghost ghost locked and limited conversation to collaborators Sep 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. new-resource Introduces a new resource. provider Pertains to the provider itself, rather than any interaction with AWS. service/guardduty Issues and PRs that pertain to the guardduty service. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Amazon GuardDuty supports exporting findings to an Amazon S3 bucket
5 participants