Closed danielmitchell closed 3 years ago
Hi @danielmitchell 👋 Thank you for raising this and sorry you ran into trouble here. We did not explicitly have an end-to-end test for table
wildcard = true
, so I quickly created one similar to the others with the following code:
func testAccAWSLakeFormationPermissions_table_wildcard(t *testing.T) {
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_lakeformation_permissions.test"
databaseResourceName := "aws_glue_catalog_database.test"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck(lakeformation.EndpointsID, t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSLakeFormationPermissionsDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLakeFormationPermissionsConfig_table_wildcard(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSLakeFormationPermissionsExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "table.#", "1"),
resource.TestCheckResourceAttrPair(resourceName, "table.0.database_name", databaseResourceName, "name"),
resource.TestCheckResourceAttr(resourceName, "table.0.wildcard", "true"),
),
},
},
})
}
func testAccAWSLakeFormationPermissionsConfig_table_wildcard(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_lakeformation_data_lake_settings" "test" {
admins = [data.aws_caller_identity.current.arn]
}
resource "aws_lakeformation_permissions" "test" {
permissions = ["ALL", "ALTER", "DELETE", "DESCRIBE", "DROP", "INSERT"]
permissions_with_grant_option = ["ALL", "ALTER", "DELETE", "DESCRIBE", "DROP", "INSERT"]
principal = aws_iam_role.test.arn
table {
database_name = aws_glue_catalog_database.test.name
wildcard = true
}
}
`, rName)
}
Which passes okay (able to grant, read, and revoke the LakeFormation Permissions with no errors/differences):
--- PASS: TestAccAWSLakeFormation_serial/Permissions/tableWildcard (25.69s)
I was however, able to reproduce your error when the principal for Terraform run was not in the LakeFormation Data Lake Settings administrators. My guess is that either your Terraform credentials need to be granted additional permissions (e.g. using the aws_lakeformation_data_lake_settings
resource) or there is some other potential issue with LakeFormation that is likely best supported by the AWS service team by raising an AWS Support case. There is also a wide variety of documentation available in the LakeFormation Developer Guide on the complex permissions model.
Thanks for investigating. I was able to resolve the issue by following your advice to ensure the Terraform user was an admin in the data lake settings :thumbsup:
Odd that it had permission for each of the individual tables when added separately (which it gets automatically as the database creator) but not when using the wildcard.
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!
Community Note
Terraform CLI and Terraform AWS Provider Version
Terraform: v0.13.16 Provider: v3.25.0
Affected Resource(s)
Terraform Configuration Files
Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.
Debug Output
Panic Output
Expected Behavior
Creating an aws_lakeformation_permissions resource with table.wildcard set to true should create permissions for all tables in the database
Actual Behavior
Creating an aws_lakeformation_permissions resource with table.wildcard set to true times out after 2 minutes and triggers an error
AccessDeniedException: Resource does not exist or requester is not authorized to access requested permissions.
Creating the same permissions resource with named tables (wildcard = false) works correctly. Creating the same permissions with wildcard = true manually in the console using the same role also works correctly.
Steps to Reproduce
terraform apply
Important Factoids
References