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 User Invite Resource #120

Merged
merged 6 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions docs/resources/user_invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "astro_user_invite Resource - astro"
subcategory: ""
description: |-
User Invite resource
---

# astro_user_invite (Resource)

User Invite resource

## Example Usage

```terraform
resource "astro_user_invite" "example" {
email = "email@organization.com"
role = "ORGANIZATION_MEMBER"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `email` (String) The email address of the user being invited
- `role` (String) The Organization role to assign to the user

### Read-Only

- `expires_at` (String) The expiration date of the invite
- `invite_id` (String) The ID of the invite
- `invitee` (Attributes) The profile of the invitee (see [below for nested schema](#nestedatt--invitee))
- `inviter` (Attributes) The profile of the inviter (see [below for nested schema](#nestedatt--inviter))
- `user_id` (String) The ID of the user

<a id="nestedatt--invitee"></a>
### Nested Schema for `invitee`

Read-Only:

- `api_token_name` (String)
- `avatar_url` (String)
- `full_name` (String)
- `id` (String)
- `subject_type` (String)
- `username` (String)


<a id="nestedatt--inviter"></a>
### Nested Schema for `inviter`

Read-Only:

- `api_token_name` (String)
- `avatar_url` (String)
- `full_name` (String)
- `id` (String)
- `subject_type` (String)
- `username` (String)
4 changes: 4 additions & 0 deletions examples/resources/astro_user_invite/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "astro_user_invite" "example" {
email = "email@organization.com"
role = "ORGANIZATION_MEMBER"
}
8 changes: 0 additions & 8 deletions internal/provider/datasources/data_source_users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,10 @@ func checkUsers(tfVarName string, filterWorkspaceId bool, filterDeploymentId boo
if instanceState.Attributes[username] == "" {
return fmt.Errorf("expected 'username' to be set")
}
fullName := fmt.Sprintf("users.%d.full_name", usersIdx)
if instanceState.Attributes[fullName] == "" {
return fmt.Errorf("expected 'full_name' to be set")
}
status := fmt.Sprintf("users.%d.status", usersIdx)
if instanceState.Attributes[status] == "" {
return fmt.Errorf("expected 'status' to be set")
}
avatarUrl := fmt.Sprintf("users.%d.avatar_url", usersIdx)
if instanceState.Attributes[avatarUrl] == "" {
return fmt.Errorf("expected 'avatar_url' to be set")
}
Comment on lines -87 to -98
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

when we create new user invites, those users can be found in our org but by default they do not have the fields fullName or avatarUrl populated

removed so the test would not check those fields (as they'll always be empty for user invites)

organizationRole := fmt.Sprintf("users.%d.organization_role", usersIdx)
if instanceState.Attributes[organizationRole] == "" {
return fmt.Errorf("expected 'organization_role' to be set")
Expand Down
38 changes: 38 additions & 0 deletions internal/provider/models/user_invite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package models

import (
"context"

"github.com/astronomer/terraform-provider-astro/internal/clients/iam"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
)

// UserInvite describes the user_invite resource
type UserInvite struct {
Email types.String `tfsdk:"email"`
Role types.String `tfsdk:"role"`
ExpiresAt types.String `tfsdk:"expires_at"`
InviteId types.String `tfsdk:"invite_id"`
Invitee types.Object `tfsdk:"invitee"`
Inviter types.Object `tfsdk:"inviter"`
UserId types.String `tfsdk:"user_id"`
}

func (data *UserInvite) ReadFromResponse(ctx context.Context, userInvite *iam.Invite, email string, role string) diag.Diagnostics {
var diags diag.Diagnostics
data.Email = types.StringValue(email)
data.Role = types.StringValue(role)
data.ExpiresAt = types.StringValue(userInvite.ExpiresAt)
data.InviteId = types.StringValue(userInvite.InviteId)
data.Invitee, diags = SubjectProfileTypesObject(ctx, userInvite.Invitee)
if diags.HasError() {
return diags
}
data.Inviter, diags = SubjectProfileTypesObject(ctx, userInvite.Inviter)
if diags.HasError() {
return diags
}
data.UserId = types.StringPointerValue(userInvite.UserId)
return nil
}
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func (p *AstroProvider) Resources(ctx context.Context) []func() resource.Resourc
resources.NewApiTokenResource,
resources.NewTeamResource,
resources.NewUserRolesResource,
resources.NewUserInviteResource,
}
}

Expand Down
Loading