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

Add API Token Resource #110

Merged
merged 54 commits into from
Jul 23, 2024
Merged

Add API Token Resource #110

merged 54 commits into from
Jul 23, 2024

Conversation

ichung08
Copy link
Collaborator

@ichung08 ichung08 commented Jul 11, 2024

Description

Add API Token resource to terraform.

Supports:

  • Creating an API Token
  • Updating an API Token (name, description and roles)
  • Deleting an API Token

🎟 Issue(s)

#105

🧪 Functional Testing

Create
Screenshot 2024-07-11 at 2 04 49 PM
Screenshot 2024-07-11 at 2 04 58 PM

Update
Screenshot 2024-07-15 at 2 53 48 PM

Delete
Screenshot 2024-07-11 at 2 38 09 PM

📸 Screenshots

📋 Checklist

  • Added/updated applicable tests
  • Added/updated examples in the examples/ directory
  • Updated any related documentation

@ichung08 ichung08 self-assigned this Jul 11, 2024
@ichung08 ichung08 linked an issue Jul 11, 2024 that may be closed by this pull request
@@ -103,6 +103,36 @@ func ApiTokenRoleAttributeTypes() map[string]attr.Type {
}
}

func ResourceApiTokenRoleSchemaAttributes() map[string]resourceSchema.Attribute {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if you look at resource_deployment.go's ValidateConfig
We should have something like that for the roles.

For example, if its an organization token, then it can have any role
If it is a deployment token, it can just have one role
In this we should also check that the role matches the entity. Ie. workspace roles for workspace entities.

Copy link
Collaborator

Choose a reason for hiding this comment

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

we should also add a bunch of error test cases for these in the acceptance tests

@ichung08 ichung08 added this to the Terraform Provider milestone Jul 15, 2024
Roles: []apiTokenRole{
{
Role: string(iam.WORKSPACEOWNER),
EntityId: workspaceId,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
EntityId: workspaceId,
EntityId: organizationId,

Copy link
Collaborator Author

@ichung08 ichung08 Jul 22, 2024

Choose a reason for hiding this comment

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

this is workspaceId intentionally - we want the role to be completely wrong

var invalidRoleError string

for _, role := range roles {
if entityType == string(iam.ApiTokenRoleEntityTypeWORKSPACE) && role.EntityType == iam.ApiTokenRoleEntityTypeORGANIZATION {
Copy link
Collaborator

@vandyliu vandyliu Jul 22, 2024

Choose a reason for hiding this comment

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

can we check that if entityType is organization then the entityId matches r.OrganizationId and add a test case as well for when it doesnt

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we can't include this validation because r.OrganizationId is not set when ValidateConfig is run

Copy link
Collaborator

Choose a reason for hiding this comment

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

can we add that as a comment in the code as well

@ichung08 ichung08 merged commit 1697d2e into main Jul 23, 2024
7 checks passed
@ichung08 ichung08 deleted the 105-add-api-tokens-resource branch July 23, 2024 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add api tokens resource
2 participants