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

[Feature] Project badge token #213

Open
nimdeveloper opened this issue Oct 16, 2023 · 3 comments
Open

[Feature] Project badge token #213

nimdeveloper opened this issue Oct 16, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@nimdeveloper
Copy link

nimdeveloper commented Oct 16, 2023

It would be great if we had a data source for the badge token so we could use it to set badges automatically.
related API: https://next.sonarqube.com/sonarqube/web_api/api/project_badges/token
Example usage with Gitlab provider:

resource "gitlab_project" "foo" {
  name = "foo-project"
}

data "sonarqube_badge_token" "sample_badge" {
   project = var.project_key
}

resource "gitlab_project_badge" "example" {
  project   = gitlab_project.foo.id
  link_url  = "https://<sonar_host>/dashboard?id=${var.project_key}"
  image_url = "https://<sonar_host>/api/project_badges/measure?project=${var.project_key}&metric=alert_status&token=${data.sonarqube_badge_token.sample_badge.token}"
  name      = "quality-gate-status"
}

Gitlab provider documentation:
https://registry.terraform.io/providers/gitlabhq/gitlab/latest/docs/resources/project_badge

@jdamata
Copy link
Owner

jdamata commented Oct 17, 2023

Are we looking to add a data source for badges? Whats the use case for this?

@nimdeveloper
Copy link
Author

nimdeveloper commented Oct 18, 2023

Are we looking to add a data source for badges? Whats the use case for this?

Sorry, I updated the description; I put an example of what we can do with the badge token. It will be helpful if we have a data source for that.

@jdamata jdamata added the enhancement New feature or request label Oct 18, 2023
@xalagu
Copy link

xalagu commented Nov 30, 2024

Exact same problem !

Need data source or read-only attribute in project resource to find out the sqb_xxxxxx token

as a workaround

data "http" "sonar_badge_token" {
  url      = "${var.SONAR_HOST}/api/project_badges/token?project=${sonarqube_project.your_project.id}"
  request_headers = {
    Authorization = "Bearer ${var.SONAR_TOKEN}"
  }
  lifecycle {
    postcondition {
      condition     = contains([200], self.status_code)
      error_message = "Status code invalid"
    }
  }
}

resource "gitlab_project_badge" "example" {
  project   = gitlab_project.foo.id
  link_url  = "https://<sonar_host>/dashboard?id=${var.project_key}"
  image_url = "https://<sonar_host>/api/project_badges/measure?project=${var.project_key}&metric=alert_status&token=${jsondecode(data.http.sonar_badge_token.response_body).token}"
  name      = "quality-gate-status"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants