diff --git a/client/project_members.go b/client/project_members.go index dbd9fce..8dba962 100644 --- a/client/project_members.go +++ b/client/project_members.go @@ -5,8 +5,8 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func ProjectMembersGroupBody(d *schema.ResourceData) models.ProjectMembersBody { - body := models.ProjectMembersBody{ +func ProjectMembersGroupBody(d *schema.ResourceData) models.ProjectMembersBodyPost { + body := models.ProjectMembersBodyPost{ RoleID: RoleType(d.Get("role").(string)), GroupMember: models.ProjectMembersBodyGroup{ GroupType: GroupType(d.Get("type").(string)), @@ -21,8 +21,8 @@ func ProjectMembersGroupBody(d *schema.ResourceData) models.ProjectMembersBody { return body } -func ProjectMembersUserBody(d *schema.ResourceData) models.ProjectMembersBody { - return models.ProjectMembersBody{ +func ProjectMembersUserBody(d *schema.ResourceData) models.ProjectMembersBodyPost { + return models.ProjectMembersBodyPost{ RoleID: RoleType(d.Get("role").(string)), UserMembers: models.ProjectMemberUsersGroup{ UserName: d.Get("user_name").(string), diff --git a/docs/resources/project_member_group.md b/docs/resources/project_member_group.md index a79ef95..87d8e67 100644 --- a/docs/resources/project_member_group.md +++ b/docs/resources/project_member_group.md @@ -7,7 +7,7 @@ resource "harbor_project" "main" { } resource "harbor_project_member_group" "main" { - project_id = harbor_project.main.id + project_id = harbor_project.main.project_id group_name = "testing1" role = "master" type = "oidc" diff --git a/docs/resources/project_member_user.md b/docs/resources/project_member_user.md index 4537adb..bb3954d 100644 --- a/docs/resources/project_member_user.md +++ b/docs/resources/project_member_user.md @@ -7,7 +7,7 @@ resource "harbor_project" "main" { } resource "harbor_project_member_user" "main" { - project_id = harbor_project.main.id + project_id = harbor_project.main.project_id user_name = "testing1" role = "master" } diff --git a/models/project_members.go b/models/project_members.go index 5c5f6f7..1ce8a2d 100644 --- a/models/project_members.go +++ b/models/project_members.go @@ -1,12 +1,20 @@ package models -type ProjectMembersBody struct { +type ProjectMembersBodyPost struct { ID int `json:"id,omitempty"` RoleID int `json:"role_id,omitempty"` GroupMember ProjectMembersBodyGroup `json:"member_group,omitempty"` UserMembers ProjectMemberUsersGroup `json:"member_user,omitempty"` } +type ProjectMembersBodyResponses struct { + ID int `json:"id,omitempty"` + RoleID int `json:"role_id,omitempty"` + ProjectID int `json:"project_id,omitempty"` + EntityType string `json:"entity_type,omitempty"` + EntityName string `json:"entity_name,omitempty"` +} + type ProjectMembersBodyGroup struct { GroupType int `json:"group_type,omitempty"` GroupName string `json:"group_name,omitempty"` @@ -17,3 +25,5 @@ type ProjectMembersBodyGroup struct { type ProjectMemberUsersGroup struct { UserName string `json:"username,omitempty"` } + + diff --git a/provider/resource_project_member_group.go b/provider/resource_project_member_group.go index 609b03b..a9ff606 100644 --- a/provider/resource_project_member_group.go +++ b/provider/resource_project_member_group.go @@ -3,6 +3,7 @@ package provider import ( "encoding/json" "fmt" + "strconv" "github.com/BESTSELLER/terraform-provider-harbor/client" "github.com/BESTSELLER/terraform-provider-harbor/models" @@ -96,13 +97,15 @@ func resourceMembersGroupRead(d *schema.ResourceData, m interface{}) error { return nil } - var jsonData models.ProjectMembersBody + var jsonData models.ProjectMembersBodyResponses err = json.Unmarshal([]byte(resp), &jsonData) if err != nil { return fmt.Errorf("Resource not found %s", d.Id()) } d.Set("role", client.RoleTypeNumber(jsonData.RoleID)) + d.Set("project_id", strconv.Itoa(jsonData.ProjectID)) + d.Set("group_name", jsonData.EntityName) return nil } diff --git a/provider/resource_project_member_group_test.go b/provider/resource_project_member_group_test.go index bce3519..9debb32 100644 --- a/provider/resource_project_member_group_test.go +++ b/provider/resource_project_member_group_test.go @@ -88,7 +88,7 @@ func testAccCheckMemberGroupBasic(projectName string, groupName string) string { } resource "harbor_project_member_group" "main" { - project_id = harbor_project.main.id + project_id = harbor_project.main.project_id group_name = "%s" role = "developer" type = "oidc" @@ -104,7 +104,7 @@ func testAccCheckMemberGroupUpdate(projectName string, groupName string) string } resource "harbor_project_member_group" "main" { - project_id = harbor_project.main.id + project_id = harbor_project.main.project_id group_name = "%s" role = "guest" type = "oidc" diff --git a/provider/resource_project_member_user.go b/provider/resource_project_member_user.go index 1776320..1bf4af1 100644 --- a/provider/resource_project_member_user.go +++ b/provider/resource_project_member_user.go @@ -3,6 +3,7 @@ package provider import ( "encoding/json" "fmt" + "strconv" "github.com/BESTSELLER/terraform-provider-harbor/client" "github.com/BESTSELLER/terraform-provider-harbor/models" @@ -47,7 +48,8 @@ func resourceMembersUser() *schema.Resource { func resourceMembersUserCreate(d *schema.ResourceData, m interface{}) error { apiClient := m.(*client.Client) - path := d.Get("project_id").(string) + "/members" + projectid := checkProjectid(d.Get("project_id").(string)) + path := projectid + "/members" body := client.ProjectMembersUserBody(d) @@ -74,13 +76,15 @@ func resourceMembersUserRead(d *schema.ResourceData, m interface{}) error { return nil } - var jsonData models.ProjectMembersBody + var jsonData models.ProjectMembersBodyResponses err = json.Unmarshal([]byte(resp), &jsonData) if err != nil { return fmt.Errorf("Resource not found %s", d.Id()) } d.Set("role", client.RoleTypeNumber(jsonData.RoleID)) + d.Set("project_id", strconv.Itoa(jsonData.ProjectID)) + d.Set("user_name", jsonData.EntityName) return nil } diff --git a/provider/resource_project_member_user_test.go b/provider/resource_project_member_user_test.go index 13b82aa..fe53fca 100644 --- a/provider/resource_project_member_user_test.go +++ b/provider/resource_project_member_user_test.go @@ -89,7 +89,7 @@ func testAccCheckMemberUserBasic() string { } resource "harbor_project_member_user" "main" { - project_id = harbor_project.main.id + project_id = harbor_project.main.project_id role = "developer" user_name = harbor_user.main.username } @@ -111,7 +111,7 @@ func testAccCheckMemberUserUpdate() string { } resource "harbor_project_member_user" "main" { - project_id = harbor_project.main.id + project_id = harbor_project.main.project_id role = "guest" user_name = harbor_user.main.username }