Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jaas-role): add jaas' role support #648

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

SimoneDutto
Copy link
Contributor

Description

In this pr we add the support for jaas' roles to the terraform provider.
This pr is very similar to the one for groups. (#570 and #602).

It required upgrading the jimm-go-sdk.

Type of change

  • Add jaas' roles support

@SimoneDutto SimoneDutto changed the title Juju 7235/jaas role feat(jaas-role): add jaas' role support Dec 16, 2024
@SimoneDutto SimoneDutto force-pushed the JUJU-7235/jaas-role branch 4 times, most recently from 0f3519c to 4afaf97 Compare December 18, 2024 14:47
@alesstimec
Copy link
Member

/build

docs/resources/jaas_access_role.md Outdated Show resolved Hide resolved

### Required

- `access` (String) Level of access to grant. Changing this value will replace the Terraform resource. Valid access levels are described at https://canonical-jaas-documentation.readthedocs-hosted.com/en/latest/reference/authorisation_model/#valid-relations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the linked page needs to be updated with valid access levels for roles

Copy link
Contributor Author

@SimoneDutto SimoneDutto Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch, i'll propose a PR to change that page soon

docs/resources/jaas_access_role.md Outdated Show resolved Hide resolved
examples/resources/juju_jaas_access_role/import.sh Outdated Show resolved Hide resolved
examples/resources/juju_jaas_access_role/resource.tf Outdated Show resolved Hide resolved
internal/juju/jaas.go Show resolved Hide resolved
Copy link
Member

@hmlanigan hmlanigan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit messages and pr description must include detail about why the change is being made, not solely what the change is. Be kind to your future self.

The PR description is missing how to test this change.

Was there agreement that we were skipping the process requiring a schema change GitHub issue to be filed and approved before the PR? There are 2 new resources, 1 new data source, and multiple schema changes which should have gone thru this process.

My review is not completed, but passing along the current thoughts. The group resource not using roles needs to be addressed.

Comment on lines +245 to +254
// ReadRoleByUUID attempts to read a role that matches the provided UUID.
func (jc *jaasClient) ReadRoleByUUID(uuid string) (*JaasRole, error) {
return jc.readRole(&params.GetRoleRequest{UUID: uuid})
}

// ReadRoleByName attempts to read a role that matches the provided name.
func (jc *jaasClient) ReadRoleByName(name string) (*JaasRole, error) {
return jc.readRole(&params.GetRoleRequest{Name: name})
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two methods are implementation details. Which the caller shouldn't have to care about. It's cleaner at a package level to have a ReadRole method, then internally decide if it's a UUID or string.

Required: true,
},
"uuid": schema.StringAttribute{
Description: "The UUID of the role.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: add a sentence describing how the uuid could be used.

@@ -121,6 +123,14 @@ func (r *genericJAASAccessResource) partialAccessSchema() map[string]schema.Attr
setvalidator.ValueStringsAre(ValidatorMatchString(jimmnames.IsValidGroupId, "group ID must be valid")),
},
},
"roles": schema.SetAttribute{
Description: "List of roles to grant access.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: update description to include how the roles are specified, name? uuid?

Comment on lines +44 to +46
// set roles to empty set because we don't support assign roles to group
emptyRoleSet, diagEmptySet := types.SetValue(types.StringType, nil)
diag.Append(diagEmptySet...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A different approach is needed if the jaas access group doesn't have roles. If a user does put roles into the jaas access group resource, when you write the data back, terraform cli will error as the values are not the same. I'm surprised testing hasn't revealed a problem here, though the tests haven't been updated for this resource.

@SimoneDutto
Copy link
Contributor Author

@hmlanigan I didn't know we required a process to add a new resource, would you like me to open these issues before addressing the comments here?

@SimoneDutto SimoneDutto requested a review from hmlanigan January 17, 2025 07:51
@hmlanigan
Copy link
Member

@hmlanigan I didn't know we required a process to add a new resource, would you like me to open these issues before addressing the comments here?

I will defer to @alesstimec on this one.

@SimoneDutto
Copy link
Contributor Author

Role data source pr: #654

@SimoneDutto
Copy link
Contributor Author

SimoneDutto commented Jan 20, 2025

Change to resource access schema: #655

@alesstimec alesstimec added the state/codefreeze this pr cannot land until the code freeze has lifted. label Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state/codefreeze this pr cannot land until the code freeze has lifted.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants