Skip to content

Commit

Permalink
Write test to confirm bug hashicorp#18446
Browse files Browse the repository at this point in the history
  • Loading branch information
Brunhil authored and YakDriver committed May 4, 2021
1 parent 28b7176 commit 8ddc68b
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
94 changes: 94 additions & 0 deletions aws/resource_aws_lakeformation_permissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,30 @@ func testAccAWSLakeFormationPermissions_selectPermissions(t *testing.T) {
})
}

func testAccAWSLakeFormationPermissions_wildcardPermissions(t *testing.T) {
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_lakeformation_permissions.test"
roleName := "aws_iam_role.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(lakeformation.EndpointsID, t) },
ErrorCheck: testAccErrorCheck(t, lakeformation.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSLakeFormationPermissionsDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLakeFormationPermissionsConfig_wildcardPermissions(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSLakeFormationPermissionsExists(resourceName),
resource.TestCheckResourceAttrPair(resourceName, "principal", roleName, "arn"),
resource.TestCheckResourceAttr(resourceName, "permissions.#", "7"),
resource.TestCheckResourceAttr(resourceName, "permissions_with_grant_option.#", "7"),
),
},
},
})
}

func testAccCheckAWSLakeFormationPermissionsDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).lakeformationconn

Expand Down Expand Up @@ -835,3 +859,73 @@ resource "aws_lakeformation_permissions" "test" {
}
`, rName)
}

func testAccAWSLakeFormationPermissionsConfig_wildcardPermissions(rName string) string {
return fmt.Sprintf(`
data "aws_partition" "current" {}
resource "aws_iam_role" "test" {
name = %[1]q
path = "/"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "glue.${data.aws_partition.current.dns_suffix}"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
data "aws_caller_identity" "current" {}
resource "aws_glue_catalog_database" "test" {
name = %[1]q
}
resource "aws_glue_catalog_table" "test" {
name = %[1]q
database_name = aws_glue_catalog_database.test.name
storage_descriptor {
columns {
name = "event"
type = "string"
}
columns {
name = "timestamp"
type = "date"
}
columns {
name = "value"
type = "double"
}
}
}
resource "aws_lakeformation_data_lake_settings" "test" {
# this will result in multiple permissions for iam role
admins = [aws_iam_role.test.arn, data.aws_caller_identity.current.arn]
}
resource "aws_lakeformation_permissions" "test" {
principal = aws_iam_role.test.arn
permissions = ["ALL", "ALTER", "DELETE", "DESCRIBE", "DROP", "INSERT", "SELECT"]
permissions_with_grant_option = ["ALL", "ALTER", "DELETE", "DESCRIBE", "DROP", "INSERT", "SELECT"]
table {
database_name = aws_glue_catalog_table.test.database_name
wildcard = true
}
}
`, rName)
}
3 changes: 2 additions & 1 deletion aws/resource_aws_lakeformation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ func TestAccAWSLakeFormation_serial(t *testing.T) {
"basic": testAccAWSLakeFormationPermissions_basic,
"dataLocation": testAccAWSLakeFormationPermissions_dataLocation,
"database": testAccAWSLakeFormationPermissions_database,
"selectPermissions": testAccAWSLakeFormationPermissions_selectPermissions,
"selectPermissions": testAccAWSLakeFormationPermissions_selectPermissions,
"wildcardPermissions": testAccAWSLakeFormationPermissions_wildcardPermissions,
},
"TablePermissions": {
"tableName": testAccAWSLakeFormationPermissions_table_name,
Expand Down

0 comments on commit 8ddc68b

Please sign in to comment.