Add cloudstack_role_permission resource - #300
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a new Terraform resource for managing individual CloudStack role permission rules (allow/deny) so role ACLs can be managed at per-API (or wildcard) granularity from Terraform.
Changes:
- Adds
cloudstack_role_permissionresource with CRUD support, including in-place updates for allow/deny toggling. - Adds an acceptance test covering basic create + update of the permission attribute.
- Adds end-user documentation and wires the new resource into the website sidebar and provider resource map.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
website/docs/r/role_permission.html.markdown |
Adds documentation for the new cloudstack_role_permission resource, including usage and arguments. |
website/cloudstack.erb |
Adds the resource to the docs sidebar navigation. |
cloudstack/resource_cloudstack_role_permission.go |
Implements the new role-permission Terraform resource (Create/Read/Update/Delete). |
cloudstack/resource_cloudstack_role_permission_test.go |
Adds an acceptance test for create + update behavior. |
cloudstack/provider.go |
Registers the new resource in the provider’s resource map. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| Config: testAccCloudStackRolePermission_update, | ||
| Check: resource.ComposeTestCheckFunc( | ||
| testAccCheckCloudStackRolePermissionExists("cloudstack_role_permission.foo", &rolePermission), | ||
| resource.TestCheckResourceAttr( | ||
| "cloudstack_role_permission.foo", "permission", "deny"), | ||
| ), | ||
| }, |
|
Updating this in a bit, I've got a few issues with the |
d6abfc8 to
c401de6
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Suppressed comments (2)
cloudstack/resource_cloudstack_role_permission.go:204
- With
authoritative = true,Deleteremoves all role permissions, including any that may have been added out-of-band after the last apply. This is a significant behavioral edge case that is not currently documented in the new resource docs; please document this explicitly (or adjust behavior to only delete permissions known to be managed by this resource, if that’s the intended contract).
if d.Get("authoritative").(bool) {
for _, rp := range rolePermissions {
if err := deleteCloudStackRolePermission(cs, rp.Id); err != nil {
return err
}
}
return nil
}
cloudstack/resource_cloudstack_role_permission.go:81
- The schema uses
permissionas both the block name (permission { ... }) and an attribute inside the block (permission = \"allow\"|\"deny\"), which is confusing in configuration and documentation. Since this is a new resource, consider renaming the inner attribute to something unambiguous likeeffect,access, oraction(keepingallow/denyvalues) to improve UX and reduce misreads.
"permission": {
Type: schema.TypeList,
Optional: true,
Description: "Ordered list of role permission rules. Rules are evaluated from top to bottom.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "ID of the role permission.",
},
"rule": {
Type: schema.TypeString,
Required: true,
Description: "The API name or wildcard (e.g. 'list*') the permission applies to.",
},
"permission": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"allow", "deny"}, false),
Description: "Whether the rule is allowed or denied. Valid options are: allow, deny.",
},
There was a problem hiding this comment.
🟡 Not ready to approve
The acceptance test CheckDestroy implementation does not currently validate that managed role-permission rules are actually removed, so delete behavior can regress without failing tests.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Review details
Suppressed comments (1)
cloudstack/resource_cloudstack_role_permission_test.go:274
testAccCheckCloudStackRolePermissionDestroycurrently only verifies thatListRolePermissionsdoesn’t error; it never asserts that managed permission rules were actually removed during destroy. This means the acceptance tests would still pass even if the resource Delete implementation were a no-op.
func testAccCheckCloudStackRolePermissionDestroy(s *terraform.State) error {
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
for _, rs := range s.RootModule().Resources {
if rs.Type != "cloudstack_role_permission" {
- Files reviewed: 5/5 changed files
- Comments generated: 0 new
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
Creates the cloudstack_role_permission resource for managing individual allow/deny rules on a role where previously this was not possible through Terraform. Rules target an API name or wildcard and support in-place toggling between allow and deny without replacement.
Tested on the basic CRUD operations on the simulator and an actual environment.