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

New Resource: aws_guardduty_member #2911

Merged
merged 3 commits into from
Jan 11, 2018

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Jan 9, 2018

References:

make testacc TEST=./aws TESTARGS='-run=TestAccAWSGuardDuty'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSGuardDuty -timeout 120m
=== RUN   TestAccAWSGuardDuty
=== RUN   TestAccAWSGuardDuty/Detector
=== RUN   TestAccAWSGuardDuty/Detector/basic
=== RUN   TestAccAWSGuardDuty/Detector/import
=== RUN   TestAccAWSGuardDuty/Member
=== RUN   TestAccAWSGuardDuty/Member/basic
=== RUN   TestAccAWSGuardDuty/Member/import
--- PASS: TestAccAWSGuardDuty (77.94s)
    --- PASS: TestAccAWSGuardDuty/Detector (47.27s)
        --- PASS: TestAccAWSGuardDuty/Detector/basic (33.38s)
        --- PASS: TestAccAWSGuardDuty/Detector/import (13.89s)
    --- PASS: TestAccAWSGuardDuty/Member (30.66s)
        --- PASS: TestAccAWSGuardDuty/Member/basic (15.09s)
        --- PASS: TestAccAWSGuardDuty/Member/import (15.58s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	77.977s

@bflad bflad mentioned this pull request Jan 9, 2018
@Ninir Ninir added enhancement Requests to existing resources that expand the functionality or scope. new-resource Introduces a new resource. labels Jan 10, 2018
@bflad bflad added the service/guardduty Issues and PRs that pertain to the guardduty service. label Jan 11, 2018
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

Looking pretty good.

I left you 2 major questions/suggestions about potential crashes and 1 minor about tests synchronicity.

log.Printf("[DEBUG] Reading GuardDuty Member: %s", input)
gmo, err := conn.GetMembers(&input)
if err != nil {
if isAWSErr(err, guardduty.ErrCodeBadRequestException, "The request is rejected because the input detectorId is not owned by the current account.") {
Copy link
Member

Choose a reason for hiding this comment

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

😭

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah its like S3 NoSuchBucket in this regard. 😢

member := gmo.Members[0]
d.Set("account_id", *member.AccountId)
d.Set("detector_id", detectorID)
d.Set("email", *member.Email)
Copy link
Member

Choose a reason for hiding this comment

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

Dereferencing here is not necessary, or in fact undesired. Set() will perform safe dereferencing - meaning that it won't crash on nil. We had many crash reports caused by this in the past which led us to this thought.

Do you mind changing it accordingly? 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

💯 I'll update this code and personally file this under "leave the stars to the night sky"!


idParts := strings.Split(d.Id(), ":")
accountID := idParts[1]
detectorID := idParts[0]
Copy link
Member

Choose a reason for hiding this comment

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

Q: What happens if the user passes only one ID? Isn't it going to crash here because Split() won't return [1]?

I think it would be nice to have a helper function for this, e.g. accId, detectorId, err := decodeGuardDutyMemberId(d.Id()) and keep the error message there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oi! This is a very good catch! I totally forgot to split it out into a decode function with the error checking after initially writing it.

"Member": {
"basic": testAccAwsGuardDutyMember_basic,
"import": testAccAwsGuardDutyMember_import,
},
Copy link
Member

Choose a reason for hiding this comment

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

I assume there can be more than 1 member per AWS account, so we don't need to make these tests synchronous? Unless I'm mistaken...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This needs to be like this because its like AWS Config, where it can only be activated once in a region, so we're left with serially doing one test at a time since we turn the GuardDuty detector on and off each test.

Copy link
Member

Choose a reason for hiding this comment

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

I see, 👌

@radeksimko radeksimko added the waiting-response Maintainers are waiting on response from community or contributor. label Jan 11, 2018
* Do not unsafely dereference member attributes for d.Set()
* Separate ID parsing into decodeGuardDutyMemberID with error checking
@bflad
Copy link
Contributor Author

bflad commented Jan 11, 2018

Updated and verified locally! Thanks for those very important catches. 🚀

make testacc TEST=./aws TESTARGS='-run=TestAccAWSGuardDuty'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSGuardDuty -timeout 120m
=== RUN   TestAccAWSGuardDuty
=== RUN   TestAccAWSGuardDuty/Detector
=== RUN   TestAccAWSGuardDuty/Detector/basic
=== RUN   TestAccAWSGuardDuty/Detector/import
=== RUN   TestAccAWSGuardDuty/Member
=== RUN   TestAccAWSGuardDuty/Member/basic
=== RUN   TestAccAWSGuardDuty/Member/import
--- PASS: TestAccAWSGuardDuty (53.58s)
    --- PASS: TestAccAWSGuardDuty/Detector (31.83s)
        --- PASS: TestAccAWSGuardDuty/Detector/basic (20.85s)
        --- PASS: TestAccAWSGuardDuty/Detector/import (10.97s)
    --- PASS: TestAccAWSGuardDuty/Member (21.75s)
        --- PASS: TestAccAWSGuardDuty/Member/basic (10.05s)
        --- PASS: TestAccAWSGuardDuty/Member/import (11.70s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	53.620s

@bflad bflad removed the waiting-response Maintainers are waiting on response from community or contributor. label Jan 11, 2018
@bflad bflad requested a review from radeksimko January 11, 2018 16:05
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

LGTM.

func decodeGuardDutyMemberID(id string) (accountID, detectorID string, err error) {
parts := strings.Split(id, ":")
if len(parts) != 2 {
err = fmt.Errorf("GuardDuty Member ID must be of the form <Detector ID>:<Member AWS Account ID>")
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: We could include the real ID in the error message here.

"Member": {
"basic": testAccAwsGuardDutyMember_basic,
"import": testAccAwsGuardDutyMember_import,
},
Copy link
Member

Choose a reason for hiding this comment

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

I see, 👌

@bflad bflad merged commit d811d63 into hashicorp:master Jan 11, 2018
@bflad bflad deleted the f-aws_guardduty_member branch January 11, 2018 18:41
bflad added a commit that referenced this pull request Jan 11, 2018
@bflad bflad added this to the v1.7.0 milestone Jan 12, 2018
@bflad
Copy link
Contributor Author

bflad commented Jan 12, 2018

This has been released in terraform-provider-aws version 1.7.0. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

jocgir added a commit to coveooss/terraform-provider-aws that referenced this pull request Jan 12, 2018
* commit 'b9284490eff637460fef663794a496d363e19f10': (190 commits)
  v1.7.0
  Update CHANGELOG.md
  d/aws_ssm_parameter: Support returning raw encrypted SecureString value. (hashicorp#2777)
  Bump aws-sdk-go to v1.12.60
  Update CHANGELOG.md
  Add acceptance test for import + randomization
  Removed reference to Core fixes
  Add instructions for vendor updates
  Use AWS example instead of Azure
  Update CHANGELOG for hashicorp#2833
  Update CHANGELOG.md
  r/lb_target_group: Fix validation rules for LB's healthcheck
  Update CHANGELOG for hashicorp#2911
  r/aws_guardduty_member: Provide given ID in error message when incorrect format
  Update CHANGELOG.md
  Update CHANGELOG with hashicorp#2888
  r/aws_guardduty_member: hashicorp#2911 PR review
  r/aws_cloudwatch_event_permission: hashicorp#2888 PR review
  Makefile: Fixed test outputs
  resource/aws_lb+aws_elb: Fix regression with undefined 'name'
  ...

# Conflicts:
#	.gitignore
#	aws/data_source_aws_s3_bucket_object.go
#	aws/resource_aws_elasticsearch_domain.go
@ghost
Copy link

ghost commented Apr 8, 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 Apr 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. new-resource Introduces a new resource. service/guardduty Issues and PRs that pertain to the guardduty service.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants