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

refactor: migrate resource metal_organization_member to framework #588

Merged
merged 3 commits into from
Mar 19, 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
1 change: 0 additions & 1 deletion equinix/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ func Provider() *schema.Provider {
"equinix_metal_project_api_key": resourceMetalProjectAPIKey(),
"equinix_metal_device": resourceMetalDevice(),
"equinix_metal_device_network_type": resourceMetalDeviceNetworkType(),
"equinix_metal_organization_member": resourceMetalOrganizationMember(),
"equinix_metal_port": resourceMetalPort(),
"equinix_metal_project": metal_project.Resource(),
"equinix_metal_reserved_ip_block": resourceMetalReservedIPBlock(),
Expand Down
285 changes: 0 additions & 285 deletions equinix/resource_metal_organization_member.go

This file was deleted.

2 changes: 2 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
metalconnection "github.com/equinix/terraform-provider-equinix/internal/resources/metal/connection"
metalgateway "github.com/equinix/terraform-provider-equinix/internal/resources/metal/gateway"
metalorganization "github.com/equinix/terraform-provider-equinix/internal/resources/metal/organization"
metalorganizationmember "github.com/equinix/terraform-provider-equinix/internal/resources/metal/organization_member"
metalprojectsshkey "github.com/equinix/terraform-provider-equinix/internal/resources/metal/project_ssh_key"
metalsshkey "github.com/equinix/terraform-provider-equinix/internal/resources/metal/ssh_key"
equinix_validation "github.com/equinix/terraform-provider-equinix/internal/validation"
Expand Down Expand Up @@ -116,6 +117,7 @@ func (p *FrameworkProvider) Resources(ctx context.Context) []func() resource.Res
metalsshkey.NewResource,
metalconnection.NewResource,
metalorganization.NewResource,
metalorganizationmember.NewResource,
}
}

Expand Down
77 changes: 77 additions & 0 deletions internal/resources/metal/organization_member/models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package organizationmember

import (
"context"
"path"

"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
)

type ResourceModel struct {
ID types.String `tfsdk:"id"`
Invitee types.String `tfsdk:"invitee"`
InvitedBy types.String `tfsdk:"invited_by"`
OrganizationID types.String `tfsdk:"organization_id"`
ProjectsIDs types.Set `tfsdk:"projects_ids"`
Nonce types.String `tfsdk:"nonce"`
Message types.String `tfsdk:"message"`
Created types.String `tfsdk:"created"`
Updated types.String `tfsdk:"updated"`
Roles types.Set `tfsdk:"roles"`
State types.String `tfsdk:"state"`
}

// func (m *ResourceModel) parse(ctx context.Context, invitee string, members []packngo.Member, invitations []packngo.Invitation) diag.Diagnostics {
func (m *ResourceModel) parse(ctx context.Context, member *member) diag.Diagnostics {
var diags diag.Diagnostics

if member.isMember() {
projectIDs := []string{}
for _, project := range member.Member.Projects {
projectIDs = append(projectIDs, path.Base(project.URL))
}

projectsList, diag := types.SetValueFrom(ctx, types.StringType, projectIDs)
if diag.HasError() {
return diag
}
m.ProjectsIDs = projectsList
m.State = types.StringValue("active")

rolesList, diag := types.SetValueFrom(ctx, types.StringType, member.Member.Roles)
if diag.HasError() {
return diag
}
m.Roles = rolesList
m.OrganizationID = types.StringValue(member.Member.Organization.URL)

} else if member.isInvitation() {
projectIDs := []string{}
for _, project := range member.Invitation.Projects {
projectIDs = append(projectIDs, path.Base(project.Href))
}
projectsList, diag := types.SetValueFrom(ctx, types.StringType, projectIDs)
if diag.HasError() {
return diag
}
m.ProjectsIDs = projectsList

m.State = types.StringValue("invited")

rolesList, diag := types.SetValueFrom(ctx, types.StringType, member.Invitation.Roles)
if diag.HasError() {
return diag
}
m.Roles = rolesList

m.OrganizationID = types.StringValue(path.Base(member.Invitation.Organization.Href))
m.Created = types.StringValue(member.Invitation.CreatedAt.String())
m.Updated = types.StringValue(member.Invitation.UpdatedAt.String())
m.Nonce = types.StringValue(member.Invitation.Nonce)

m.InvitedBy = types.StringValue(path.Base(member.Invitation.InvitedBy.Href))
m.ID = types.StringValue(member.Invitation.ID)
}
return diags
}
Loading
Loading