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

NO-TICKET: PR127-scott-doyland #130

Merged
merged 3 commits into from
Dec 3, 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
20 changes: 13 additions & 7 deletions cloudsmith/resource_manage_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ func resourceManageTeamAdd(d *schema.ResourceData, m interface{}) error {
organization := requiredString(d, "organization")
teamName := requiredString(d, "team_name")

teamMembers := d.Get("members").([]interface{})
teamMembersList := make([]cloudsmith.OrganizationTeamMembership, len(teamMembers))
for i, v := range teamMembers {
// Fetching members from the Set, converting to a list
teamMembersSet := d.Get("members").(*schema.Set).List()
teamMembersList := make([]cloudsmith.OrganizationTeamMembership, len(teamMembersSet))

for i, v := range teamMembersSet {
teamMember := v.(map[string]interface{})
teamMembersList[i] = cloudsmith.OrganizationTeamMembership{
Role: teamMember["role"].(string),
Expand Down Expand Up @@ -63,9 +65,11 @@ func resourceManageTeamUpdateRemove(d *schema.ResourceData, m interface{}) error
organization := requiredString(d, "organization")
teamName := requiredString(d, "team_name")

teamMembers := d.Get("members").([]interface{})
teamMembersList := make([]cloudsmith.OrganizationTeamMembership, len(teamMembers))
for i, v := range teamMembers {
// Fetching members from the Set, converting to a list
teamMembersSet := d.Get("members").(*schema.Set).List()
teamMembersList := make([]cloudsmith.OrganizationTeamMembership, len(teamMembersSet))

for i, v := range teamMembersSet {
teamMember := v.(map[string]interface{})
teamMembersList[i] = cloudsmith.OrganizationTeamMembership{
Role: teamMember["role"].(string),
Expand Down Expand Up @@ -117,9 +121,11 @@ func resourceManageTeamRead(d *schema.ResourceData, m interface{}) error {
}
}

// Setting the values into the resource data
d.Set("organization", organization)
d.Set("team_name", teamName)
d.Set("members", members)

// Set the ID to the organization and team name, no slug returned from the API
d.SetId(fmt.Sprintf("%s.%s", organization, teamName))

Expand Down Expand Up @@ -147,7 +153,7 @@ func resourceManageTeam() *schema.Resource {
Required: true,
},
"members": {
Type: schema.TypeList,
Type: schema.TypeSet,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"role": {
Expand Down
12 changes: 6 additions & 6 deletions cloudsmith/resource_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ func TestAccService_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccServiceCheckExists("cloudsmith_service.test"),
resource.TestCheckResourceAttrSet("cloudsmith_service.test", "team.#"),
resource.TestCheckTypeSetElemNestedAttrs("cloudsmith_service.test", "team.*", map[string]string{
"slug": "tf-test-team-svc",
"role": "Member",
resource.TestMatchTypeSetElemNestedAttrs("cloudsmith_service.test", "team.*", map[string]*regexp.Regexp{
"slug": regexp.MustCompile("^tf-test-team-svc(-[^2].*)?$"),
"role": regexp.MustCompile("^Member$"),
}),
),
},
Expand Down Expand Up @@ -161,7 +161,7 @@ resource "cloudsmith_service" "test" {

var testAccServiceConfigBasic = fmt.Sprintf(`
resource "cloudsmith_service" "test" {
name = "TF Test Service"
name = "TF Test Service cs"
organization = "%s"
}
`, os.Getenv("CLOUDSMITH_NAMESPACE"))
Expand All @@ -180,7 +180,7 @@ resource "cloudsmith_team" "test" {
}

resource "cloudsmith_service" "test" {
name = "TF Test Service"
name = "TF Test Service cs"
organization = "%s"
role = "Manager"

Expand All @@ -202,7 +202,7 @@ resource "cloudsmith_team" "test2" {
}

resource "cloudsmith_service" "test" {
name = "TF Test Service"
name = "TF Test Service cs"
organization = "%s"
role = "Manager"

Expand Down
Loading