@@ -103,6 +103,73 @@ resource "redshift_group" "update_group" {
103
103
})
104
104
}
105
105
106
+ func TestAccRedshiftGroup_RemoveExistingUser (t * testing.T ) {
107
+ groupName := strings .ReplaceAll (acctest .RandomWithPrefix ("TF_acc_group" ), "-" , "_" )
108
+ userName1 := strings .ReplaceAll (acctest .RandomWithPrefix ("TF_Acc_Group_User" ), "-" , "_" )
109
+ userName2 := strings .ReplaceAll (acctest .RandomWithPrefix ("tf_acc_group_user" ), "-" , "_" )
110
+
111
+ configCreate := fmt .Sprintf (`
112
+ resource "redshift_group" "group" {
113
+ name = %[1]q
114
+ users = [
115
+ redshift_user.user1.name,
116
+ redshift_user.user2.name,
117
+ ]
118
+ }
119
+
120
+ resource "redshift_user" "user1" {
121
+ name = %[2]q
122
+ }
123
+
124
+ resource "redshift_user" "user2" {
125
+ name = %[3]q
126
+ }
127
+ ` , groupName , userName1 , userName2 )
128
+
129
+ configUpdate := fmt .Sprintf (`
130
+ resource "redshift_group" "group" {
131
+ name = %[1]q
132
+ users = [
133
+ redshift_user.user1.name
134
+ ]
135
+ }
136
+
137
+ resource "redshift_user" "user1" {
138
+ name = %[2]q
139
+ }
140
+
141
+ resource "redshift_user" "user2" {
142
+ name = %[3]q
143
+ }
144
+ ` , groupName , userName1 , userName2 )
145
+ resource .Test (t , resource.TestCase {
146
+ PreCheck : func () { testAccPreCheck (t ) },
147
+ Providers : testAccProviders ,
148
+ CheckDestroy : testAccCheckRedshiftGroupDestroy ,
149
+ Steps : []resource.TestStep {
150
+ {
151
+ Config : configCreate ,
152
+ Check : resource .ComposeTestCheckFunc (
153
+ testAccCheckRedshiftGroupExists (groupName ),
154
+ resource .TestCheckResourceAttr ("redshift_group.group" , "name" , strings .ToLower (groupName )),
155
+ resource .TestCheckResourceAttr ("redshift_group.group" , "users.#" , "2" ),
156
+ resource .TestCheckTypeSetElemAttr ("redshift_group.group" , "users.*" , userName1 ),
157
+ resource .TestCheckTypeSetElemAttr ("redshift_group.group" , "users.*" , userName2 ),
158
+ ),
159
+ },
160
+ {
161
+ Config : configUpdate ,
162
+ Check : resource .ComposeTestCheckFunc (
163
+ testAccCheckRedshiftGroupExists (groupName ),
164
+ resource .TestCheckResourceAttr ("redshift_group.group" , "name" , strings .ToLower (groupName )),
165
+ resource .TestCheckResourceAttr ("redshift_group.group" , "users.#" , "1" ),
166
+ resource .TestCheckTypeSetElemAttr ("redshift_group.group" , "users.*" , userName1 ),
167
+ ),
168
+ },
169
+ },
170
+ })
171
+ }
172
+
106
173
func testAccCheckRedshiftGroupDestroy (s * terraform.State ) error {
107
174
client := testAccProvider .Meta ().(* Client )
108
175
0 commit comments