Skip to content

Commit c86c199

Browse files
ronaldgrnjianyuan
authored andcommitted
prevent deletion of userrole during tests
1 parent 4d4d655 commit c86c199

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

internal/provider/resource_user_role_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ func TestAccUserRoleResource(t *testing.T) {
1818
PreCheck: func() { acctest.PreCheck(t) },
1919
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
2020
Steps: []resource.TestStep{
21+
// Import existing user role
22+
{
23+
Config: testAccUserRoleResourceConfig(acctest.TestUserId, "owner"),
24+
ResourceName: rn,
25+
ImportState: true,
26+
ImportStateId: acctest.TestUserId,
27+
},
2128
{
2229
Config: testAccUserRoleResourceConfig(acctest.TestUserId, "owner"),
2330
ConfigStateChecks: []statecheck.StateCheck{
@@ -32,6 +39,10 @@ func TestAccUserRoleResource(t *testing.T) {
3239
statecheck.ExpectKnownValue(rn, tfjsonpath.New("role"), knownvalue.StringExact("reader")),
3340
},
3441
},
42+
{
43+
// Detach state to prevent deletion of user
44+
Config: testAccUserRoleDetachState(),
45+
},
3546
},
3647
})
3748
}
@@ -41,6 +52,22 @@ func testAccUserRoleResourceConfig(userId, role string) string {
4152
resource "openai_user_role" "test" {
4253
user_id = %[1]q
4354
role = %[2]q
55+
56+
lifecycle {
57+
prevent_destroy = true
58+
}
4459
}
4560
`, userId, role)
4661
}
62+
63+
func testAccUserRoleDetachState() string {
64+
return `
65+
removed {
66+
from = openai_user_role.test
67+
68+
lifecycle {
69+
destroy = false
70+
}
71+
}
72+
`
73+
}

0 commit comments

Comments
 (0)