Skip to content
This repository was archived by the owner on Jan 17, 2025. It is now read-only.

Commit 23b3d4a

Browse files
committed
Add tests for grant to public for tables
1 parent 74a2b71 commit 23b3d4a

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

redshift/resource_redshift_grant.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,9 @@ func readTableGrants(db *DBConnection, d *schema.ResourceData) error {
447447
d.Set(grantPrivilegesAttr, privilegesSet)
448448
break
449449
}
450+
451+
log.Printf("[DEBUG] Collected table grants; table: '%v'; privileges: %v; for: %s", objName, privilegesSet.List(), entityName)
450452
}
451-
log.Printf("[DEBUG] Collected table grants")
452453

453454
return nil
454455
}

redshift/resource_redshift_grant_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,46 @@ resource "redshift_grant" "public" {
102102
})
103103
}
104104

105+
func TestAccRedshiftGrant_TableToPublic(t *testing.T) {
106+
config := `
107+
resource "redshift_grant" "public" {
108+
group = "public"
109+
110+
schema = "pg_catalog"
111+
object_type = "table"
112+
objects = ["pg_user_info"]
113+
privileges = ["select", "update", "insert", "delete", "drop", "references", "rule", "trigger"]
114+
}
115+
`
116+
resource.Test(t, resource.TestCase{
117+
PreCheck: func() { testAccPreCheck(t) },
118+
Providers: testAccProviders,
119+
CheckDestroy: func(s *terraform.State) error { return nil },
120+
Steps: []resource.TestStep{
121+
{
122+
Config: config,
123+
Check: resource.ComposeTestCheckFunc(
124+
resource.TestCheckResourceAttr("redshift_grant.public", "id", "gn:public_ot:table_pg_catalog_pg_user_info"),
125+
resource.TestCheckResourceAttr("redshift_grant.public", "group", "public"),
126+
resource.TestCheckResourceAttr("redshift_grant.public", "schema", "pg_catalog"),
127+
resource.TestCheckResourceAttr("redshift_grant.public", "object_type", "table"),
128+
resource.TestCheckResourceAttr("redshift_grant.public", "objects.#", "1"),
129+
resource.TestCheckTypeSetElemAttr("redshift_grant.public", "objects.*", "pg_user_info"),
130+
resource.TestCheckResourceAttr("redshift_grant.public", "privileges.#", "8"),
131+
resource.TestCheckTypeSetElemAttr("redshift_grant.public", "privileges.*", "select"),
132+
resource.TestCheckTypeSetElemAttr("redshift_grant.public", "privileges.*", "update"),
133+
resource.TestCheckTypeSetElemAttr("redshift_grant.public", "privileges.*", "insert"),
134+
resource.TestCheckTypeSetElemAttr("redshift_grant.public", "privileges.*", "delete"),
135+
resource.TestCheckTypeSetElemAttr("redshift_grant.public", "privileges.*", "drop"),
136+
resource.TestCheckTypeSetElemAttr("redshift_grant.public", "privileges.*", "references"),
137+
resource.TestCheckTypeSetElemAttr("redshift_grant.public", "privileges.*", "rule"),
138+
resource.TestCheckTypeSetElemAttr("redshift_grant.public", "privileges.*", "trigger"),
139+
),
140+
},
141+
},
142+
})
143+
}
144+
105145
func TestAccRedshiftGrant_BasicDatabase(t *testing.T) {
106146
groupNames := []string{
107147
strings.ReplaceAll(acctest.RandomWithPrefix("tf_acc_group"), "-", "_"),

0 commit comments

Comments
 (0)