@@ -171,6 +171,106 @@ resource grafana_folder child2 {
171
171
})
172
172
}
173
173
174
+ func TestAccFolder_ChangeParent (t * testing.T ) {
175
+ testutils .CheckOSSTestsEnabled (t , ">=10.3.0" )
176
+
177
+ var parentFolder models.Folder
178
+ var childFolder1 models.Folder
179
+ name := acctest .RandStringFromCharSet (10 , acctest .CharSetAlpha )
180
+
181
+ resource .ParallelTest (t , resource.TestCase {
182
+ ProtoV5ProviderFactories : testutils .ProtoV5ProviderFactories ,
183
+ CheckDestroy : resource .ComposeTestCheckFunc (
184
+ folderCheckExists .destroyed (& parentFolder , nil ),
185
+ folderCheckExists .destroyed (& childFolder1 , nil ),
186
+ ),
187
+ Steps : []resource.TestStep {
188
+ {
189
+ Config : fmt .Sprintf (`
190
+ resource grafana_folder parent {
191
+ title = "Nested Test: Parent %[1]s"
192
+ }
193
+
194
+ resource grafana_folder child1 {
195
+ title = "Nested Test: Child 1 %[1]s"
196
+ uid = "%[1]s-child1"
197
+ }
198
+ ` , name ),
199
+ Check : resource .ComposeTestCheckFunc (
200
+ folderCheckExists .exists ("grafana_folder.parent" , & parentFolder ),
201
+ resource .TestMatchResourceAttr ("grafana_folder.parent" , "id" , defaultOrgIDRegexp ),
202
+ resource .TestCheckResourceAttr ("grafana_folder.parent" , "title" , "Nested Test: Parent " + name ),
203
+ resource .TestCheckResourceAttr ("grafana_folder.parent" , "parent_folder_uid" , "" ),
204
+
205
+ folderCheckExists .exists ("grafana_folder.child1" , & childFolder1 ),
206
+ resource .TestMatchResourceAttr ("grafana_folder.child1" , "id" , defaultOrgIDRegexp ),
207
+ resource .TestCheckResourceAttr ("grafana_folder.child1" , "title" , "Nested Test: Child 1 " + name ),
208
+ resource .TestCheckResourceAttr ("grafana_folder.child1" , "parent_folder_uid" , "" ),
209
+ ),
210
+ },
211
+ {
212
+ Config : fmt .Sprintf (`
213
+ resource grafana_folder parent {
214
+ title = "Nested Test: Parent %[1]s"
215
+ }
216
+
217
+ resource grafana_folder child1 {
218
+ title = "Nested Test: Child 1 %[1]s"
219
+ uid = "%[1]s-child1"
220
+ parent_folder_uid = grafana_folder.parent.uid
221
+ }
222
+ ` , name ),
223
+ Check : resource .ComposeTestCheckFunc (
224
+ folderCheckExists .exists ("grafana_folder.parent" , & parentFolder ),
225
+ resource .TestMatchResourceAttr ("grafana_folder.parent" , "id" , defaultOrgIDRegexp ),
226
+ resource .TestCheckResourceAttr ("grafana_folder.parent" , "title" , "Nested Test: Parent " + name ),
227
+ resource .TestCheckResourceAttr ("grafana_folder.parent" , "parent_folder_uid" , "" ),
228
+
229
+ folderCheckExists .exists ("grafana_folder.child1" , & childFolder1 ),
230
+ resource .TestMatchResourceAttr ("grafana_folder.child1" , "id" , defaultOrgIDRegexp ),
231
+ resource .TestCheckResourceAttr ("grafana_folder.child1" , "title" , "Nested Test: Child 1 " + name ),
232
+ resource .TestCheckResourceAttrSet ("grafana_folder.child1" , "parent_folder_uid" ),
233
+ ),
234
+ },
235
+ {
236
+ Config : fmt .Sprintf (`
237
+ resource grafana_folder parent {
238
+ title = "Nested Test: Parent %[1]s"
239
+ }
240
+
241
+ resource grafana_folder child1 {
242
+ title = "Nested Test: Child 1 %[1]s"
243
+ uid = "%[1]s-child1"
244
+ }
245
+ ` , name ),
246
+ Check : resource .ComposeTestCheckFunc (
247
+ folderCheckExists .exists ("grafana_folder.parent" , & parentFolder ),
248
+ resource .TestMatchResourceAttr ("grafana_folder.parent" , "id" , defaultOrgIDRegexp ),
249
+ resource .TestCheckResourceAttr ("grafana_folder.parent" , "title" , "Nested Test: Parent " + name ),
250
+ resource .TestCheckResourceAttr ("grafana_folder.parent" , "parent_folder_uid" , "" ),
251
+
252
+ folderCheckExists .exists ("grafana_folder.child1" , & childFolder1 ),
253
+ resource .TestMatchResourceAttr ("grafana_folder.child1" , "id" , defaultOrgIDRegexp ),
254
+ resource .TestCheckResourceAttr ("grafana_folder.child1" , "title" , "Nested Test: Child 1 " + name ),
255
+ resource .TestCheckResourceAttr ("grafana_folder.child1" , "parent_folder_uid" , "" ),
256
+ ),
257
+ },
258
+ {
259
+ ResourceName : "grafana_folder.parent" ,
260
+ ImportState : true ,
261
+ ImportStateVerify : true ,
262
+ ImportStateVerifyIgnore : []string {"prevent_destroy_if_not_empty" },
263
+ },
264
+ {
265
+ ResourceName : "grafana_folder.child1" ,
266
+ ImportState : true ,
267
+ ImportStateVerify : true ,
268
+ ImportStateVerifyIgnore : []string {"prevent_destroy_if_not_empty" },
269
+ },
270
+ },
271
+ })
272
+ }
273
+
174
274
func TestAccFolder_PreventDeletion (t * testing.T ) {
175
275
testutils .CheckOSSTestsEnabled (t , ">=10.2.0" ) // Searching by folder UID was added in 10.2.0
176
276
0 commit comments