This template accepts a pending AWS GuardDuty invitation for a member account and manages the association with the primary account.

Terraform Template

resource "aws_guardduty_detector" "member" {
  provider = "aws.member"
}

resource "aws_guardduty_detector" "primary" {
  provider = "aws.primary"
}

resource "aws_guardduty_invite_accepter" "member" {
  depends_on = ["aws_guardduty_member.member"]
  detector_id = aws_guardduty_detector.member.id
  master_account_id = aws_guardduty_detector.primary.account_id
  provider = "aws.member"
}

resource "aws_guardduty_member" "member" {
  account_id = aws_guardduty_detector.member.account_id
  detector_id = aws_guardduty_detector.primary.id
  email = "required@example.com"
  invite = true
  provider = "aws.primary"
}