Skip to content

Commit

Permalink
hashicorp#25131: add kubernetes test
Browse files Browse the repository at this point in the history
  • Loading branch information
nick committed Jul 17, 2022
1 parent 29f5103 commit 81a712b
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions internal/service/guardduty/organization_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,44 @@ func testAccOrganizationConfiguration_s3logs(t *testing.T) {
})
}

func testAccOrganizationConfiguration_kubernetes(t *testing.T) {
detectorResourceName := "aws_guardduty_detector.test"
resourceName := "aws_guardduty_organization_configuration.test"

resource.Test(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(t)
acctest.PreCheckOrganizationsAccount(t)
},
ErrorCheck: acctest.ErrorCheck(t, guardduty.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: testAccCheckDetectorDestroy,
Steps: []resource.TestStep{
{
Config: testAccOrganizationConfigurationConfig_kubernetes(true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "auto_enable", "true"),
resource.TestCheckResourceAttrPair(resourceName, "detector_id", detectorResourceName, "id"),
resource.TestCheckResourceAttr(resourceName, "datasources.0.kubernetes.0.audit_logs.0.enable", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccOrganizationConfigurationConfig_kubernetes(false),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "auto_enable", "true"),
resource.TestCheckResourceAttrPair(resourceName, "detector_id", detectorResourceName, "id"),
resource.TestCheckResourceAttr(resourceName, "datasources.0.kubernetes.0.audit_logs.0.enable", "false"),
),
},
},
})
}

func testAccOrganizationConfigurationConfig_autoEnable(autoEnable bool) string {
return fmt.Sprintf(`
data "aws_caller_identity" "current" {}
Expand Down Expand Up @@ -146,3 +184,39 @@ resource "aws_guardduty_organization_configuration" "test" {
}
`, autoEnable)
}

func testAccOrganizationConfigurationConfig_kubernetes(autoEnable bool) string {
return fmt.Sprintf(`
data "aws_caller_identity" "current" {}
data "aws_partition" "current" {}
resource "aws_organizations_organization" "test" {
aws_service_access_principals = ["guardduty.${data.aws_partition.current.dns_suffix}"]
feature_set = "ALL"
}
resource "aws_guardduty_detector" "test" {}
resource "aws_guardduty_organization_admin_account" "test" {
depends_on = [aws_organizations_organization.test]
admin_account_id = data.aws_caller_identity.current.account_id
}
resource "aws_guardduty_organization_configuration" "test" {
depends_on = [aws_guardduty_organization_admin_account.test]
auto_enable = true
detector_id = aws_guardduty_detector.test.id
datasources {
kubernetes {
audit_logs {
enable = %[1]t
}
}
}
}
`, autoEnable)
}

0 comments on commit 81a712b

Please sign in to comment.