Skip to content

Commit

Permalink
Merge pull request #236 from PabloHiro/fix/login_name_template_permis…
Browse files Browse the repository at this point in the history
…sions

fix: missing support for permission_template name instead of id
  • Loading branch information
jdamata authored Jan 24, 2024
2 parents 0e5c623 + f782475 commit 694763e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
4 changes: 4 additions & 0 deletions sonarqube/resource_sonarqube_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func resourceSonarqubePermissionsCreate(d *schema.ResourceData, m interface{}) e
// template user permission
sonarQubeURL.Path = strings.TrimSuffix(sonarQubeURL.Path, "/") + "/api/permissions/add_user_to_template"
RawQuery.Add("templateId", templateID.(string))
// name provide instead of id
} else if templateName, ok := d.GetOk("template_name"); ok {
sonarQubeURL.Path = strings.TrimSuffix(sonarQubeURL.Path, "/") + "/api/permissions/add_user_to_template"
RawQuery.Add("templateName", templateName.(string))
} else {
// direct user permission
sonarQubeURL.Path = strings.TrimSuffix(sonarQubeURL.Path, "/") + "/api/permissions/add_user"
Expand Down
41 changes: 40 additions & 1 deletion sonarqube/resource_sonarqube_permissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func testAccSonarqubePermissionLoginNameConfig(id string, loginName string, perm
name = "%[2]s"
password = "secret-sauce37!"
}
resource "sonarqube_permissions" "%[1]s" {
login_name = sonarqube_user.%[1]s.name
permissions = %[3]s
Expand All @@ -94,3 +94,42 @@ func TestAccSonarqubePermissionLoginName(t *testing.T) {
},
})
}

func testAccSonarqubePermissionLoginNameTemplateNameConfig(id string, loginName string, permissions []string) string {
formattedPermissions := generateHCLList(permissions)
return fmt.Sprintf(`
resource "sonarqube_user" "%[1]s" {
login_name = "%[2]s"
name = "%[2]s"
password = "secret-sauce37!"
}
resource "sonarqube_permission_template" "this" {
name = "foo"
}
resource "sonarqube_permissions" "%[1]s" {
login_name = sonarqube_user.%[1]s.name
template_name = sonarqube_permission_template.this.name
permissions = %[3]s
}
`, id, loginName, formattedPermissions)
}

func TestAccSonarqubePermissionLoginNameTemplateName(t *testing.T) {
rnd := generateRandomResourceName()
name := "sonarqube_permissions." + rnd
permissions := []string{"codeviewer", "scan"}

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccSonarqubePermissionLoginNameTemplateNameConfig(rnd, "testAccSonarqubePermissions", permissions),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "login_name", "testAccSonarqubePermissions"),
),
},
},
})
}

0 comments on commit 694763e

Please sign in to comment.