Skip to content

Commit

Permalink
fix: Add RequiresReplace for organizationRoleMembershipResource to al…
Browse files Browse the repository at this point in the history
…low changes (#36)
  • Loading branch information
fluff2908 authored Oct 3, 2024
1 parent 0a141f1 commit 705c646
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ resource "sonatypeiq_user" "example" {
resource "sonatypeiq_organization_role_membership" "organization_role_membership" {
organization_id = data.sonatypeiq_organization.sandbox.id
role_id = data.sonatypeiq_role.developer.id
username = sonatypeiq_user.example.username
user_name = sonatypeiq_user.example.username

# group_name can also be used but it is mutually exclusive with the user_name attribute.
# group_name = "developers"
}

14 changes: 14 additions & 0 deletions internal/provider/organization_role_membership_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"

sonatypeiq "github.com/sonatype-nexus-community/nexus-iq-api-client-go"
Expand Down Expand Up @@ -64,18 +66,30 @@ func (r *organizationRoleMembershipResource) Schema(_ context.Context, _ resourc
"role_id": schema.StringAttribute{
Required: true,
Description: "The role ID",
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
"organization_id": schema.StringAttribute{
Required: true,
Description: "The organization ID",
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
"user_name": schema.StringAttribute{
Optional: true,
Description: "The username of the user (mutually exclusive with group_name)",
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
"group_name": schema.StringAttribute{
Optional: true,
Description: "The group name of the group (mutually exclusive with user_name)",
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
},
}
Expand Down
76 changes: 53 additions & 23 deletions internal/provider/organization_role_membership_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,65 @@ func TestAccOrganizationRoleMembershipResource(t *testing.T) {
// Create and Read testing
{
Config: fmt.Sprintf(providerConfig+`
data "sonatypeiq_organization" "sandbox" {
name = "Sandbox Organization"
}
data "sonatypeiq_role" "developer" {
name = "Developer"
}
resource "sonatypeiq_user" "user" {
username = "%s"
password = "randomthing"
first_name = "Example"
last_name = "User"
email = "[email protected]"
}
resource "sonatypeiq_organization_role_membership" "test" {
role_id = data.sonatypeiq_role.developer.id
organization_id = data.sonatypeiq_organization.sandbox.id
user_name = sonatypeiq_user.user.username
}
`, userName),
data "sonatypeiq_organization" "sandbox" {
name = "Sandbox Organization"
}
data "sonatypeiq_role" "developer" {
name = "Developer"
}
resource "sonatypeiq_user" "user" {
username = "%s"
password = "randomthing"
first_name = "Example"
last_name = "User"
email = "[email protected]"
}
resource "sonatypeiq_organization_role_membership" "test" {
role_id = data.sonatypeiq_role.developer.id
organization_id = data.sonatypeiq_organization.sandbox.id
user_name = sonatypeiq_user.user.username
}
`, userName),
Check: resource.ComposeAggregateTestCheckFunc(
// Verify application role membership
resource.TestCheckResourceAttrSet("sonatypeiq_organization_role_membership.test", "id"),
resource.TestCheckResourceAttr("sonatypeiq_organization_role_membership.test", "user_name", userName),
),
},
{
Config: fmt.Sprintf(providerConfig+`
data "sonatypeiq_organization" "sandbox" {
name = "Sandbox Organization"
}
data "sonatypeiq_role" "owner" {
name = "Owner"
}
resource "sonatypeiq_user" "user" {
username = "%s"
password = "randomthing"
first_name = "Example"
last_name = "User"
email = "[email protected]"
}
resource "sonatypeiq_organization_role_membership" "test" {
role_id = data.sonatypeiq_role.owner.id
organization_id = data.sonatypeiq_organization.sandbox.id
user_name = sonatypeiq_user.user.username
}
`, userName),
Check: resource.ComposeAggregateTestCheckFunc(
// Verify application role membership
resource.TestCheckResourceAttr("sonatypeiq_organization_role_membership.test", "role_id", "1cddabf7fdaa47d6833454af10e0a3ef"),
),
},
},
})
}

0 comments on commit 705c646

Please sign in to comment.