@@ -391,6 +391,11 @@ func TestAccCloudflareAccountMember_PoliciesAddResourceGroup(t *testing.T) {
391391 domainGroupID1 := createDomainGroup (t , rnd , accountID , zones [0 ].ID )
392392 domainGroupID2 := createDomainGroup (t , rnd , accountID , zones [1 ].ID )
393393
394+ t .Cleanup (func () {
395+ deleteDomainGroup (accountID , domainGroupID1 )
396+ deleteDomainGroup (accountID , domainGroupID2 )
397+ })
398+
394399 resource .Test (t , resource.TestCase {
395400 PreCheck : func () {
396401 acctest .TestAccPreCheck_AccountID (t )
@@ -412,7 +417,46 @@ func TestAccCloudflareAccountMember_PoliciesAddResourceGroup(t *testing.T) {
412417 },
413418 },
414419 {
420+ // Another apply should not cause any changes (stable state)
421+ Config : acctest .LoadTestCase ("cloudflare_account_member-add-resource-group1.tf" , accountID , email , permissionGroupID , domainGroupID1 ),
422+ ConfigPlanChecks : resource.ConfigPlanChecks {
423+ PreApply : []plancheck.PlanCheck {
424+ plancheck .ExpectResourceAction (resourceName , plancheck .ResourceActionNoop ),
425+ },
426+ },
427+ ConfigStateChecks : []statecheck.StateCheck {
428+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New (consts .AccountIDSchemaKey ), knownvalue .StringExact (accountID )),
429+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("email" ), knownvalue .StringExact (email )),
430+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("policies" ), knownvalue .ListSizeExact (1 )),
431+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("policies" ).AtSliceIndex (0 ).AtMapKey ("access" ), knownvalue .StringExact ("allow" )),
432+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("policies" ).AtSliceIndex (0 ).AtMapKey ("permission_groups" ), knownvalue .ListSizeExact (1 )),
433+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("policies" ).AtSliceIndex (0 ).AtMapKey ("permission_groups" ).AtSliceIndex (0 ).AtMapKey ("id" ), knownvalue .StringExact (permissionGroupID )),
434+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("policies" ).AtSliceIndex (0 ).AtMapKey ("resource_groups" ), knownvalue .ListSizeExact (1 )),
435+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("policies" ).AtSliceIndex (0 ).AtMapKey ("resource_groups" ).AtSliceIndex (0 ).AtMapKey ("id" ), knownvalue .StringExact (domainGroupID1 )),
436+ },
437+ },
438+ {
439+ Config : acctest .LoadTestCase ("cloudflare_account_member-add-resource-group2.tf" , accountID , email , permissionGroupID , domainGroupID1 , domainGroupID2 ),
440+ ConfigStateChecks : []statecheck.StateCheck {
441+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New (consts .AccountIDSchemaKey ), knownvalue .StringExact (accountID )),
442+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("email" ), knownvalue .StringExact (email )),
443+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("policies" ), knownvalue .ListSizeExact (1 )),
444+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("policies" ).AtSliceIndex (0 ).AtMapKey ("access" ), knownvalue .StringExact ("allow" )),
445+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("policies" ).AtSliceIndex (0 ).AtMapKey ("permission_groups" ), knownvalue .ListSizeExact (1 )),
446+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("policies" ).AtSliceIndex (0 ).AtMapKey ("permission_groups" ).AtSliceIndex (0 ).AtMapKey ("id" ), knownvalue .StringExact (permissionGroupID )),
447+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("policies" ).AtSliceIndex (0 ).AtMapKey ("resource_groups" ), knownvalue .ListSizeExact (2 )),
448+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("policies" ).AtSliceIndex (0 ).AtMapKey ("resource_groups" ).AtSliceIndex (0 ).AtMapKey ("id" ), knownvalue .StringExact (domainGroupID1 )),
449+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("policies" ).AtSliceIndex (0 ).AtMapKey ("resource_groups" ).AtSliceIndex (1 ).AtMapKey ("id" ), knownvalue .StringExact (domainGroupID2 )),
450+ },
451+ },
452+ {
453+ // Another apply should not cause any changes (stable state)
415454 Config : acctest .LoadTestCase ("cloudflare_account_member-add-resource-group2.tf" , accountID , email , permissionGroupID , domainGroupID1 , domainGroupID2 ),
455+ ConfigPlanChecks : resource.ConfigPlanChecks {
456+ PreApply : []plancheck.PlanCheck {
457+ plancheck .ExpectResourceAction (resourceName , plancheck .ResourceActionNoop ),
458+ },
459+ },
416460 ConfigStateChecks : []statecheck.StateCheck {
417461 statecheck .ExpectKnownValue (resourceName , tfjsonpath .New (consts .AccountIDSchemaKey ), knownvalue .StringExact (accountID )),
418462 statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("email" ), knownvalue .StringExact (email )),
@@ -425,12 +469,14 @@ func TestAccCloudflareAccountMember_PoliciesAddResourceGroup(t *testing.T) {
425469 statecheck .ExpectKnownValue (resourceName , tfjsonpath .New ("policies" ).AtSliceIndex (0 ).AtMapKey ("resource_groups" ).AtSliceIndex (1 ).AtMapKey ("id" ), knownvalue .StringExact (domainGroupID2 )),
426470 },
427471 },
472+ {
473+ ResourceName : resourceName ,
474+ ImportState : true ,
475+ ImportStateVerify : true ,
476+ ImportStateIdPrefix : fmt .Sprintf ("%s/" , accountID ),
477+ },
428478 },
429479 })
430-
431- //cleanup
432- deleteDomainGroup (accountID , domainGroupID1 )
433- deleteDomainGroup (accountID , domainGroupID2 )
434480}
435481
436482func testCloudflareAccountMemberPoliciesConfig (accountID , emailAddress , permgroupId string ) string {
0 commit comments