├── .env.dce.lts.yml ├── .env.dce.yml ├── .github ├── CODE_OF_CONDUCT.md ├── ISSUE_TEMPLATE.md ├── dependabot.yml └── workflows │ ├── acceptance-tests-dce.yml │ ├── acceptance-tests.yml │ ├── codeql-analysis.yml │ ├── release.yaml │ ├── tfplugindocs-check.yml │ └── tfplugindocs-generate.yml ├── .gitignore ├── .goreleaser.yml ├── LICENSE ├── Makefile ├── README.md ├── debugging.md ├── docker-compose-dce.yml ├── docs ├── data-sources │ ├── group.md │ ├── group_members.md │ ├── groups.md │ ├── languages.md │ ├── permission_templates.md │ ├── portfolio.md │ ├── project.md │ ├── qualitygate.md │ ├── qualitygates.md │ ├── qualityprofile.md │ ├── qualityprofiles.md │ ├── rule.md │ ├── user.md │ ├── user_tokens.md │ └── users.md ├── index.md └── resources │ ├── alm_azure.md │ ├── alm_github.md │ ├── alm_gitlab.md │ ├── azure_binding.md │ ├── github_binding.md │ ├── gitlab_binding.md │ ├── group.md │ ├── group_member.md │ ├── new_code_periods.md │ ├── permission_template.md │ ├── permissions.md │ ├── plugin.md │ ├── portfolio.md │ ├── project.md │ ├── project_main_branch.md │ ├── qualitygate.md │ ├── qualitygate_project_association.md │ ├── qualitygate_usergroup_association.md │ ├── qualityprofile.md │ ├── qualityprofile_activate_rule.md │ ├── qualityprofile_project_association.md │ ├── qualityprofile_usergroup_association.md │ ├── rule.md │ ├── setting.md │ ├── user.md │ ├── user_external_identity.md │ ├── user_token.md │ └── webhook.md ├── examples ├── basic-env-vars │ ├── README.md │ └── main.tf ├── basic-module │ ├── README.md │ ├── main.tf │ └── modules │ │ └── example │ │ ├── main.tf │ │ └── variables.tf ├── basic │ ├── README.md │ └── main.tf ├── data-sources │ ├── sonarqube_group │ │ └── data-source.tf │ ├── sonarqube_group_members │ │ └── data-source.tf │ ├── sonarqube_groups │ │ └── data-source.tf │ ├── sonarqube_languages │ │ └── data-source.tf │ ├── sonarqube_permission_templates │ │ └── data-source.tf │ ├── sonarqube_portfolio │ │ └── data-source.tf │ ├── sonarqube_project │ │ └── data-source.tf │ ├── sonarqube_qualitygate │ │ └── data-source.tf │ ├── sonarqube_qualitygates │ │ └── data-source.tf │ ├── sonarqube_qualityprofile │ │ └── data-source.tf │ ├── sonarqube_qualityprofiles │ │ └── data-source.tf │ ├── sonarqube_rule │ │ └── data-source.tf │ ├── sonarqube_user │ │ └── data-source.tf │ ├── sonarqube_user_tokens │ │ └── data-source.tf │ └── sonarqube_users │ │ └── data-source.tf ├── provider │ └── provider.tf └── resources │ ├── sonarqube_alm_azure │ └── resource.tf │ ├── sonarqube_alm_github │ └── resource.tf │ ├── sonarqube_alm_gitlab │ └── resource.tf │ ├── sonarqube_azure_binding │ └── resource.tf │ ├── sonarqube_github_binding │ └── resource.tf │ ├── sonarqube_gitlab_binding │ └── resource.tf │ ├── sonarqube_group │ └── resource.tf │ ├── sonarqube_group_member │ └── resource.tf │ ├── sonarqube_new_code_periods │ ├── global.tf │ └── project.tf │ ├── sonarqube_permission_template │ └── resource.tf │ ├── sonarqube_permissions │ ├── global-admin.tf │ ├── project-admin.tf │ ├── project-template.tf │ └── project-user.tf │ ├── sonarqube_plugin │ └── resource.tf │ ├── sonarqube_portfolio │ └── resource.tf │ ├── sonarqube_project │ ├── project-settings.tf │ └── project.tf │ ├── sonarqube_project_main_branch │ └── resource.tf │ ├── sonarqube_qualitygate │ └── resource.tf │ ├── sonarqube_qualitygate_project_association │ └── resource.tf │ ├── sonarqube_qualitygate_usergroup_association │ ├── user-association.tf │ └── usergroup-association.tf │ ├── sonarqube_qualityprofile │ └── resource.tf │ ├── sonarqube_qualityprofile_activate_rule │ └── resource.tf │ ├── sonarqube_qualityprofile_project_association │ └── resource.tf │ ├── sonarqube_qualityprofile_usergroup_association │ ├── user-association.tf │ └── usergroup-association.tf │ ├── sonarqube_rules │ └── resource.tf │ ├── sonarqube_setting │ ├── multi-field-values.tf │ └── multi-value.tf │ ├── sonarqube_user │ ├── local.tf │ └── remote.tf │ ├── sonarqube_user_external_identity │ └── resource.tf │ ├── sonarqube_user_token │ ├── global-analysis-token.tf │ ├── project-analysis-token.tf │ └── user-token.tf │ └── sonarqube_webhook │ ├── project-webhook.tf │ └── webhook.tf ├── go.mod ├── go.sum ├── main.go ├── sonarqube ├── data_source_sonarqube_group.go ├── data_source_sonarqube_group_members.go ├── data_source_sonarqube_group_members_test.go ├── data_source_sonarqube_group_test.go ├── data_source_sonarqube_groups.go ├── data_source_sonarqube_groups_test.go ├── data_source_sonarqube_languages.go ├── data_source_sonarqube_languages_test.go ├── data_source_sonarqube_permission_templates.go ├── data_source_sonarqube_permission_templates_test.go ├── data_source_sonarqube_portfolio.go ├── data_source_sonarqube_portfolio_test.go ├── data_source_sonarqube_project.go ├── data_source_sonarqube_project_test.go ├── data_source_sonarqube_qualitygate.go ├── data_source_sonarqube_qualitygate_test.go ├── data_source_sonarqube_qualitygates.go ├── data_source_sonarqube_qualitygates_test.go ├── data_source_sonarqube_qualityprofile.go ├── data_source_sonarqube_qualityprofile_test.go ├── data_source_sonarqube_qualityprofiles.go ├── data_source_sonarqube_qualityprofiles_test.go ├── data_source_sonarqube_rule.go ├── data_source_sonarqube_rule_test.go ├── data_source_sonarqube_user.go ├── data_source_sonarqube_user_test.go ├── data_source_sonarqube_user_tokens.go ├── data_source_sonarqube_user_tokens_test.go ├── data_source_sonarqube_users.go ├── data_source_sonarqube_users_test.go ├── helper_test.go ├── httpHelpers.go ├── httpHelpers_test.go ├── provider.go ├── provider_test.go ├── resource_sonarqube_alm_azure.go ├── resource_sonarqube_alm_azure_test.go ├── resource_sonarqube_alm_github.go ├── resource_sonarqube_alm_github_test.go ├── resource_sonarqube_alm_gitlab.go ├── resource_sonarqube_alm_gitlab_test.go ├── resource_sonarqube_azure_binding.go ├── resource_sonarqube_azure_binding_test.go ├── resource_sonarqube_github_binding.go ├── resource_sonarqube_github_binding_test.go ├── resource_sonarqube_gitlab_binding.go ├── resource_sonarqube_gitlab_binding_test.go ├── resource_sonarqube_group.go ├── resource_sonarqube_group_member.go ├── resource_sonarqube_group_member_test.go ├── resource_sonarqube_group_test.go ├── resource_sonarqube_new_code_periods.go ├── resource_sonarqube_new_code_periods_test.go ├── resource_sonarqube_permissions.go ├── resource_sonarqube_permissions_template.go ├── resource_sonarqube_permissions_template_test.go ├── resource_sonarqube_permissions_test.go ├── resource_sonarqube_plugins.go ├── resource_sonarqube_portfolio.go ├── resource_sonarqube_portfolio_test.go ├── resource_sonarqube_project.go ├── resource_sonarqube_project_main_branch.go ├── resource_sonarqube_project_main_branch_test.go ├── resource_sonarqube_project_test.go ├── resource_sonarqube_qualitygate.go ├── resource_sonarqube_qualitygate_project_association.go ├── resource_sonarqube_qualitygate_project_association_test.go ├── resource_sonarqube_qualitygate_test.go ├── resource_sonarqube_qualitygate_usergroup_association.go ├── resource_sonarqube_qualitygate_usergroup_association_test.go ├── resource_sonarqube_qualityprofile.go ├── resource_sonarqube_qualityprofile_activate_rule.go ├── resource_sonarqube_qualityprofile_activate_rule_test.go ├── resource_sonarqube_qualityprofile_project_association.go ├── resource_sonarqube_qualityprofile_project_association_test.go ├── resource_sonarqube_qualityprofile_test.go ├── resource_sonarqube_qualityprofile_usergroup_association.go ├── resource_sonarqube_qualityprofile_usergroup_association_test.go ├── resource_sonarqube_rules.go ├── resource_sonarqube_rules_test.go ├── resource_sonarqube_setting.go ├── resource_sonarqube_setting_test.go ├── resource_sonarqube_user.go ├── resource_sonarqube_user_external_identity.go ├── resource_sonarqube_user_external_identity_test.go ├── resource_sonarqube_user_test.go ├── resource_sonarqube_user_token.go ├── resource_sonarqube_user_token_test.go ├── resource_sonarqube_webhook.go ├── resource_sonarqube_webhook_test.go └── util.go ├── templates ├── index.md.tmpl └── resources │ ├── new_code_periods.md.tmpl │ ├── permissions.md.tmpl │ ├── project.md.tmpl │ ├── qualitygate.md.tmpl │ ├── qualitygate_usergroup_association.md.tmpl │ ├── qualityprofile_usergroup_association.md.tmpl │ ├── setting.md.tmpl │ ├── user.md.tmpl │ ├── user_token.md.tmpl │ └── webhook.md.tmpl └── tools ├── go.mod ├── go.sum └── tools.go /.env.dce.lts.yml: -------------------------------------------------------------------------------- 1 | TAG=lts-datacenter -------------------------------------------------------------------------------- /.env.dce.yml: -------------------------------------------------------------------------------- 1 | TAG=datacenter -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | HashiCorp Community Guidelines apply to you when interacting with the community here on GitHub and contributing code. 4 | 5 | Please read the full text at https://www.hashicorp.com/community-guidelines -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Hi there, 2 | 3 | Thank you for opening an issue. 4 | 5 | ### Terraform Version 6 | Run `terraform -v` to show the version. If you are not running the latest version of Terraform, please upgrade because your issue may have already been fixed. 7 | 8 | ### Affected Resource(s) 9 | Please list the resources as a list, for example: 10 | - sonarqube_group 11 | - sonarqube_project 12 | 13 | ### Terraform Configuration Files 14 | ```hcl 15 | # Copy-paste your Terraform configurations here - for large Terraform configs, 16 | ``` 17 | 18 | ### Expected Behavior 19 | What should have happened? 20 | 21 | ### Actual Behavior 22 | What actually happened? 23 | 24 | ### Steps to Reproduce 25 | Please list the steps required to reproduce the issue, for example: 26 | 1. `terraform apply` 27 | 28 | ### References 29 | Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example: 30 | - GH-1234 31 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "gomod" # See documentation for possible values 4 | directory: "/" # Location of package manifests 5 | schedule: 6 | interval: "daily" 7 | -------------------------------------------------------------------------------- /.github/workflows/acceptance-tests-dce.yml: -------------------------------------------------------------------------------- 1 | name: acceptance-tests-dce 2 | on: 3 | push: 4 | branches: [master] 5 | pull_request: 6 | branches: [master] 7 | jobs: 8 | acceptance-tests: 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | env: [.env.dce.lts.yml, .env.dce.yml] 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v4 17 | - name: Add hosts to /etc/hosts 18 | run: | 19 | sudo echo "127.0.0.1 sonarqube.dev.local" | sudo tee -a /etc/hosts 20 | - name: Start Sonarqube dce 21 | run: docker compose -f docker-compose-dce.yml --env-file ${{ matrix.env }} up -d 22 | - name: Set up Go 23 | uses: actions/setup-go@v5 24 | with: 25 | go-version: 1.24 26 | - name: build and vet the provider 27 | run: make 28 | env: 29 | GO111MODULE: on 30 | - name: Setup terraform 31 | uses: hashicorp/setup-terraform@v3 32 | with: 33 | terraform_wrapper: false 34 | - name: run acceptance tests 35 | run: | 36 | while [[ "$(curl -s -o /dev/null -w "%{http_code}" admin:admin@sonarqube.dev.local/api/system/info)" != "200" ]]; do echo "waiting for SonarQube to start"; sleep 15; done 37 | go test -race -coverprofile=coverage.txt -covermode=atomic ./... 38 | env: 39 | TF_ACC: 1 40 | GO111MODULE: on 41 | SONAR_HOST: http://sonarqube.dev.local 42 | SONAR_USER: admin 43 | SONAR_PASS: admin 44 | INSTALLED_VERSION: 9.9 45 | INSTALLED_EDITION: Datacenter -------------------------------------------------------------------------------- /.github/workflows/acceptance-tests.yml: -------------------------------------------------------------------------------- 1 | name: acceptance-tests 2 | on: 3 | push: 4 | branches: [master] 5 | pull_request: 6 | branches: [master] 7 | jobs: 8 | acceptance-tests: 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | image_tag: [lts-community, lts-developer, lts-enterprise, latest, developer, enterprise] 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v4 17 | - name: Set up Go 18 | uses: actions/setup-go@v5 19 | with: 20 | go-version: 1.24 21 | - name: build and vet the provider 22 | run: make 23 | env: 24 | GO111MODULE: on 25 | - name: Setup terraform 26 | uses: hashicorp/setup-terraform@v3 27 | with: 28 | terraform_wrapper: false 29 | - name: run acceptance tests 30 | run: | 31 | while [[ "$(curl -s -o /dev/null -w "%{http_code}" admin:admin@localhost:9000/api/system/info)" != "200" ]]; do echo "waiting for SonarQube to start"; sleep 15; done 32 | go test -race -coverprofile=coverage.txt -covermode=atomic ./... 33 | env: 34 | TF_ACC: 1 35 | GO111MODULE: on 36 | SONAR_HOST: http://127.0.0.1:9000 37 | SONAR_USER: admin 38 | SONAR_PASS: admin 39 | - name: Run code coverage 40 | if: ${{ github.ref == 'refs/heads/master' && matrix.image_tag == 'enterprise'}} 41 | uses: codecov/codecov-action@v2 42 | services: 43 | sonarqube: 44 | image: sonarqube:${{ matrix.image_tag }} 45 | ports: 46 | - 9000:9000 47 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [master] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [master] 20 | schedule: 21 | - cron: "39 19 * * 0" 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | 28 | strategy: 29 | fail-fast: false 30 | matrix: 31 | language: ["go"] 32 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] 33 | # Learn more: 34 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed 35 | 36 | steps: 37 | - name: Checkout 38 | uses: actions/checkout@v4 39 | 40 | # Initializes the CodeQL tools for scanning. 41 | - name: Initialize CodeQL 42 | uses: github/codeql-action/init@v3 43 | with: 44 | languages: ${{ matrix.language }} 45 | # If you wish to specify custom queries, you can do so here or in a config file. 46 | # By default, queries listed here will override any specified in a config file. 47 | # Prefix the list here with "+" to use these queries and those in the config file. 48 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 49 | 50 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 51 | # If this step fails, then you should remove it and run the build manually (see below) 52 | - name: Autobuild 53 | uses: github/codeql-action/autobuild@v3 54 | 55 | # ℹ️ Command-line programs to run using the OS shell. 56 | # 📚 https://git.io/JvXDl 57 | 58 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 59 | # and modify them (or add more) to build your code if your project 60 | # uses a compiled language 61 | 62 | #- run: | 63 | # make bootstrap 64 | # make release 65 | 66 | - name: Perform CodeQL Analysis 67 | uses: github/codeql-action/analyze@v3 68 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | # This GitHub action can publish assets for release when a tag is created. 2 | # Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0). 3 | # 4 | # This uses an action (paultyng/ghaction-import-gpg) that assumes you set your 5 | # private key in the `GPG_PRIVATE_KEY` secret and passphrase in the `PASSPHRASE` 6 | # secret. If you would rather own your own GPG handling, please fork this action 7 | # or use an alternative one for key handling. 8 | # 9 | # You will need to pass the `--batch` flag to `gpg` in your signing step 10 | # in `goreleaser` to indicate this is being used in a non-interactive mode. 11 | # 12 | name: release 13 | on: 14 | push: 15 | tags: 16 | - "v*" 17 | jobs: 18 | goreleaser: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: Checkout 22 | uses: actions/checkout@v4 23 | - name: Unshallow 24 | run: git fetch --prune --unshallow 25 | - name: Set up Go 26 | uses: actions/setup-go@v5 27 | with: 28 | go-version: 1.24 29 | - name: Import GPG key 30 | id: import_gpg 31 | uses: crazy-max/ghaction-import-gpg@v6.1.0 32 | with: 33 | gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} 34 | passphrase: ${{ secrets.PASSPHRASE }} 35 | - name: Run GoReleaser 36 | uses: goreleaser/goreleaser-action@v6 37 | with: 38 | version: latest 39 | args: release 40 | env: 41 | GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} 42 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 43 | -------------------------------------------------------------------------------- /.github/workflows/tfplugindocs-check.yml: -------------------------------------------------------------------------------- 1 | name: tfplugindocs check 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | tfplugindocs_check: 10 | name: tfplugindocs check 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v4 14 | 15 | - uses: actions/setup-go@v5 16 | with: 17 | go-version-file: tools/go.mod 18 | cache-dependency-path: tools/go.sum 19 | 20 | - run: | 21 | make tools 22 | make docs 23 | git add -N docs/ 24 | git diff --exit-code 25 | -------------------------------------------------------------------------------- /.github/workflows/tfplugindocs-generate.yml: -------------------------------------------------------------------------------- 1 | name: tfplugindocs generate 2 | 3 | on: 4 | pull_request_target: 5 | paths: 6 | - .github/workflows/tfplugindocs-generate.yml 7 | - Makefile 8 | - docs/** 9 | - examples/** 10 | - templates/** 11 | - sonarqube/** 12 | 13 | jobs: 14 | tfplugindocs_generate: 15 | name: tfplugindocs generate 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: Checkout repository code 19 | uses: actions/checkout@v4 20 | with: 21 | persist-credentials: false # don't write token to git config 22 | fetch-depth: 0 23 | ref: '${{ github.head_ref }}' 24 | repository: '${{ github.event.pull_request.head.repo.full_name }}' 25 | 26 | - name: Setup Go with version from tools/go.mod 27 | uses: actions/setup-go@v5 28 | with: 29 | go-version-file: tools/go.mod 30 | cache-dependency-path: tools/go.sum 31 | 32 | - name: Install tools and generate documentation 33 | run: | 34 | make tools 35 | make docs 36 | 37 | - name: Commit and push generated documentation 38 | uses: actions-js/push@v1.5 39 | with: 40 | github_token: ${{ secrets.GITHUB_TOKEN }} 41 | branch: ${{ github.head_ref }} 42 | message: "[skip ci] chore(docs): tfplugindocs generate" 43 | repository: ${{ github.event.pull_request.head.repo.full_name }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # Dependency directories (remove the comment below to include it) 15 | # vendor/ 16 | # 17 | # 18 | terraform-provider-sonarqube 19 | .terraform** 20 | terraform.tfstate 21 | crash.log 22 | terraform.tfstate.backup 23 | terraform.tfstate.*.backup 24 | 25 | coverage.txt 26 | 27 | # dist directory for local testingg 28 | dist/ 29 | .vscode/settings.json 30 | 31 | .DS_Store 32 | 33 | -------------------------------------------------------------------------------- /.goreleaser.yml: -------------------------------------------------------------------------------- 1 | # Visit https://goreleaser.com for documentation on how to customize this 2 | # behavior. 3 | before: 4 | hooks: 5 | # this is just an example and not a requirement for provider building/publishing 6 | - go mod tidy 7 | builds: 8 | - env: 9 | # goreleaser does not work with CGO, it could also complicate 10 | # usage by users in CI/CD systems like Terraform Cloud where 11 | # they are unable to install libraries. 12 | - CGO_ENABLED=0 13 | mod_timestamp: '{{ .CommitTimestamp }}' 14 | flags: 15 | - -trimpath 16 | ldflags: 17 | - '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}' 18 | goos: 19 | - freebsd 20 | - windows 21 | - linux 22 | - darwin 23 | goarch: 24 | - amd64 25 | - '386' 26 | - arm 27 | - arm64 28 | ignore: 29 | - goos: darwin 30 | goarch: '386' 31 | binary: '{{ .ProjectName }}_v{{ .Version }}' 32 | archives: 33 | - formats: [ 'zip' ] 34 | name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}' 35 | checksum: 36 | name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS' 37 | algorithm: sha256 38 | signs: 39 | - artifacts: checksum 40 | args: 41 | # if you are using this in a GitHub action or some other automated pipeline, you 42 | # need to pass the batch flag to indicate its not interactive. 43 | - "--batch" 44 | - "--local-user" 45 | - "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key 46 | - "--output" 47 | - "${signature}" 48 | - "--detach-sign" 49 | - "${artifact}" 50 | release: 51 | # If you want to manually examine the release before its live, uncomment this line: 52 | # draft: true 53 | version: 2 54 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | export GO111MODULE=on 2 | export CGO_ENABLED=1 3 | export TF_LOG=DEBUG 4 | SRC=$(shell find . -name '*.go') 5 | SONARQUBE_IMAGE?=sonarqube:latest 6 | SONARQUBE_START_SLEEP?=60 7 | GO_VER ?= go 8 | 9 | .PHONY: all vet build test tools docs 10 | 11 | all: fmt vet build 12 | 13 | tools: 14 | cd tools && $(GO_VER) install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs 15 | 16 | docs: 17 | @tfplugindocs generate 18 | 19 | build: 20 | go build -a -tags netgo -o terraform-provider-sonarqube 21 | 22 | fmt: 23 | go fmt ./... 24 | 25 | vet: 26 | go vet ./... 27 | 28 | testacc: 29 | docker run --name sonarqube1 -d -p 9001:9000 ${SONARQUBE_IMAGE} 30 | timeout 300 bash -c 'while [[ "$$(curl -s -o /dev/null -w "%{http_code}" admin:admin@localhost:9001/api/system/info)" != "200" ]]; do echo "waiting for SonarQube to start"; sleep 15; done' 31 | -TF_ACC=1 SONAR_HOST=http://localhost:9001 SONAR_USER=admin SONAR_PASS=admin go test -race -coverprofile=coverage.txt -covermode=atomic ./... 32 | docker stop sonarqube1 33 | docker rm sonarqube1 34 | 35 | testacc-no-docker-windows: 36 | # docker run --name sonarqube1 -d -p 9001:9000 sonarqube:latest 37 | set TF_ACC=1\ 38 | && set SONAR_HOST=http://localhost:9001\ 39 | && set SONAR_USER=admin\ 40 | && set SONAR_PASS=admin\ 41 | && go test -race -coverprofile=coverage.txt -covermode=atomic ./... -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # terraform-provider-sonarqube 2 | 3 | [![release](https://github.com/jdamata/terraform-provider-sonarqube/actions/workflows/release.yaml/badge.svg)](https://github.com/jdamata/terraform-provider-sonarqube/actions/workflows/release.yaml) 4 | [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=jdamata_terraform-provider-sonarqube&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=jdamata_terraform-provider-sonarqube) 5 | [![Go Report Card](https://goreportcard.com/badge/github.com/jdamata/terraform-provider-sonarqube)](https://goreportcard.com/report/github.com/jdamata/terraform-provider-sonarqube) 6 | [![codecov](https://codecov.io/gh/jdamata/terraform-provider-sonarqube/branch/master/graph/badge.svg)](https://codecov.io/gh/jdamata/terraform-provider-sonarqube) 7 | [![GPLv3 License](https://img.shields.io/badge/License-GPL%20v3-yellow.svg)](https://opensource.org/licenses/) 8 | 9 | Terraform provider for managing Sonarqube configuration 10 | 11 | This is a community provider and is not supported by Hashicorp. 12 | 13 | ## Installation 14 | 15 | This provider has been published to the Terraform Registry at https://registry.terraform.io/providers/jdamata/sonarqube. Please visit the registry for documentation and installation instructions. 16 | 17 | ## Developing the Provider 18 | 19 | Working on this provider requires the following: 20 | 21 | - [Terraform](https://www.terraform.io/downloads.html) 22 | - [Go](http://www.golang.org) 23 | - [Docker Engine](https://docs.docker.com/engine/install/) 24 | 25 | You will also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH), as well as adding `${GOPATH}/bin` to your `$PATH`. 26 | 27 | To compile the provider, run `make`. This will install the provider into your GOPATH. 28 | 29 | In order to run the full suite of Acceptance tests, run `make -i testacc`. These tests require Docker to be installed on the machine that runs them. The tests do not create any remote resources. 30 | 31 | ```sh 32 | $ make -i testacc 33 | ``` 34 | 35 | ## Generate documentation 36 | 37 | Documentation is generated using `tfplugindocs`. These are auto-generated when creating a PR to the project. 38 | 39 | If you wish to generate documentation locally to verify it's accuracy, run the following commands: 40 | 41 | ```sh 42 | $ make tools 43 | $ make docs 44 | ``` 45 | 46 | ## Debugging the Provider 47 | 48 | See [debugging.md](debugging.md) 49 | -------------------------------------------------------------------------------- /debugging.md: -------------------------------------------------------------------------------- 1 | # Debugging the Provider 2 | 3 | You can debug the provider using a tool similar to [delve](https://github.com/go-delve/delve) as described in the Hashicorp article [Debugger-Based Debugging](https://developer.hashicorp.com/terraform/plugin/debugging#debugger-based-debugging). 4 | 5 | ## Starting a debug session 6 | 7 | ### Visual Studio Code 8 | 9 | Using [Visual Studio Code](https://code.visualstudio.com/) with the [Go extension](https://marketplace.visualstudio.com/items?itemName=golang.go) installed, you would add a configuration similar to this to your `launch.json` file: 10 | 11 | ```json 12 | { 13 | "name": "Debug Terraform Provider", 14 | "type": "go", 15 | "request": "launch", 16 | "mode": "debug", 17 | "program": "${workspaceFolder}", 18 | "env": { 19 | 20 | }, 21 | "args": [ 22 | "-debug" 23 | ], 24 | "showLog": true 25 | } 26 | ``` 27 | 28 | Start the process using this configuration and then follow the instructions provided in the debug console: 29 | 30 | ```shell 31 | Provider started. To attach Terraform CLI, set the TF_REATTACH_PROVIDERS environment variable with the following: 32 | 33 | Command Prompt: set "TF_REATTACH_PROVIDERS={"registry.terraform.io/jdamata/sonarqube":{"Protocol":"grpc","ProtocolVersion":5,"Pid":2748,"Test":true,"Addr":{"Network":"tcp","String":"127.0.0.1:56560"}}}" 34 | 35 | PowerShell: $env:TF_REATTACH_PROVIDERS='{"registry.terraform.io/jdamata/sonarqube":{"Protocol":"grpc","ProtocolVersion":5,"Pid":2748,"Test":true,"Addr":{"Network":"tcp","String":"127.0.0.1:56560"}}}' 36 | ``` 37 | 38 | ### Delve CLI 39 | 40 | With the delve CLI you would start a delve debugging session: 41 | 42 | ```shell 43 | dlv exec --accept-multiclient --continue --headless ./terraform-provider-example -- -debug 44 | ``` 45 | 46 | and copy the line starting `TF_REATTACH_PROVIDERS` from your provider's output, again setting it according to your command prompt/shell. 47 | 48 | ## Attaching to the debug session 49 | 50 | In order to use the debug instance of the provider, set `TF_REATTACH_PROVIDERS` as described previously, set some breakpoints in the provider, and start your terraform script as normal. 51 | 52 | Happy debugging! 53 | -------------------------------------------------------------------------------- /docs/data-sources/group.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_group Data Source - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Use this data source to get a Sonarqube Group resource 7 | --- 8 | 9 | # sonarqube_group (Data Source) 10 | 11 | Use this data source to get a Sonarqube Group resource 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | data "sonarqube_group" "group" { 17 | name = "terraform-test" 18 | } 19 | ``` 20 | 21 | 22 | ## Schema 23 | 24 | ### Required 25 | 26 | - `name` (String) The name of the group. 27 | 28 | ### Read-Only 29 | 30 | - `description` (String) The group description. 31 | - `id` (String) The ID of this resource. 32 | -------------------------------------------------------------------------------- /docs/data-sources/group_members.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_group_members Data Source - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Use this data source to get Sonarqube group member resources 7 | --- 8 | 9 | # sonarqube_group_members (Data Source) 10 | 11 | Use this data source to get Sonarqube group member resources 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | data "sonarqube_group_members" "group_members" { 17 | group = "sonar-users" 18 | ignore_missing = true 19 | } 20 | ``` 21 | 22 | 23 | ## Schema 24 | 25 | ### Required 26 | 27 | - `group` (String) The name of the group. 28 | 29 | ### Optional 30 | 31 | - `ignore_missing` (Boolean) If set to true, the data source will not fail if the group does not exist. 32 | - `login_name` (String) To limit the search to a specific user. 33 | 34 | ### Read-Only 35 | 36 | - `id` (String) The ID of this resource. 37 | - `members` (List of Object) The list of members in the group. (see [below for nested schema](#nestedatt--members)) 38 | 39 | 40 | ### Nested Schema for `members` 41 | 42 | Read-Only: 43 | 44 | - `login_name` (String) 45 | - `name` (String) 46 | -------------------------------------------------------------------------------- /docs/data-sources/groups.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_groups Data Source - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Use this data source to get Sonarqube group resources 7 | --- 8 | 9 | # sonarqube_groups (Data Source) 10 | 11 | Use this data source to get Sonarqube group resources 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | data "sonarqube_groups" "groups" { 17 | 18 | } 19 | ``` 20 | 21 | 22 | ## Schema 23 | 24 | ### Optional 25 | 26 | - `search` (String) Search groups by name. 27 | 28 | ### Read-Only 29 | 30 | - `groups` (List of Object) The list of groups. (see [below for nested schema](#nestedatt--groups)) 31 | - `id` (String) The ID of this resource. 32 | 33 | 34 | ### Nested Schema for `groups` 35 | 36 | Read-Only: 37 | 38 | - `description` (String) 39 | - `name` (String) 40 | -------------------------------------------------------------------------------- /docs/data-sources/languages.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_languages Data Source - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Use this data source to get Sonarqube language resources. 7 | --- 8 | 9 | # sonarqube_languages (Data Source) 10 | 11 | Use this data source to get Sonarqube language resources. 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | data "sonarqube_languages" "languages" { 17 | 18 | } 19 | 20 | data "sonarqube_languages" "languages_java" { 21 | search = "java" 22 | } 23 | ``` 24 | 25 | 26 | ## Schema 27 | 28 | ### Optional 29 | 30 | - `search` (String) Search languages by key or name. 31 | 32 | ### Read-Only 33 | 34 | - `id` (String) The ID of this resource. 35 | - `languages` (List of Object) The list of languages. (see [below for nested schema](#nestedatt--languages)) 36 | 37 | 38 | ### Nested Schema for `languages` 39 | 40 | Read-Only: 41 | 42 | - `key` (String) 43 | - `name` (String) 44 | -------------------------------------------------------------------------------- /docs/data-sources/permission_templates.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_permission_templates Data Source - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Use this data source to get Sonarqube permission templates resources 7 | --- 8 | 9 | # sonarqube_permission_templates (Data Source) 10 | 11 | Use this data source to get Sonarqube permission templates resources 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | data "sonarqube_permission_templates" "permission_templates" { 17 | 18 | } 19 | ``` 20 | 21 | 22 | ## Schema 23 | 24 | ### Optional 25 | 26 | - `search` (String) Search permission templates by name. 27 | 28 | ### Read-Only 29 | 30 | - `id` (String) The ID of this resource. 31 | - `permission_templates` (List of Object) The list of permission templates. (see [below for nested schema](#nestedatt--permission_templates)) 32 | 33 | 34 | ### Nested Schema for `permission_templates` 35 | 36 | Read-Only: 37 | 38 | - `description` (String) 39 | - `id` (String) 40 | - `name` (String) 41 | - `project_key_pattern` (String) 42 | -------------------------------------------------------------------------------- /docs/data-sources/portfolio.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_portfolio Data Source - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Use this data source to get a Sonarqube portfolio resource 7 | --- 8 | 9 | # sonarqube_portfolio (Data Source) 10 | 11 | Use this data source to get a Sonarqube portfolio resource 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | data "sonarqube_portfolio" "portfolio" { 17 | key = "portfolio-key" 18 | } 19 | ``` 20 | 21 | 22 | ## Schema 23 | 24 | ### Required 25 | 26 | - `key` (String) The key of the portfolio 27 | 28 | ### Read-Only 29 | 30 | - `branch` (String) Which branch is analyzed 31 | - `description` (String) Description of the portfolio 32 | - `id` (String) The ID of this resource. 33 | - `name` (String) Name of the portfolio 34 | - `qualifier` (String) `VW` (portfolios always have this qualifier) 35 | - `regexp` (String) The regular expression used to populate the portfolio. Only active when `selection_mode` is `REGEXP` 36 | - `selection_mode` (String) How the Portfolio is populated. Possible values are `NONE`, `MANUAL`, `TAGS`, `REGEXP` or `REST`. [See docs](https://docs.sonarqube.org/9.8/project-administration/managing-portfolios/#populating-portfolios) for how Portfolio population works 37 | - `tags` (List of String) The list of tags used to populate the Portfolio. Only active when `selection_mode` is `TAGS` 38 | - `visibility` (String) Portfolio visibility 39 | -------------------------------------------------------------------------------- /docs/data-sources/project.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_project Data Source - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Use this data source to get a Sonarqube project resource 7 | --- 8 | 9 | # sonarqube_project (Data Source) 10 | 11 | Use this data source to get a Sonarqube project resource 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | data "sonarqube_project" "project" { 17 | project = "projet-key-id" 18 | } 19 | ``` 20 | 21 | 22 | ## Schema 23 | 24 | ### Required 25 | 26 | - `project` (String) The project key of the project 27 | 28 | ### Read-Only 29 | 30 | - `id` (String) The ID of this resource. 31 | - `name` (String) Name of the project 32 | - `visibility` (String) Project visibility 33 | -------------------------------------------------------------------------------- /docs/data-sources/qualitygate.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_qualitygate Data Source - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Use this data source to get a Sonarqube qualitygate resource 7 | --- 8 | 9 | # sonarqube_qualitygate (Data Source) 10 | 11 | Use this data source to get a Sonarqube qualitygate resource 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | data "sonarqube_qualitygate" "main" { 17 | name = "example" 18 | } 19 | ``` 20 | 21 | 22 | ## Schema 23 | 24 | ### Required 25 | 26 | - `name` (String) The name of the Quality Gate. 27 | 28 | ### Read-Only 29 | 30 | - `condition` (List of Object) List of Quality Gate conditions. (see [below for nested schema](#nestedatt--condition)) 31 | - `copy_from` (String) Origin of the Quality Gate 32 | - `id` (String) The ID of this resource. 33 | - `is_default` (Boolean) Quality Gate default. 34 | 35 | 36 | ### Nested Schema for `condition` 37 | 38 | Read-Only: 39 | 40 | - `id` (String) 41 | - `metric` (String) 42 | - `op` (String) 43 | - `threshold` (String) 44 | -------------------------------------------------------------------------------- /docs/data-sources/qualitygates.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_qualitygates Data Source - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Use this data source to get Sonarqube quality gates resources 7 | --- 8 | 9 | # sonarqube_qualitygates (Data Source) 10 | 11 | Use this data source to get Sonarqube quality gates resources 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | data "sonarqube_qualitygates" "qualitygates" { 17 | 18 | } 19 | 20 | data "sonarqube_qualitygates" "qualitygates_sonarway" { 21 | name = "Sonar way" 22 | ignore_missing = true 23 | } 24 | ``` 25 | 26 | 27 | ## Schema 28 | 29 | ### Required 30 | 31 | - `name` (String) Search quality gates by name. 32 | 33 | ### Optional 34 | 35 | - `ignore_missing` (Boolean) If set to true, the data source will not fail if the quality gate does not exist. 36 | 37 | ### Read-Only 38 | 39 | - `id` (String) The ID of this resource. 40 | - `quality_gates` (List of Object) The list of quality gates. (see [below for nested schema](#nestedatt--quality_gates)) 41 | 42 | 43 | ### Nested Schema for `quality_gates` 44 | 45 | Read-Only: 46 | 47 | - `condition` (List of Object) (see [below for nested schema](#nestedobjatt--quality_gates--condition)) 48 | - `copy_from` (String) 49 | - `id` (String) 50 | - `is_default` (Boolean) 51 | - `name` (String) 52 | 53 | 54 | ### Nested Schema for `quality_gates.condition` 55 | 56 | Read-Only: 57 | 58 | - `id` (String) 59 | - `metric` (String) 60 | - `op` (String) 61 | - `threshold` (String) 62 | -------------------------------------------------------------------------------- /docs/data-sources/qualityprofile.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_qualityprofile Data Source - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Use this data source to get a Sonarqube qualityprofile resource 7 | --- 8 | 9 | # sonarqube_qualityprofile (Data Source) 10 | 11 | Use this data source to get a Sonarqube qualityprofile resource 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | data "sonarqube_qualityprofile" "main" { 17 | name = "example" 18 | } 19 | ``` 20 | 21 | 22 | ## Schema 23 | 24 | ### Optional 25 | 26 | - `key` (String) The key of the Quality Profile 27 | - `language` (String) Quality Profile language 28 | - `name` (String) The name of the Quality Profile 29 | 30 | ### Read-Only 31 | 32 | - `id` (String) The ID of this resource. 33 | - `is_default` (Boolean) Quality Profile default 34 | -------------------------------------------------------------------------------- /docs/data-sources/qualityprofiles.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_qualityprofiles Data Source - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Use this data source to get Sonarqube quality profiles resources 7 | --- 8 | 9 | # sonarqube_qualityprofiles (Data Source) 10 | 11 | Use this data source to get Sonarqube quality profiles resources 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | data "sonarqube_qualityprofiles" "qualityprofiles" { 17 | 18 | } 19 | 20 | data "sonarqube_qualityprofiles" "qualityprofiles_sonarway_java" { 21 | name = "Sonar way" 22 | language = "java" 23 | } 24 | ``` 25 | 26 | 27 | ## Schema 28 | 29 | ### Optional 30 | 31 | - `language` (String) Search quality profiles by language. 32 | - `name` (String) Search quality profiles by name. 33 | 34 | ### Read-Only 35 | 36 | - `id` (String) The ID of this resource. 37 | - `quality_profiles` (List of Object) The list of quality profiles. (see [below for nested schema](#nestedatt--quality_profiles)) 38 | 39 | 40 | ### Nested Schema for `quality_profiles` 41 | 42 | Read-Only: 43 | 44 | - `is_default` (Boolean) 45 | - `key` (String) 46 | - `language` (String) 47 | - `name` (String) 48 | -------------------------------------------------------------------------------- /docs/data-sources/rule.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_rule Data Source - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Use this data source to get a Sonarqube rule resource 7 | --- 8 | 9 | # sonarqube_rule (Data Source) 10 | 11 | Use this data source to get a Sonarqube rule resource 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | data "sonarqube_rule" "rule" { 17 | key = "squid:forbidSonar" 18 | } 19 | ``` 20 | 21 | 22 | ## Schema 23 | 24 | ### Required 25 | 26 | - `key` (String) The key of the sonarqube rule. Should be :. https://next.sonarqube.com/sonarqube/web_api/api/rules?query=api%2Frules%2Fcreate 27 | 28 | ### Read-Only 29 | 30 | - `id` (String) The ID of this resource. 31 | - `markdown_description` (String) Rule description 32 | - `name` (String) Rule name 33 | - `severity` (String) Rule severity 34 | - `status` (String) Rule status 35 | - `template_key` (String) Key of the template rule 36 | - `type` (String) Rule type 37 | -------------------------------------------------------------------------------- /docs/data-sources/user.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_user Data Source - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Use this data source to get a Sonarqube User resource 7 | --- 8 | 9 | # sonarqube_user (Data Source) 10 | 11 | Use this data source to get a Sonarqube User resource 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | data "sonarqube_user" "user" { 17 | login_name = "terraform-test" 18 | } 19 | ``` 20 | 21 | 22 | ## Schema 23 | 24 | ### Required 25 | 26 | - `login_name` (String) The login name of the user 27 | 28 | ### Read-Only 29 | 30 | - `email` (String) The email of the user 31 | - `id` (String) The ID of this resource. 32 | - `is_local` (Boolean) Whether the user is local 33 | - `name` (String) The name of the user 34 | -------------------------------------------------------------------------------- /docs/data-sources/user_tokens.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_user_tokens Data Source - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Use this data source to get Sonarqube user token resources 7 | --- 8 | 9 | # sonarqube_user_tokens (Data Source) 10 | 11 | Use this data source to get Sonarqube user token resources 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | data "sonarqube_user_tokens" "user_tokens_admin" { 17 | login = "admin" 18 | } 19 | ``` 20 | 21 | 22 | ## Schema 23 | 24 | ### Optional 25 | 26 | - `ignore_missing` (Boolean) If set to true, the data source will not fail if the user does not exist. 27 | - `login_name` (String) Search user tokens for the specified login name. Otherwise, tokens for the current user are listed. This login must exist and be active. 28 | 29 | ### Read-Only 30 | 31 | - `id` (String) The ID of this resource. 32 | - `user_tokens` (List of Object) The list of user tokens. (see [below for nested schema](#nestedatt--user_tokens)) 33 | 34 | 35 | ### Nested Schema for `user_tokens` 36 | 37 | Read-Only: 38 | 39 | - `created_at` (String) 40 | - `expiration_date` (String) 41 | - `id` (String) 42 | - `name` (String) 43 | - `project_key` (String) 44 | - `type` (String) 45 | -------------------------------------------------------------------------------- /docs/data-sources/users.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_users Data Source - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Use this data source to get Sonarqube user resources 7 | --- 8 | 9 | # sonarqube_users (Data Source) 10 | 11 | Use this data source to get Sonarqube user resources 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | data "sonarqube_users" "users" { 17 | 18 | } 19 | ``` 20 | 21 | 22 | ## Schema 23 | 24 | ### Optional 25 | 26 | - `search` (String) Search users by login, name and email. 27 | 28 | ### Read-Only 29 | 30 | - `id` (String) The ID of this resource. 31 | - `users` (List of Object) The list of users. (see [below for nested schema](#nestedatt--users)) 32 | 33 | 34 | ### Nested Schema for `users` 35 | 36 | Read-Only: 37 | 38 | - `email` (String) 39 | - `is_local` (Boolean) 40 | - `login_name` (String) 41 | - `name` (String) 42 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "Provider: sonarqube" 3 | description: |- 4 | The sonarqube provider is used to configure sonarqube. The provider needs to be configured with a url, and either with user and password or token. 5 | --- 6 | 7 | # Provider configuration 8 | 9 | The sonarqube provider is used to configure sonarqube. The provider needs to be configured with a url, and either with user and password or token. 10 | 11 | ## Example: Authenticate with username and password 12 | 13 | ```terraform 14 | terraform { 15 | required_providers { 16 | sonarqube = { 17 | source = "jdamata/sonarqube" 18 | } 19 | } 20 | } 21 | 22 | provider "sonarqube" { 23 | user = "admin" 24 | pass = "admin" 25 | host = "http://127.0.0.1:9000" 26 | } 27 | ``` 28 | 29 | ## Example: Authenticate with token 30 | 31 | ```terraform 32 | terraform { 33 | required_providers { 34 | sonarqube = { 35 | source = "jdamata/sonarqube" 36 | } 37 | } 38 | } 39 | 40 | provider "sonarqube" { 41 | token = "d4at55a6f7r199bd707h39625685510880gbf7ff" 42 | host = "http://127.0.0.1:9000" 43 | } 44 | ``` 45 | 46 | ## Argument Reference 47 | 48 | The following arguments are supported: 49 | 50 | - `user` - (Optional) Sonarqube user. This can also be set via the `SONARQUBE_USER` environment variable. 51 | - `pass` - (Optional) Sonarqube pass. This can also be set via the `SONARQUBE_PASS` environment variable. 52 | - `token` - (Optional) Sonarqube token. This can also be set via the `SONARQUBE_TOKEN` environment variable. 53 | - `host` - (Required) Sonarqube url. This can be also be set via the `SONARQUBE_HOST` environment variable. 54 | - `installed_version` - (Optional) The version of the Sonarqube server. When specified, the provider will avoid requesting this from the 55 | server during the initialization process. This can be helpful when using the same Terraform code to install Sonarqube and configure it. 56 | - `tls_insecure_skip_verify` - (Optional) Allows ignoring insecure certificates when set to true. Defaults to false. Disabling TLS verification 57 | is dangerous and should only be done for local testing. 58 | - `anonymize_user_on_delete` - (Optional) Allows anonymizing users on destroy. Requires Sonarqube version >= `9.7`. This can be helpful 59 | to comply with regulations like [GDPR](https://en.wikipedia.org/wiki/General_Data_Protection_Regulation). 60 | -------------------------------------------------------------------------------- /docs/resources/alm_azure.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_alm_azure Resource - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Provides a Sonarqube Azure Devops Alm/Devops Platform Integration resource. This can be used to create and manage a Alm/Devops 7 | Platform Integration for Azure Devops. 8 | --- 9 | 10 | # sonarqube_alm_azure (Resource) 11 | 12 | Provides a Sonarqube Azure Devops Alm/Devops Platform Integration resource. This can be used to create and manage a Alm/Devops 13 | Platform Integration for Azure Devops. 14 | 15 | ## Example Usage 16 | 17 | ```terraform 18 | resource "sonarqube_alm_azure" "az1" { 19 | key = "az1" 20 | personal_access_token = "my_pat" 21 | url = "https://dev.azure.com/my-org" 22 | } 23 | ``` 24 | 25 | 26 | ## Schema 27 | 28 | ### Required 29 | 30 | - `key` (String) Unique key of the Azure Devops instance setting 31 | - `personal_access_token` (String, Sensitive) Azure Devops personal access token 32 | - `url` (String) Azure API URL 33 | 34 | ### Read-Only 35 | 36 | - `id` (String) The ID of this resource. 37 | -------------------------------------------------------------------------------- /docs/resources/alm_github.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_alm_github Resource - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Provides a Sonarqube GitHub Alm/Devops Platform Integration resource. This can be used to create and manage a Alm/Devops 7 | Platform Integration for GitHub. 8 | --- 9 | 10 | # sonarqube_alm_github (Resource) 11 | 12 | Provides a Sonarqube GitHub Alm/Devops Platform Integration resource. This can be used to create and manage a Alm/Devops 13 | Platform Integration for GitHub. 14 | 15 | ## Example Usage 16 | 17 | ```terraform 18 | resource "sonarqube_alm_github" "github-alm" { 19 | app_id = "12345" 20 | client_id = "56789" 21 | client_secret = "secret" 22 | key = "myalm" 23 | private_key = "myprivate_key" 24 | url = "https://api.github.com" 25 | webhook_secret = "mysecret" 26 | } 27 | ``` 28 | 29 | 30 | ## Schema 31 | 32 | ### Required 33 | 34 | - `app_id` (String) GitHub App ID. Maximum length: 80 35 | - `client_id` (String) GitHub App Client ID. Maximum length: 80 36 | - `client_secret` (String) GitHub App Client Secret. Maximum length: 160 37 | - `key` (String) Unique key of the GitHUb instance setting. Maximum length: 200 38 | - `private_key` (String) GitHub App private key. Maximum length: 2500 39 | - `url` (String) GitHub API URL. Maximum length: 2000 40 | 41 | ### Optional 42 | 43 | - `webhook_secret` (String) GitHub App Webhook Secret. Maximum length: 160 44 | 45 | ### Read-Only 46 | 47 | - `id` (String) The ID of this resource. 48 | -------------------------------------------------------------------------------- /docs/resources/alm_gitlab.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_alm_gitlab Resource - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Provides a Sonarqube GitLab Alm/Devops Platform Integration resource. This can be used to create and manage a Alm/Devops 7 | Platform Integration for GitLab. 8 | --- 9 | 10 | # sonarqube_alm_gitlab (Resource) 11 | 12 | Provides a Sonarqube GitLab Alm/Devops Platform Integration resource. This can be used to create and manage a Alm/Devops 13 | Platform Integration for GitLab. 14 | 15 | ## Example Usage 16 | 17 | ```terraform 18 | resource "sonarqube_alm_gitlab" "gitlab-alm" { 19 | key = "myalm" 20 | personal_access_token = "my_personal_access_token" 21 | url = "https://gitlab.com/api/v4" 22 | } 23 | ``` 24 | 25 | 26 | ## Schema 27 | 28 | ### Required 29 | 30 | - `key` (String) Unique key of the GitLab instance setting. Maximum length: 200 31 | - `personal_access_token` (String, Sensitive) GitLab App personal access token with the `read_api` scope. See [this doc](https://docs.sonarqube.org/latest/devops-platform-integration/gitlab-integration/#importing-your-gitlab-projects-into-sonarqube) for more information. Maximum length: 2000 32 | - `url` (String) GitLab API URL. Maximum length: 2000 33 | 34 | ### Read-Only 35 | 36 | - `id` (String) The ID of this resource. 37 | -------------------------------------------------------------------------------- /docs/resources/azure_binding.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_azure_binding Resource - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Provides a Sonarqube Azure Devops binding resource. This can be used to create and manage the binding between an 7 | Azure Devops repository and a SonarQube project 8 | --- 9 | 10 | # sonarqube_azure_binding (Resource) 11 | 12 | Provides a Sonarqube Azure Devops binding resource. This can be used to create and manage the binding between an 13 | Azure Devops repository and a SonarQube project 14 | 15 | ## Example Usage 16 | 17 | ```terraform 18 | resource "sonarqube_alm_azure" "az1" { 19 | key = "az1" 20 | personal_access_token = "my_pat" 21 | url = "https://dev.azure.com/my-org" 22 | } 23 | 24 | resource "sonarqube_project" "main" { 25 | name = "SonarQube" 26 | project = "main" 27 | visibility = "public" 28 | } 29 | 30 | resource "sonarqube_azure_binding" "main" { 31 | alm_setting = sonarqube_alm_azure.az1.key 32 | project = sonarqube_project.main.project 33 | project_name = "my_azure_project" 34 | repository_name = "my_repo" 35 | } 36 | ``` 37 | 38 | 39 | ## Schema 40 | 41 | ### Required 42 | 43 | - `alm_setting` (String) Azure DevOps setting key 44 | - `project` (String) SonarQube project key 45 | - `project_name` (String) Azure project name 46 | - `repository_name` (String) Azure repository name 47 | 48 | ### Optional 49 | 50 | - `monorepo` (Boolean) Is this project part of a monorepo 51 | 52 | ### Read-Only 53 | 54 | - `id` (String) The ID of this resource. 55 | -------------------------------------------------------------------------------- /docs/resources/github_binding.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_github_binding Resource - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Provides a Sonarqube GitHub binding resource. This can be used to create and manage the binding between a 7 | GitHub repository and a SonarQube project 8 | --- 9 | 10 | # sonarqube_github_binding (Resource) 11 | 12 | Provides a Sonarqube GitHub binding resource. This can be used to create and manage the binding between a 13 | GitHub repository and a SonarQube project 14 | 15 | ## Example Usage 16 | 17 | ```terraform 18 | resource "sonarqube_alm_github" "github-alm" { 19 | app_id = "12345" 20 | client_id = "56789" 21 | client_secret = "secret" 22 | key = "myalm" 23 | private_key = "myprivate_key" 24 | url = "https://api.github.com" 25 | webhook_secret = "mysecret" 26 | } 27 | 28 | resource "sonarqube_project" "main" { 29 | name = "SonarQube" 30 | project = "my_project" 31 | visibility = "public" 32 | } 33 | resource "sonarqube_github_binding" "github-binding" { 34 | alm_setting = sonarqube_alm_github.github-alm.key 35 | project = "my_project" 36 | repository = "myorg/myrepo" 37 | } 38 | ``` 39 | 40 | 41 | ## Schema 42 | 43 | ### Required 44 | 45 | - `alm_setting` (String) GitHub ALM setting key 46 | - `project` (String) Project key 47 | - `repository` (String) The full name of your GitHub repository, including the organization, case-sensitive. Maximum length: 256 48 | 49 | ### Optional 50 | 51 | - `monorepo` (String) Is this project part of a monorepo. Default value: false 52 | - `summary_comment_enabled` (String) Enable/disable summary in PR discussion tab. Default value: true 53 | 54 | ### Read-Only 55 | 56 | - `id` (String) The ID of this resource. 57 | -------------------------------------------------------------------------------- /docs/resources/gitlab_binding.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_gitlab_binding Resource - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Provides a Sonarqube GitLab binding resource. This can be used to create and manage the binding between a 7 | GitLab repository and a SonarQube project 8 | --- 9 | 10 | # sonarqube_gitlab_binding (Resource) 11 | 12 | Provides a Sonarqube GitLab binding resource. This can be used to create and manage the binding between a 13 | GitLab repository and a SonarQube project 14 | 15 | ## Example Usage 16 | 17 | ```terraform 18 | resource "sonarqube_alm_gitlab" "gitlab-alm" { 19 | key = "myalm" 20 | personal_access_token = "my_personal_access_token" 21 | url = "https://gitlab.com/api/v4" 22 | } 23 | 24 | resource "sonarqube_project" "main" { 25 | name = "SonarQube" 26 | project = "my_project" 27 | visibility = "public" 28 | } 29 | 30 | resource "sonarqube_gitlab_binding" "gitlab-binding" { 31 | alm_setting = sonarqube_alm_gitlab.gitlab-alm.key 32 | project = "my_project" 33 | repository = "123" 34 | } 35 | ``` 36 | 37 | 38 | ## Schema 39 | 40 | ### Required 41 | 42 | - `alm_setting` (String) GitLab ALM setting key 43 | - `project` (String) SonarQube project key. Changing this will force a new resource to be created 44 | - `repository` (String) The GitLab project ID 45 | 46 | ### Optional 47 | 48 | - `monorepo` (String) Is this project part of a monorepo. Default value: false 49 | 50 | ### Read-Only 51 | 52 | - `id` (String) The ID of this resource. 53 | -------------------------------------------------------------------------------- /docs/resources/group.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_group Resource - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Provides a Sonarqube Group resource. This can be used to create and manage Sonarqube Groups. 7 | --- 8 | 9 | # sonarqube_group (Resource) 10 | 11 | Provides a Sonarqube Group resource. This can be used to create and manage Sonarqube Groups. 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | resource "sonarqube_group" "project_users" { 17 | name = "Project-Users" 18 | description = "This is a group" 19 | } 20 | ``` 21 | 22 | 23 | ## Schema 24 | 25 | ### Required 26 | 27 | - `name` (String) The name of the Group to create. Changing this forces a new resource to be created. 28 | 29 | ### Optional 30 | 31 | - `description` (String) Description of the Group. 32 | 33 | ### Read-Only 34 | 35 | - `id` (String) The ID of this resource. 36 | -------------------------------------------------------------------------------- /docs/resources/group_member.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_group_member Resource - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Provides a Sonarqube Group Member resource. This can be used to add or remove user to or from Sonarqube Groups. 7 | --- 8 | 9 | # sonarqube_group_member (Resource) 10 | 11 | Provides a Sonarqube Group Member resource. This can be used to add or remove user to or from Sonarqube Groups. 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | resource "sonarqube_user" "user" { 17 | login_name = "terraform-test" 18 | name = "terraform-test" 19 | password = "secret-sauce37!" 20 | } 21 | 22 | resource "sonarqube_group" "project_users" { 23 | name = "Project-Users" 24 | description = "This is a group" 25 | } 26 | 27 | resource "sonarqube_group_member" "project_users_member" { 28 | name = sonarqube_group.project_users.name 29 | login_name = sonarqube_user.user.login_name 30 | } 31 | ``` 32 | 33 | 34 | ## Schema 35 | 36 | ### Required 37 | 38 | - `login_name` (String) The `login_name` of the User to add as a member. Changing this forces a new resource to be created. 39 | - `name` (String) The name of the Group to add a member to. Changing this forces a new resource to be created. 40 | 41 | ### Read-Only 42 | 43 | - `id` (String) The ID of this resource. 44 | -------------------------------------------------------------------------------- /docs/resources/new_code_periods.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "sonarqube_new_code_periods Resource - terraform-provider-sonarqube" 3 | subcategory: "" 4 | description: |- 5 | Provides a Sonarqube New Code Periods resource. This can be used to manage Sonarqube New Code Periods. 6 | --- 7 | 8 | # sonarqube_new_code_periods (Resource) 9 | 10 | Provides a Sonarqube New Code Periods resource. This can be used to manage Sonarqube New Code Periods. 11 | 12 | ## Example Usage 13 | 14 | ### Example: Set the global new code period to a number of days 15 | ```terraform 16 | resource "sonarqube_new_code_periods" "code_period" { 17 | type = "NUMBER_OF_DAYS" 18 | value = "7" 19 | } 20 | ``` 21 | 22 | ### Example: create a project and set its new code period to a reference branch 23 | ```terraform 24 | resource "sonarqube_project" "reference" { 25 | name = "my-project" 26 | } 27 | 28 | resource "sonarqube_new_code_periods" "reference" { 29 | project = sonarqube_project.reference.project 30 | type = "REFERENCE_BRANCH" 31 | value = "main" 32 | ``` 33 | 34 | 35 | ## Schema 36 | 37 | ### Required 38 | 39 | - `type` (String) The kind of new code period to use. Supported values are SPECIFIC_ANALYSIS, PREVIOUS_VERSION, NUMBER_OF_DAYS, or REFERENCE_BRANCH. 40 | 41 | ### Optional 42 | 43 | - `branch` (String) The name of a branch of a project for which the new code period will be configured. Changing this will force a new resource to be created. Setting this also requires setting the 'project' argument. 44 | - `project` (String) The key of a project for which the new code period will be configured. Changing this will force a new resource to be created. 45 | - `value` (String) The desired value of the new code period. Varies based on the 'type'. For SPECIFIC_ANALYIS, the value must be the UUID of a previous analysis. For NUMBER_OF_DAYS it must be a numeric string. For REFERENCE_BRANCH it should be the name of branch on the project. For PREVIOUS_VERSION it must **not** be set. 46 | 47 | ### Read-Only 48 | 49 | - `id` (String) The ID of this resource. 50 | -------------------------------------------------------------------------------- /docs/resources/permission_template.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_permission_template Resource - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Provides a Sonarqube Permission template resource. This can be used to create and manage Sonarqube Permission 7 | templates. 8 | --- 9 | 10 | # sonarqube_permission_template (Resource) 11 | 12 | Provides a Sonarqube Permission template resource. This can be used to create and manage Sonarqube Permission 13 | templates. 14 | 15 | ## Example Usage 16 | 17 | ```terraform 18 | resource "sonarqube_permission_template" "template" { 19 | name = "Internal-Projects" 20 | description = "These are internal projects" 21 | project_key_pattern = "internal.*" 22 | } 23 | ``` 24 | 25 | 26 | ## Schema 27 | 28 | ### Required 29 | 30 | - `name` (String) The name of the Permission template to create. Do not use names with `/`. If needed, use `replace(var.permission_template_name, "/", "_")`. Changing this forces a new resource to be created. 31 | 32 | ### Optional 33 | 34 | - `default` (Boolean) Set the template as the default. This can only be set for one template. 35 | - `description` (String) Description of the Template. 36 | - `project_key_pattern` (String) The project key pattern. Must be a valid Java regular expression. 37 | 38 | ### Read-Only 39 | 40 | - `id` (String) The ID of this resource. 41 | -------------------------------------------------------------------------------- /docs/resources/permissions.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "sonarqube_permissions Resource - terraform-provider-sonarqube" 3 | subcategory: "" 4 | description: |- 5 | Provides a Sonarqube Permissions resource. This resource can be used to manage global and project permissions. It supports importing using the format 'principal(:scope)' where principal is login_name or group_name or special_group_name and the optional scope is project_key (p_), template_id (t_) or template_name (tn_) with prefixes. Example: group1:tn_test_template_name 6 | --- 7 | 8 | # sonarqube_permissions (Resource) 9 | 10 | Provides a Sonarqube Permissions resource. This resource can be used to manage global and project permissions. It supports importing using the format 'principal(:scope)' where principal is login_name or group_name or special_group_name and the optional scope is project_key (p_), template_id (t_) or template_name (tn_) with prefixes. Example: group1:tn_test_template_name 11 | 12 | ## Example Usage 13 | 14 | ### Example: Set global admin permissions for a group called "my-admins" 15 | ```terraform 16 | resource "sonarqube_permissions" "my_global_admins" { 17 | group_name = "my-admins" 18 | permissions = ["admin"] 19 | } 20 | ``` 21 | 22 | ### Example: Set project admin permissions for a group called "my-project-admins" 23 | ```terraform 24 | resource "sonarqube_permissions" "my_project_admins" { 25 | group_name = "my-project-admins" 26 | project_key = "my-project" 27 | permissions = ["admin"] 28 | } 29 | ``` 30 | 31 | ### Example: Set project admin permissions for a group called "my-project-admins on a permission template" 32 | ```terraform 33 | resource "sonarqube_permissions" "internal_admins" { 34 | group_name = "my-internal-admins" 35 | template_id = sonarqube_permission_template.template.id 36 | permissions = ["admin"] 37 | } 38 | ``` 39 | 40 | ### Example: Set codeviewer & user permissions on project level for a user called "johndoe" 41 | ```terraform 42 | resource "sonarqube_permissions" "john_project_read" { 43 | login_name = "johndoe" 44 | project_key = "my-project" 45 | permissions = ["codeviewer", "user"] 46 | } 47 | ``` 48 | 49 | 50 | ## Schema 51 | 52 | ### Required 53 | 54 | - `permissions` (Set of String) A list of permissions that should be applied. Possible values are: `admin`, `codeviewer`, `issueadmin`, `securityhotspotadmin`, `scan`, `user`. 55 | 56 | ### Optional 57 | 58 | - `group_name` (String) The name of the Group that should get the specified permissions. Changing this forces a new resource to be created. Cannot be used with `login_name` and `special_group_name`. 59 | - `login_name` (String) The name of the user that should get the specified permissions. Changing this forces a new resource to be created. Cannot be used with `group_name` and `special_group_name`. 60 | - `project_key` (String) Specify if you want to apply project level permissions. Changing this forces a new resource to be created. Cannot be used with `special_group_name`, `template_id` and `template_name`. 61 | - `special_group_name` (String) The name of the Special Group that should get the specified permissions. Changing this forces a new resource to be created. Cannot be used with `login_name` and `group_name`. 62 | - `template_id` (String) Specify if you want to apply the permissions to a permission template. Changing this forces a new resource to be created. Cannot be used with `project_key` and `template_name`. 63 | - `template_name` (String) Specify if you want to apply the permissions to a permission template. Changing this forces a new resource to be created. Cannot be used with `project_key` and `template_id`. 64 | 65 | ### Read-Only 66 | 67 | - `id` (String) The ID of this resource. 68 | -------------------------------------------------------------------------------- /docs/resources/plugin.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_plugin Resource - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Provides a Sonarqube Plugin resource. This can be used to create and manage Sonarqube Plugins. 7 | --- 8 | 9 | # sonarqube_plugin (Resource) 10 | 11 | Provides a Sonarqube Plugin resource. This can be used to create and manage Sonarqube Plugins. 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | resource "sonarqube_plugin" "main" { 17 | key = "cloudformation" 18 | } 19 | ``` 20 | 21 | 22 | ## Schema 23 | 24 | ### Required 25 | 26 | - `key` (String) The key identifying the plugin to uninstall. 27 | 28 | ### Read-Only 29 | 30 | - `id` (String) The ID of this resource. 31 | -------------------------------------------------------------------------------- /docs/resources/portfolio.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_portfolio Resource - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Provides a Sonarqube Portfolio resource. This can be used to create and manage Sonarqube Portfolio. Note that the SonarQube API for Portfolios is called views 7 | --- 8 | 9 | # sonarqube_portfolio (Resource) 10 | 11 | Provides a Sonarqube Portfolio resource. This can be used to create and manage Sonarqube Portfolio. Note that the SonarQube API for Portfolios is called ``views`` 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | resource "sonarqube_portfolio" "main" { 17 | key = "portfolio-key" 18 | name = "portfolio-name" 19 | description = "portfolio-description" 20 | } 21 | ``` 22 | 23 | 24 | ## Schema 25 | 26 | ### Required 27 | 28 | - `description` (String) A description of the Portfolio to create 29 | - `key` (String) The key of the Portfolio to create 30 | - `name` (String) The name of the Portfolio to create 31 | 32 | ### Optional 33 | 34 | - `branch` (String) Which branch to analyze. If nothing, or '' is specified, the main branch is used. 35 | - `regexp` (String) A regular expression that is used to match Projects with a matching name OR key. If they match, they are added to the Portfolio 36 | - `selected_projects` (Block Set) A set of projects to add to the portfolio. (see [below for nested schema](#nestedblock--selected_projects)) 37 | - `selection_mode` (String) How to populate the Portfolio to create. Possible values are `NONE`, `MANUAL`, `TAGS`, `REGEXP` or `REST`. [See docs](https://docs.sonarqube.org/9.8/project-administration/managing-portfolios/#populating-portfolios) for how Portfolio population works 38 | - `tags` (List of String) List of Project tags to populate the Portfolio from. Only active when `selection_mode` is `TAGS` 39 | - `visibility` (String) Whether the created portfolio should be visible to everyone, or only specific user/groups. If no visibility is specified, the default portfolio visibility will be `public`. 40 | 41 | ### Read-Only 42 | 43 | - `id` (String) The ID of this resource. 44 | - `qualifier` (String) 45 | 46 | 47 | ### Nested Schema for `selected_projects` 48 | 49 | Required: 50 | 51 | - `project_key` (String) The project key of the project to add to the portfolio 52 | 53 | Optional: 54 | 55 | - `selected_branches` (Set of String) A set of branches for the project to add to the portfolio 56 | -------------------------------------------------------------------------------- /docs/resources/project.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "sonarqube_project Resource - terraform-provider-sonarqube" 3 | subcategory: "" 4 | description: |- 5 | Provides a Sonarqube Project resource. This can be used to create and manage Sonarqube Project. 6 | --- 7 | 8 | # sonarqube_project (Resource) 9 | 10 | Provides a Sonarqube Project resource. This can be used to create and manage Sonarqube Project. 11 | 12 | 13 | ## Example Usage 14 | ### Example: create a project 15 | ```terraform 16 | resource "sonarqube_project" "main" { 17 | name = "SonarQube" 18 | project = "my_project" 19 | visibility = "public" 20 | } 21 | ``` 22 | 23 | ### Example: a project with associated settings 24 | ```terraform 25 | resource "sonarqube_project" "main" { 26 | name = "SonarQube" 27 | project = "my_project" 28 | visibility = "public" 29 | 30 | setting { 31 | key = "sonar.demo" 32 | value = "sonarqube@example.org" 33 | } 34 | } 35 | ``` 36 | 37 | 38 | ## Schema 39 | 40 | ### Required 41 | 42 | - `name` (String) The name of the Project to create 43 | - `project` (String) Key of the project. Maximum length 400. All letters, digits, dash, underscore, period or colon. 44 | 45 | ### Optional 46 | 47 | - `setting` (Block List) A list of settings associated to the project (see [below for nested schema](#nestedblock--setting)) 48 | - `tags` (List of String) A list of tags to put on the project. 49 | - `visibility` (String) Whether the created project should be visible to everyone, or only specific user/groups. If no visibility is specified, the default project visibility of the organization will be used. Valid values are `public` and `private`. 50 | 51 | ### Read-Only 52 | 53 | - `id` (String) The ID of this resource. 54 | 55 | 56 | ### Nested Schema for `setting` 57 | 58 | Required: 59 | 60 | - `key` (String) Setting key 61 | 62 | Optional: 63 | 64 | - `field_values` (List of Map of String) Setting field values for the supplied key 65 | - `value` (String) Setting a value for the supplied key 66 | - `values` (List of String) Setting multi values for the supplied key 67 | -------------------------------------------------------------------------------- /docs/resources/project_main_branch.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_project_main_branch Resource - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Provides a Sonarqube Project main branch resource. This can be used to create and manage a Sonarqube Projects main branch. 7 | --- 8 | 9 | # sonarqube_project_main_branch (Resource) 10 | 11 | Provides a Sonarqube Project main branch resource. This can be used to create and manage a Sonarqube Projects main branch. 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | resource "sonarqube_project" "main" { 17 | name = "SonarQube" 18 | project = "my_project" 19 | visibility = "public" 20 | } 21 | resource "sonarqube_project_main_branch" "mybranch" { 22 | name = "release" 23 | project = "my_project" 24 | } 25 | ``` 26 | 27 | 28 | ## Schema 29 | 30 | ### Required 31 | 32 | - `name` (String) The name you want the main branch to have. 33 | - `project` (String) Key of the project. Maximum length 400. All letters, digits, dash, underscore, period or colon. 34 | 35 | ### Read-Only 36 | 37 | - `id` (String) The ID of this resource. 38 | -------------------------------------------------------------------------------- /docs/resources/qualitygate.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "sonarqube_qualitygate Resource - terraform-provider-sonarqube" 3 | subcategory: "" 4 | description: |- 5 | Provides a Sonarqube Quality Gate resource. This can be used to create and manage Sonarqube Quality Gates and their Conditions. 6 | --- 7 | 8 | # sonarqube_qualitygate (Resource) 9 | 10 | Provides a Sonarqube Quality Gate resource. This can be used to create and manage Sonarqube Quality Gates and their Conditions. 11 | 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | resource "sonarqube_qualitygate" "main" { 17 | name = "example" 18 | is_default = true 19 | 20 | condition { 21 | metric = "new_coverage" 22 | op = "LT" 23 | threshold = "50" 24 | } 25 | 26 | condition { 27 | metric = "vulnerabilities" 28 | threshold = "10" 29 | op = "GT" 30 | } 31 | } 32 | ``` 33 | 34 | **Disclaimer: Operator Requirement for Grade Rating Conditions** 35 | 36 | When working with grade rating conditions, (A-D), it is important to note that the "GT" (greater than) operator must be used for the `op` field. This is due to SonarQube's API design. More information can be found in this [issue](https://github.com/jdamata/terraform-provider-sonarqube/issues/171). 37 | 38 | For example, if you are using a grade rating metric such as `new_reliability_rating`, where A represents the highest rating and subsequent letters represent lower ratings, you need to supply the `op` field with "GT" via the provider. Using "LT" will return an error from SonarQube's API: 39 | 40 | ```terraform 41 | condition { 42 | metric = "new_reliability_rating" 43 | op = "GT" 44 | threshold = "1" 45 | } 46 | ``` 47 | 48 | 49 | ## Schema 50 | 51 | ### Required 52 | 53 | - `name` (String) The name of the Quality Gate to create. Maximum length 100. 54 | 55 | ### Optional 56 | 57 | - `condition` (Block List) A list of conditions that the gate uses. (see [below for nested schema](#nestedblock--condition)) 58 | - `copy_from` (String) Name of an existing Quality Gate to copy from. 59 | - `is_default` (Boolean) When set to true this Quality Gate is set as default. 60 | 61 | ### Read-Only 62 | 63 | - `id` (String) The ID of this resource. 64 | 65 | 66 | ### Nested Schema for `condition` 67 | 68 | Required: 69 | 70 | - `metric` (String) Condition metric. 71 | 72 | Only metrics of the following types are allowed: 73 | 74 | - INT 75 | - MILLISEC 76 | - RATING 77 | - WORK_DUR 78 | - FLOAT 79 | - PERCENT 80 | - LEVEL. 81 | 82 | The following metrics are forbidden: 83 | 84 | - alert_status 85 | - security_hotspots 86 | - new_security_hotspots 87 | - `op` (String) Condition operator. Possible values are: LT and GT 88 | - `threshold` (String) Condition error threshold (For ratings: A=1, B=2, C=3, D=4) 89 | 90 | Read-Only: 91 | 92 | - `id` (String) 93 | -------------------------------------------------------------------------------- /docs/resources/qualitygate_project_association.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_qualitygate_project_association Resource - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Provides a Sonarqube Quality Gate Project association resource. This can be used to associate a Quality Gate to a Project 7 | --- 8 | 9 | # sonarqube_qualitygate_project_association (Resource) 10 | 11 | Provides a Sonarqube Quality Gate Project association resource. This can be used to associate a Quality Gate to a Project 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | ## Example: create a quality gate project association 17 | 18 | resource "sonarqube_qualitygate" "main" { 19 | name = "my_qualitygate" 20 | 21 | condition { 22 | metric = "new_coverage" 23 | op = "LT" 24 | threshold = "30" 25 | } 26 | } 27 | 28 | resource "sonarqube_project" "main" { 29 | name = "SonarQube" 30 | project = "my_project" 31 | visibility = "public" 32 | } 33 | 34 | resource "sonarqube_qualitygate_project_association" "main" { 35 | gatename = sonarqube_qualitygate.main.id 36 | projectkey = sonarqube_project.main.project 37 | } 38 | ``` 39 | 40 | 41 | ## Schema 42 | 43 | ### Required 44 | 45 | - `projectkey` (String) Key of the project. Maximum length 400. All letters, digits, dash, underscore, period or colon. 46 | 47 | ### Optional 48 | 49 | - `gateid` (String) 50 | - `gatename` (String) The name of the Quality Gate 51 | 52 | ### Read-Only 53 | 54 | - `id` (String) The ID of this resource. 55 | -------------------------------------------------------------------------------- /docs/resources/qualitygate_usergroup_association.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "sonarqube_qualitygate_usergroup_association Resource - terraform-provider-sonarqube" 3 | subcategory: "" 4 | description: |- 5 | Provides a Sonarqube Quality Gate Usergroup association resource. This can be used to associate a Quality Gate to an User or to a Group. 6 | The feature is available on SonarQube 9.2 or newer. 7 | --- 8 | 9 | # sonarqube_qualitygate_usergroup_association (Resource) 10 | 11 | Provides a Sonarqube Quality Gate Usergroup association resource. This can be used to associate a Quality Gate to an User or to a Group. 12 | The feature is available on SonarQube 9.2 or newer. 13 | 14 | ## Example Usage 15 | ### Example: create a quality gate user association 16 | ```terraform 17 | resource "sonarqube_qualitygate" "main" { 18 | name = "my_qualitygate" 19 | 20 | condition { 21 | metric = "new_coverage" 22 | op = "LT" 23 | threshold = "30" 24 | } 25 | } 26 | 27 | resource "sonarqube_user" "qa_user" { 28 | login_name = "qa-user" 29 | name = "qa-user" 30 | password = "secret-sauce37!" 31 | } 32 | 33 | resource "sonarqube_qualitygate_usergroup_association" "main" { 34 | gatename = sonarqube_qualitygate.main.id 35 | login_name = sonarqube_user.qa_user.id 36 | } 37 | ``` 38 | 39 | ### Example: create a quality gate group association 40 | ```terraform 41 | resource "sonarqube_qualitygate" "main" { 42 | name = "my_qualitygate" 43 | 44 | condition { 45 | metric = "new_coverage" 46 | op = "LT" 47 | threshold = "30" 48 | } 49 | } 50 | 51 | resource "sonarqube_group" "qa_team" { 52 | name = "QA-Team" 53 | description = "Quality Assurence Team" 54 | } 55 | 56 | resource "sonarqube_qualitygate_usergroup_association" "main" { 57 | gatename = sonarqube_qualitygate.main.id 58 | group_name = sonarqube_group.qa_team.name 59 | } 60 | ``` 61 | 62 | 63 | ## Schema 64 | 65 | ### Required 66 | 67 | - `gatename` (String) The name of the Quality Gate 68 | 69 | ### Optional 70 | 71 | - `group_name` (String) The name of the Group to associate. Either `group_name` or `login_name` should be provided. 72 | - `login_name` (String) The name of the User to associate. Either `group_name` or `login_name` should be provided. 73 | 74 | ### Read-Only 75 | 76 | - `id` (String) The ID of this resource. 77 | -------------------------------------------------------------------------------- /docs/resources/qualityprofile.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_qualityprofile Resource - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Provides a Sonarqube Quality Profile resource. This can be used to create and manage Sonarqube Quality Profiles. 7 | --- 8 | 9 | # sonarqube_qualityprofile (Resource) 10 | 11 | Provides a Sonarqube Quality Profile resource. This can be used to create and manage Sonarqube Quality Profiles. 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | resource "sonarqube_qualityprofile" "main" { 17 | name = "example" 18 | language = "js" 19 | is_default = false 20 | parent = "sonar way" 21 | } 22 | ``` 23 | 24 | 25 | ## Schema 26 | 27 | ### Required 28 | 29 | - `language` (String) Quality profile language. Must be one of "cs", "css", "flex", "go", "java", "js", "jsp", "kotlin", "php", "py", "ruby", "scala", "ts", "vbnet", "web", "xml" 30 | - `name` (String) The name of the Quality Profile to create. Maximum length 100 31 | 32 | ### Optional 33 | 34 | - `is_default` (Boolean) When set to true this will make the added Quality Profile default 35 | - `parent` (String) When a parent is provided the quality profile will inherit it's rules 36 | 37 | ### Read-Only 38 | 39 | - `id` (String) The ID of this resource. 40 | - `key` (String) ID of the Sonarqube Quality Profile 41 | -------------------------------------------------------------------------------- /docs/resources/qualityprofile_activate_rule.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_qualityprofile_activate_rule Resource - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Provides a Sonarqube Rules resource. This can be used to manage Sonarqube rules. 7 | --- 8 | 9 | # sonarqube_qualityprofile_activate_rule (Resource) 10 | 11 | Provides a Sonarqube Rules resource. This can be used to manage Sonarqube rules. 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | resource "sonarqube_rule" "allowed_maven_dependencies" { 17 | custom_key = "Only_use_allowed_Maven_dependencies" 18 | markdown_description = "Description" 19 | name = "Only use allowed Maven dependencies" 20 | params = "FilePattern=**/pom.xml" 21 | severity = "BLOCKER" 22 | status = "READY" 23 | template_key = "xml:XPathCheck" 24 | type = "VULNERABILITY" 25 | } 26 | 27 | resource "sonarqube_qualityprofile" "xml" { 28 | name = "test way - xml" 29 | language = "xml" 30 | is_default = "false" 31 | parent = "Sonar way" 32 | } 33 | 34 | resource "sonarqube_qualityprofile_activate_rule" "xml_rule" { 35 | key = sonarqube_qualityprofile.xml.key # .id also works 36 | rule = sonarqube_rule.allowed_maven_dependencies.id 37 | severity = "BLOCKER" 38 | } 39 | ``` 40 | 41 | 42 | ## Schema 43 | 44 | ### Required 45 | 46 | - `key` (String) Quality Profile key. Can be obtained through api/qualityprofiles/search 47 | - `rule` (String) Rule key 48 | 49 | ### Optional 50 | 51 | - `params` (String) Parameters as semi-colon list of =, for example 'params=key1=v1;key2=v2' (Only for custom rule) 52 | - `reset` (String) Reset severity and parameters of activated rule. Set the values defined on parent profile or from rule default values. 53 | - Possible values true false yes no (Default false) 54 | - `severity` (String) Severity. Ignored if parameter reset is true. 55 | - Possible values - INFO, MINOR, MAJOR, CRITICAL, BLOCKER 56 | 57 | ### Read-Only 58 | 59 | - `id` (String) The ID of this resource. 60 | -------------------------------------------------------------------------------- /docs/resources/qualityprofile_project_association.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_qualityprofile_project_association Resource - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Provides a Sonarqube Quality Profile Project association resource. This can be used to associate a Quality Profile to a Project 7 | --- 8 | 9 | # sonarqube_qualityprofile_project_association (Resource) 10 | 11 | Provides a Sonarqube Quality Profile Project association resource. This can be used to associate a Quality Profile to a Project 12 | 13 | ## Example Usage 14 | 15 | ```terraform 16 | resource "sonarqube_qualityprofile" "main" { 17 | name = "my_quality_profile" 18 | language = "js" 19 | } 20 | 21 | resource "sonarqube_project" "main" { 22 | name = "SonarQube" 23 | project = "my_project" 24 | visibility = "public" 25 | } 26 | 27 | resource "sonarqube_qualityprofile_project_association" "main" { 28 | quality_profile = sonarqube_qualityprofile.main.name 29 | project = sonarqube_project.main.project 30 | language = "js" 31 | } 32 | ``` 33 | 34 | 35 | ## Schema 36 | 37 | ### Required 38 | 39 | - `language` (String) Quality profile language. Must be a langauge in this list https://next.sonarqube.com/sonarqube/web_api/api/languages/list 40 | - `project` (String) Name of the project 41 | - `quality_profile` (String) Name of the Quality Profile 42 | 43 | ### Read-Only 44 | 45 | - `id` (String) The ID of this resource. 46 | -------------------------------------------------------------------------------- /docs/resources/qualityprofile_usergroup_association.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "sonarqube_qualityprofile_usergroup_association Resource - terraform-provider-sonarqube" 3 | subcategory: "" 4 | description: |- 5 | Provides a Sonarqube Quality Profile Usergroup association resource. This can be used to associate a Quality Profile to an User or to a Group. 6 | The feature is available on SonarQube 6.6 or newer. 7 | --- 8 | 9 | # sonarqube_qualityprofile_usergroup_association (Resource) 10 | 11 | Provides a Sonarqube Quality Profile Usergroup association resource. This can be used to associate a Quality Profile to an User or to a Group. 12 | The feature is available on SonarQube 6.6 or newer. 13 | 14 | ## Example Usage 15 | ### Example: create a quality profile user association 16 | ```terraform 17 | resource "sonarqube_qualityprofile" "main" { 18 | name = "my_qualityprofile" 19 | language = "java" 20 | parent = "Sonar way" 21 | } 22 | 23 | resource "sonarqube_user" "qa_user" { 24 | login_name = "qa-user" 25 | name = "qa-user" 26 | password = "secret-sauce37!" 27 | } 28 | 29 | resource "sonarqube_qualityprofile_usergroup_association" "main" { 30 | profile_name = sonarqube_qualityprofile.main.id 31 | language = sonarqube_qualityprofile.language.id 32 | login_name = sonarqube_user.qa_user.id 33 | } 34 | ``` 35 | 36 | ### Example: create a quality profile group association 37 | ```terraform 38 | resource "sonarqube_qualityprofile" "main" { 39 | name = "my_qualityprofile" 40 | language = "java" 41 | parent = "Sonar way" 42 | } 43 | 44 | resource "sonarqube_group" "qa_team" { 45 | name = "QA-Team" 46 | description = "Quality Assurence Team" 47 | } 48 | 49 | resource "sonarqube_qualityprofile_usergroup_association" "main" { 50 | profile_name = sonarqube_qualityprofile.main.id 51 | language = sonarqube_qualityprofile.language.id 52 | group_name = sonarqube_group.qa_team.name 53 | } 54 | ``` 55 | 56 | 57 | ## Schema 58 | 59 | ### Required 60 | 61 | - `language` (String) The language of the Quality Profile. 62 | - `profile_name` (String) The name of the Quality Profile. 63 | 64 | ### Optional 65 | 66 | - `group_name` (String) The name of the Group to associate. Either `group_name` or `login_name` should be provided. 67 | - `login_name` (String) The name of the User to associate. Either `group_name` or `login_name` should be provided. 68 | 69 | ### Read-Only 70 | 71 | - `id` (String) The ID of this resource. 72 | -------------------------------------------------------------------------------- /docs/resources/rule.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_rule Resource - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Provides a Sonarqube Rules resource. This can be used to manage Sonarqube rules. 7 | --- 8 | 9 | # sonarqube_rule (Resource) 10 | 11 | Provides a Sonarqube Rules resource. This can be used to manage Sonarqube rules. 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - `custom_key` (String) key of the custom rule should only contain : a-z, 0-9, \_ 21 | - `markdown_description` (String) Rule description 22 | - `name` (String) Rule name 23 | - `template_key` (String) Key of the template rule in order to create a custom rule (mandatory for custom rule) 24 | - [Example values](https://docs.sonarqube.org/latest/user-guide/rules/#header-4) 25 | 26 | ### Optional 27 | 28 | - `params` (String) Parameters as semi-colon list of =, for example 'params=key1=v1;key2=v2' (Only for custom rule) 29 | - parameter order: expression=value;filePattern=value;message=value 30 | - `prevent_reactivation` (String) If set to true and if the rule has been deactivated (status 'REMOVED'), a status 409 will be returned 31 | - Possible values - true, false, yes, no 32 | - `severity` (String) Rule severity 33 | - Possible values - INFO, MINOR, MAJOR, CRITICAL, BLOCKER 34 | - `status` (String) Rule status 35 | - Possible values - BETA, DEPRECATED, READY, REMOVED 36 | - Default value - READY 37 | - `type` (String) Rule type 38 | - Possible values - CODE_SMELL, BUG, VULNERABILITY, SECURITY_HOTSPOT 39 | 40 | ### Read-Only 41 | 42 | - `id` (String) The ID of this resource. 43 | -------------------------------------------------------------------------------- /docs/resources/setting.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "sonarqube_setting Resource - terraform-provider-sonarqube" 3 | subcategory: "" 4 | description: |- 5 | Provides a Sonarqube Settings resource. This can be used to manage Sonarqube settings. 6 | --- 7 | 8 | # sonarqube_setting (Resource) 9 | 10 | Provides a Sonarqube Settings resource. This can be used to manage Sonarqube settings. 11 | 12 | ## Example Usage 13 | ### Example: create a setting with multiple values 14 | ```terraform 15 | resource "sonarqube_setting" "multi_value_setting" { 16 | key = "sonar.global.exclusions" 17 | values = ["foo", "bar/**/*.*"] 18 | } 19 | ``` 20 | 21 | ### Example: create a setting with multiple field values 22 | ```terraform 23 | resource "sonarqube_setting" "multi_field_setting" { 24 | key = "sonar.issue.ignore.multicriteria" 25 | field_values = [ 26 | { 27 | "ruleKey" : "foo", 28 | "resourceKey" : "bar" 29 | }, 30 | { 31 | "ruleKey" : "foo2", 32 | "resourceKey" : "bar2" 33 | } 34 | ] 35 | } 36 | ``` 37 | 38 | 39 | ## Schema 40 | 41 | ### Required 42 | 43 | - `key` (String) Setting key 44 | 45 | ### Optional 46 | 47 | - `field_values` (List of Map of String) Setting field values for the supplied key 48 | - `value` (String) Setting value. To reset a value, please use the reset web service. 49 | - `values` (List of String) Setting multi values for the supplied key 50 | 51 | ### Read-Only 52 | 53 | - `id` (String) The ID of this resource. 54 | -------------------------------------------------------------------------------- /docs/resources/user.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "sonarqube_user Resource - terraform-provider-sonarqube" 3 | subcategory: "" 4 | description: |- 5 | Provides a Sonarqube User resource. This can be used to manage Sonarqube Users. 6 | --- 7 | 8 | # sonarqube_user (Resource) 9 | 10 | Provides a Sonarqube User resource. This can be used to manage Sonarqube Users. 11 | 12 | ## Example Usage 13 | ### Example: create a local user 14 | ```terraform 15 | resource "sonarqube_user" "user" { 16 | login_name = "terraform-test" 17 | name = "terraform-test" 18 | password = "secret-sauce37!" 19 | } 20 | ``` 21 | 22 | ### Example: create a remote user 23 | ```terraform 24 | resource "sonarqube_user" "remote_user" { 25 | login_name = "terraform-test" 26 | name = "terraform-test" 27 | email = "terraform-test@sonarqube.com" 28 | is_local = false 29 | } 30 | ``` 31 | 32 | 33 | ## Schema 34 | 35 | ### Required 36 | 37 | - `login_name` (String) The login name of the User to create. Changing this forces a new resource to be created. 38 | - `name` (String) The name of the User to create. Changing this forces a new resource to be created. 39 | 40 | ### Optional 41 | 42 | - `email` (String) The email of the User to create. 43 | - `is_local` (Boolean) `True` if the User should be of type `local`. Defaults to `true`. 44 | - `password` (String, Sensitive) The password of User to create. This is only used if the user is of type `local`. 45 | 46 | ### Read-Only 47 | 48 | - `id` (String) The ID of this resource. 49 | -------------------------------------------------------------------------------- /docs/resources/user_external_identity.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "sonarqube_user_external_identity Resource - terraform-provider-sonarqube" 4 | subcategory: "" 5 | description: |- 6 | Updates the external identity of a non local Sonarqube User. This can be used to set the Identity Provider which should be used to 7 | authenticate a specific user. 8 | The Sonarqube API currently does not provide an endpoint to read the external identity setting of an user. 9 | --- 10 | 11 | # sonarqube_user_external_identity (Resource) 12 | 13 | Updates the _external identity_ of a _non local_ Sonarqube User. This can be used to set the _Identity Provider_ which should be used to 14 | authenticate a specific user. 15 | 16 | The Sonarqube API currently does not provide an endpoint to read the _external identity_ setting of an user. 17 | 18 | ## Example Usage 19 | 20 | ```terraform 21 | ## Example: change the external identity to SAML 22 | 23 | resource "sonarqube_user" "remote_user" { 24 | login_name = "terraform-test" 25 | name = "terraform-test" 26 | email = "terraform-test@sonarqube.com" 27 | is_local = false 28 | } 29 | 30 | resource "sonarqube_user_external_identity" "remote_user" { 31 | login_name = sonarqube_user.remote_user.login_name 32 | external_identity = "terraform-test@sonarqube.com" 33 | external_provider = "saml" 34 | } 35 | ``` 36 | 37 | 38 | ## Schema 39 | 40 | ### Required 41 | 42 | - `external_identity` (String) The identifier of the User used by the Authentication Provider. Changing this forces a new resource to be created. 43 | - `external_provider` (String) The key of the Authentication Provider. The Authentication Provider must be activated on Sonarqube. Changing this forces a new resource to be created. 44 | - `login_name` (String) The login name of the User to update. Changing this forces a new resource to be created. 45 | 46 | ### Read-Only 47 | 48 | - `id` (String) The ID of this resource. 49 | -------------------------------------------------------------------------------- /docs/resources/user_token.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "sonarqube_user_token Resource - terraform-provider-sonarqube" 3 | subcategory: "" 4 | description: |- 5 | Provides a Sonarqube User token resource. This can be used to manage Sonarqube User tokens. 6 | --- 7 | 8 | # sonarqube_user_token (Resource) 9 | 10 | Provides a Sonarqube User token resource. This can be used to manage Sonarqube User tokens. 11 | 12 | ## Example Usage 13 | ### Example: create a user, user token and output the token value 14 | ```terraform 15 | resource "sonarqube_user" "user" { 16 | login_name = "terraform-test" 17 | name = "terraform-test" 18 | password = "secret-sauce37!" 19 | } 20 | 21 | resource "sonarqube_user_token" "token" { 22 | login_name = sonarqube_user.user.login_name 23 | name = "my-token" 24 | } 25 | 26 | output "user_token" { 27 | value = sonarqube_user_token.token.token 28 | } 29 | ``` 30 | 31 | ### Example: create an expiring global analysis token and output the token value 32 | ```terraform 33 | resource "sonarqube_user_token" "token" { 34 | name = "my-token" 35 | type = "GLOBAL_ANALYSIS_TOKEN" 36 | expiration_date = "2099-01-01" 37 | } 38 | 39 | output "global_analysis_token" { 40 | value = sonarqube_user_token.token.token 41 | } 42 | ``` 43 | 44 | ### Example: create a project, project analysis token, and output the token value 45 | ```terraform 46 | resource "sonarqube_user_token" "token" { 47 | name = "my-token" 48 | type = "PROJECT_ANALYSIS_TOKEN" 49 | project_key = "my-project" 50 | } 51 | 52 | output "project_analysis_token" { 53 | value = sonarqube_user_token.token.token 54 | } 55 | ``` 56 | 57 | 58 | ## Schema 59 | 60 | ### Required 61 | 62 | - `name` (String) The name of the Token to create. Changing this forces a new resource to be created. 63 | 64 | ### Optional 65 | 66 | - `expiration_date` (String) The expiration date of the token being generated, in ISO 8601 format (YYYY-MM-DD). If not set, default to no expiration. 67 | - `login_name` (String) The login name of the User for which the token should be created. If not set, the token is created for the authenticated user. Changing this forces a new resource to be created. 68 | - `project_key` (String) The key of the only project that can be analyzed by the PROJECT_ANALYSIS TOKEN being created. Changing this forces a new resource to be created. 69 | - `type` (String) The kind of Token to create. Changing this forces a new resource to be created. Possible values are USER_TOKEN, GLOBAL_ANALYSIS_TOKEN, or PROJECT_ANALYSIS_TOKEN. Defaults to USER_TOKEN. If set to PROJECT_ANALYSIS_TOKEN, then the project_key must also be specified. 70 | 71 | ### Read-Only 72 | 73 | - `id` (String) The ID of this resource. 74 | - `token` (String, Sensitive) The token value. 75 | -------------------------------------------------------------------------------- /docs/resources/webhook.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "sonarqube_webhook Resource - terraform-provider-sonarqube" 3 | subcategory: "" 4 | description: |- 5 | Provides a Sonarqube Webhook resource. This can be used to manage Sonarqube webhooks. 6 | --- 7 | 8 | # sonarqube_webhook (Resource) 9 | 10 | Provides a Sonarqube Webhook resource. This can be used to manage Sonarqube webhooks. 11 | 12 | ## Example Usage 13 | ### Example: create a webhook 14 | ```terraform 15 | resource "sonarqube_webhook" "webhook" { 16 | name = "terraform-webhook" 17 | url = "https://my-webhook-destination.example.com" 18 | } 19 | ``` 20 | 21 | ### Example: create a webhook owned by a project 22 | ```terraform 23 | resource "sonarqube_project" "project" { 24 | name = "project" 25 | project = "project" 26 | visibility = "public" 27 | } 28 | 29 | resource "sonarqube_webhook" "webhook" { 30 | name = "terraform-webhook" 31 | url = "https://my-webhook-destination.example.com" 32 | project = sonarqube_project.project.name 33 | } 34 | ``` 35 | 36 | 37 | ## Schema 38 | 39 | ### Required 40 | 41 | - `name` (String) The name of the webhook to create. This will be displayed in the Sonarqube administration console. 42 | - `url` (String) The URL to send event payloads to. This must begin with either `https://` or `http://`. 43 | 44 | ### Optional 45 | 46 | - `project` (String) The key of the project that will own the webhook. 47 | - `secret` (String, Sensitive) The secret to send with the event payload. 48 | 49 | ### Read-Only 50 | 51 | - `id` (String) The ID of this resource. 52 | -------------------------------------------------------------------------------- /examples/basic-env-vars/README.md: -------------------------------------------------------------------------------- 1 | # Basic sonarqube configuration using env vars 2 | Start sonarqube: 3 | 4 | ```sh 5 | docker run --name sonarqube -d -p 9000:9000 sonarqube:latest 6 | ``` 7 | 8 | Run terraform commands to create the a sonarqube project, remove it from state and then re-add it to state. 9 | 10 | ```sh 11 | export SONAR_HOST=http://127.0.0.1:9000 12 | export SONAR_USER=admin 13 | export SONAR_PASS=admin 14 | terraform init 15 | terraform plan 16 | terraform apply --auto-approve 17 | terraform state rm 'sonarqube_project.tf-postfix-test' 18 | terraform import 'sonarqube_project.tf-postfix-test' tf-postfix-test 19 | terraform destroy --auto-approve 20 | ``` -------------------------------------------------------------------------------- /examples/basic-env-vars/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | sonarqube = { 4 | source = "jdamata/sonarqube" 5 | } 6 | } 7 | } 8 | 9 | provider "sonarqube" {} 10 | 11 | resource "sonarqube_project" "tf-postfix-test" { 12 | name = "tf-postfix-test" 13 | project = "tf-postfix-test" 14 | visibility = "public" 15 | } 16 | -------------------------------------------------------------------------------- /examples/basic-module/README.md: -------------------------------------------------------------------------------- 1 | # Basic 2 | 3 | 4 | 5 | ```sh 6 | terraform init 7 | terraform plan 8 | terraform apply 9 | ``` -------------------------------------------------------------------------------- /examples/basic-module/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | sonarqube = { 4 | source = "jdamata/sonarqube" 5 | } 6 | } 7 | } 8 | 9 | provider "sonarqube" { 10 | user = "admin" 11 | pass = "admin" 12 | host = "http://127.0.0.1:9000" 13 | } 14 | 15 | resource "sonarqube_qualitygate" "tf-postfix" { 16 | name = "tf-postfix" 17 | 18 | condition { 19 | metric = "new_coverage" 20 | op = "LT" 21 | threshold = "30" 22 | } 23 | } 24 | 25 | module "tf-postfix-repo" { 26 | source = "./modules/example" 27 | 28 | name = "tf-postfix" 29 | quality_gates = { 30 | gate1 = { 31 | id = sonarqube_qualitygate.tf-postfix.id 32 | metric = "vulnerabilities" 33 | threshold = "11" 34 | operator = "GT" 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /examples/basic-module/modules/example/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | sonarqube = { 4 | source = "jdamata/sonarqube" 5 | } 6 | } 7 | } 8 | 9 | # Sonarqube project configuration 10 | # 11 | # This file contains all configurations for a sonarqube project, which is used for multiple code validations 12 | 13 | resource "sonarqube_project" "this" { 14 | name = var.name 15 | project = var.name 16 | visibility = "public" 17 | } 18 | 19 | # Associate custom quality gates to the project. 20 | # Configuration taken from `quality_gates` map 21 | resource "sonarqube_qualitygate" "this" { 22 | for_each = var.quality_gates 23 | 24 | name = each.key 25 | 26 | condition { 27 | metric = each.value.metric 28 | threshold = each.value.threshold 29 | op = each.value.operator 30 | } 31 | } 32 | 33 | resource "sonarqube_qualitygate_project_association" "this" { 34 | for_each = var.quality_gates 35 | 36 | gatename = sonarqube_qualitygate.this[each.key].id 37 | projectkey = sonarqube_project.this.project 38 | } 39 | -------------------------------------------------------------------------------- /examples/basic-module/modules/example/variables.tf: -------------------------------------------------------------------------------- 1 | variable "name" { 2 | type = string 3 | description = "Name of project" 4 | } 5 | 6 | variable "quality_gates" { 7 | type = map(any) 8 | description = "Quality gates" 9 | } -------------------------------------------------------------------------------- /examples/basic/README.md: -------------------------------------------------------------------------------- 1 | # Basic sonarqube configuration example 2 | 3 | Start sonarqube: 4 | 5 | ```sh 6 | docker run --name sonarqube -d -p 9000:9000 sonarqube:latest 7 | ``` 8 | 9 | Run terraform commands to create the a sonarqube project, remove it from state and then re-add it to state. 10 | 11 | ```sh 12 | terraform init 13 | terraform plan 14 | terraform apply 15 | terraform state rm 'sonarqube_project.tf-postfix-test' 16 | terraform import 'sonarqube_project.tf-postfix-test' tf-postfix-test 17 | ``` -------------------------------------------------------------------------------- /examples/basic/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | sonarqube = { 4 | source = "jdamata/sonarqube" 5 | } 6 | } 7 | } 8 | 9 | provider "sonarqube" { 10 | user = "admin" 11 | pass = "admin" 12 | host = "http://127.0.0.1:9000" 13 | } 14 | 15 | resource "sonarqube_project" "tf-postfix-test" { 16 | name = "tf-postfix-test" 17 | project = "tf-postfix-test" 18 | visibility = "public" 19 | } 20 | -------------------------------------------------------------------------------- /examples/data-sources/sonarqube_group/data-source.tf: -------------------------------------------------------------------------------- 1 | data "sonarqube_group" "group" { 2 | name = "terraform-test" 3 | } 4 | -------------------------------------------------------------------------------- /examples/data-sources/sonarqube_group_members/data-source.tf: -------------------------------------------------------------------------------- 1 | data "sonarqube_group_members" "group_members" { 2 | group = "sonar-users" 3 | ignore_missing = true 4 | } 5 | -------------------------------------------------------------------------------- /examples/data-sources/sonarqube_groups/data-source.tf: -------------------------------------------------------------------------------- 1 | data "sonarqube_groups" "groups" { 2 | 3 | } 4 | -------------------------------------------------------------------------------- /examples/data-sources/sonarqube_languages/data-source.tf: -------------------------------------------------------------------------------- 1 | data "sonarqube_languages" "languages" { 2 | 3 | } 4 | 5 | data "sonarqube_languages" "languages_java" { 6 | search = "java" 7 | } 8 | -------------------------------------------------------------------------------- /examples/data-sources/sonarqube_permission_templates/data-source.tf: -------------------------------------------------------------------------------- 1 | data "sonarqube_permission_templates" "permission_templates" { 2 | 3 | } 4 | -------------------------------------------------------------------------------- /examples/data-sources/sonarqube_portfolio/data-source.tf: -------------------------------------------------------------------------------- 1 | data "sonarqube_portfolio" "portfolio" { 2 | key = "portfolio-key" 3 | } 4 | -------------------------------------------------------------------------------- /examples/data-sources/sonarqube_project/data-source.tf: -------------------------------------------------------------------------------- 1 | data "sonarqube_project" "project" { 2 | project = "projet-key-id" 3 | } 4 | -------------------------------------------------------------------------------- /examples/data-sources/sonarqube_qualitygate/data-source.tf: -------------------------------------------------------------------------------- 1 | data "sonarqube_qualitygate" "main" { 2 | name = "example" 3 | } 4 | -------------------------------------------------------------------------------- /examples/data-sources/sonarqube_qualitygates/data-source.tf: -------------------------------------------------------------------------------- 1 | data "sonarqube_qualitygates" "qualitygates" { 2 | 3 | } 4 | 5 | data "sonarqube_qualitygates" "qualitygates_sonarway" { 6 | name = "Sonar way" 7 | ignore_missing = true 8 | } 9 | -------------------------------------------------------------------------------- /examples/data-sources/sonarqube_qualityprofile/data-source.tf: -------------------------------------------------------------------------------- 1 | data "sonarqube_qualityprofile" "main" { 2 | name = "example" 3 | } 4 | -------------------------------------------------------------------------------- /examples/data-sources/sonarqube_qualityprofiles/data-source.tf: -------------------------------------------------------------------------------- 1 | data "sonarqube_qualityprofiles" "qualityprofiles" { 2 | 3 | } 4 | 5 | data "sonarqube_qualityprofiles" "qualityprofiles_sonarway_java" { 6 | name = "Sonar way" 7 | language = "java" 8 | } 9 | -------------------------------------------------------------------------------- /examples/data-sources/sonarqube_rule/data-source.tf: -------------------------------------------------------------------------------- 1 | data "sonarqube_rule" "rule" { 2 | key = "squid:forbidSonar" 3 | } 4 | -------------------------------------------------------------------------------- /examples/data-sources/sonarqube_user/data-source.tf: -------------------------------------------------------------------------------- 1 | data "sonarqube_user" "user" { 2 | login_name = "terraform-test" 3 | } 4 | -------------------------------------------------------------------------------- /examples/data-sources/sonarqube_user_tokens/data-source.tf: -------------------------------------------------------------------------------- 1 | data "sonarqube_user_tokens" "user_tokens_admin" { 2 | login = "admin" 3 | } 4 | -------------------------------------------------------------------------------- /examples/data-sources/sonarqube_users/data-source.tf: -------------------------------------------------------------------------------- 1 | data "sonarqube_users" "users" { 2 | 3 | } 4 | -------------------------------------------------------------------------------- /examples/provider/provider.tf: -------------------------------------------------------------------------------- 1 | ## Example: Authenticate with username and password 2 | 3 | terraform { 4 | required_providers { 5 | sonarqube = { 6 | source = "jdamata/sonarqube" 7 | } 8 | } 9 | } 10 | 11 | provider "sonarqube" { 12 | user = "admin" 13 | pass = "admin" 14 | host = "http://127.0.0.1:9000" 15 | } 16 | 17 | ## Example: Authenticate with token 18 | 19 | terraform { 20 | required_providers { 21 | sonarqube = { 22 | source = "jdamata/sonarqube" 23 | } 24 | } 25 | } 26 | 27 | provider "sonarqube" { 28 | token = "d4at55a6f7r199bd707h39625685510880gbf7ff" 29 | host = "http://127.0.0.1:9000" 30 | } 31 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_alm_azure/resource.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_alm_azure" "az1" { 2 | key = "az1" 3 | personal_access_token = "my_pat" 4 | url = "https://dev.azure.com/my-org" 5 | } 6 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_alm_github/resource.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_alm_github" "github-alm" { 2 | app_id = "12345" 3 | client_id = "56789" 4 | client_secret = "secret" 5 | key = "myalm" 6 | private_key = "myprivate_key" 7 | url = "https://api.github.com" 8 | webhook_secret = "mysecret" 9 | } 10 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_alm_gitlab/resource.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_alm_gitlab" "gitlab-alm" { 2 | key = "myalm" 3 | personal_access_token = "my_personal_access_token" 4 | url = "https://gitlab.com/api/v4" 5 | } 6 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_azure_binding/resource.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_alm_azure" "az1" { 2 | key = "az1" 3 | personal_access_token = "my_pat" 4 | url = "https://dev.azure.com/my-org" 5 | } 6 | 7 | resource "sonarqube_project" "main" { 8 | name = "SonarQube" 9 | project = "main" 10 | visibility = "public" 11 | } 12 | 13 | resource "sonarqube_azure_binding" "main" { 14 | alm_setting = sonarqube_alm_azure.az1.key 15 | project = sonarqube_project.main.project 16 | project_name = "my_azure_project" 17 | repository_name = "my_repo" 18 | } 19 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_github_binding/resource.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_alm_github" "github-alm" { 2 | app_id = "12345" 3 | client_id = "56789" 4 | client_secret = "secret" 5 | key = "myalm" 6 | private_key = "myprivate_key" 7 | url = "https://api.github.com" 8 | webhook_secret = "mysecret" 9 | } 10 | 11 | resource "sonarqube_project" "main" { 12 | name = "SonarQube" 13 | project = "my_project" 14 | visibility = "public" 15 | } 16 | resource "sonarqube_github_binding" "github-binding" { 17 | alm_setting = sonarqube_alm_github.github-alm.key 18 | project = "my_project" 19 | repository = "myorg/myrepo" 20 | } 21 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_gitlab_binding/resource.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_alm_gitlab" "gitlab-alm" { 2 | key = "myalm" 3 | personal_access_token = "my_personal_access_token" 4 | url = "https://gitlab.com/api/v4" 5 | } 6 | 7 | resource "sonarqube_project" "main" { 8 | name = "SonarQube" 9 | project = "my_project" 10 | visibility = "public" 11 | } 12 | 13 | resource "sonarqube_gitlab_binding" "gitlab-binding" { 14 | alm_setting = sonarqube_alm_gitlab.gitlab-alm.key 15 | project = "my_project" 16 | repository = "123" 17 | } 18 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_group/resource.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_group" "project_users" { 2 | name = "Project-Users" 3 | description = "This is a group" 4 | } 5 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_group_member/resource.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_user" "user" { 2 | login_name = "terraform-test" 3 | name = "terraform-test" 4 | password = "secret-sauce37!" 5 | } 6 | 7 | resource "sonarqube_group" "project_users" { 8 | name = "Project-Users" 9 | description = "This is a group" 10 | } 11 | 12 | resource "sonarqube_group_member" "project_users_member" { 13 | name = sonarqube_group.project_users.name 14 | login_name = sonarqube_user.user.login_name 15 | } 16 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_new_code_periods/global.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_new_code_periods" "code_period" { 2 | type = "NUMBER_OF_DAYS" 3 | value = "7" 4 | } 5 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_new_code_periods/project.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_project" "reference" { 2 | name = "my-project" 3 | } 4 | 5 | resource "sonarqube_new_code_periods" "reference" { 6 | project = sonarqube_project.reference.project 7 | type = "REFERENCE_BRANCH" 8 | value = "main" 9 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_permission_template/resource.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_permission_template" "template" { 2 | name = "Internal-Projects" 3 | description = "These are internal projects" 4 | project_key_pattern = "internal.*" 5 | } 6 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_permissions/global-admin.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_permissions" "my_global_admins" { 2 | group_name = "my-admins" 3 | permissions = ["admin"] 4 | } 5 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_permissions/project-admin.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_permissions" "my_project_admins" { 2 | group_name = "my-project-admins" 3 | project_key = "my-project" 4 | permissions = ["admin"] 5 | } 6 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_permissions/project-template.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_permissions" "internal_admins" { 2 | group_name = "my-internal-admins" 3 | template_id = sonarqube_permission_template.template.id 4 | permissions = ["admin"] 5 | } 6 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_permissions/project-user.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_permissions" "john_project_read" { 2 | login_name = "johndoe" 3 | project_key = "my-project" 4 | permissions = ["codeviewer", "user"] 5 | } 6 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_plugin/resource.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_plugin" "main" { 2 | key = "cloudformation" 3 | } 4 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_portfolio/resource.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_portfolio" "main" { 2 | key = "portfolio-key" 3 | name = "portfolio-name" 4 | description = "portfolio-description" 5 | } 6 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_project/project-settings.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_project" "main" { 2 | name = "SonarQube" 3 | project = "my_project" 4 | visibility = "public" 5 | 6 | setting { 7 | key = "sonar.demo" 8 | value = "sonarqube@example.org" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_project/project.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_project" "main" { 2 | name = "SonarQube" 3 | project = "my_project" 4 | visibility = "public" 5 | } 6 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_project_main_branch/resource.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_project" "main" { 2 | name = "SonarQube" 3 | project = "my_project" 4 | visibility = "public" 5 | } 6 | resource "sonarqube_project_main_branch" "mybranch" { 7 | name = "release" 8 | project = "my_project" 9 | } 10 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_qualitygate/resource.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_qualitygate" "main" { 2 | name = "example" 3 | is_default = true 4 | 5 | condition { 6 | metric = "new_coverage" 7 | op = "LT" 8 | threshold = "50" 9 | } 10 | 11 | condition { 12 | metric = "vulnerabilities" 13 | threshold = "10" 14 | op = "GT" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_qualitygate_project_association/resource.tf: -------------------------------------------------------------------------------- 1 | ## Example: create a quality gate project association 2 | 3 | resource "sonarqube_qualitygate" "main" { 4 | name = "my_qualitygate" 5 | 6 | condition { 7 | metric = "new_coverage" 8 | op = "LT" 9 | threshold = "30" 10 | } 11 | } 12 | 13 | resource "sonarqube_project" "main" { 14 | name = "SonarQube" 15 | project = "my_project" 16 | visibility = "public" 17 | } 18 | 19 | resource "sonarqube_qualitygate_project_association" "main" { 20 | gatename = sonarqube_qualitygate.main.id 21 | projectkey = sonarqube_project.main.project 22 | } 23 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_qualitygate_usergroup_association/user-association.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_qualitygate" "main" { 2 | name = "my_qualitygate" 3 | 4 | condition { 5 | metric = "new_coverage" 6 | op = "LT" 7 | threshold = "30" 8 | } 9 | } 10 | 11 | resource "sonarqube_user" "qa_user" { 12 | login_name = "qa-user" 13 | name = "qa-user" 14 | password = "secret-sauce37!" 15 | } 16 | 17 | resource "sonarqube_qualitygate_usergroup_association" "main" { 18 | gatename = sonarqube_qualitygate.main.id 19 | login_name = sonarqube_user.qa_user.id 20 | } 21 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_qualitygate_usergroup_association/usergroup-association.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_qualitygate" "main" { 2 | name = "my_qualitygate" 3 | 4 | condition { 5 | metric = "new_coverage" 6 | op = "LT" 7 | threshold = "30" 8 | } 9 | } 10 | 11 | resource "sonarqube_group" "qa_team" { 12 | name = "QA-Team" 13 | description = "Quality Assurence Team" 14 | } 15 | 16 | resource "sonarqube_qualitygate_usergroup_association" "main" { 17 | gatename = sonarqube_qualitygate.main.id 18 | group_name = sonarqube_group.qa_team.name 19 | } 20 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_qualityprofile/resource.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_qualityprofile" "main" { 2 | name = "example" 3 | language = "js" 4 | is_default = false 5 | parent = "sonar way" 6 | } 7 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_qualityprofile_activate_rule/resource.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_rule" "allowed_maven_dependencies" { 2 | custom_key = "Only_use_allowed_Maven_dependencies" 3 | markdown_description = "Description" 4 | name = "Only use allowed Maven dependencies" 5 | params = "FilePattern=**/pom.xml" 6 | severity = "BLOCKER" 7 | status = "READY" 8 | template_key = "xml:XPathCheck" 9 | type = "VULNERABILITY" 10 | } 11 | 12 | resource "sonarqube_qualityprofile" "xml" { 13 | name = "test way - xml" 14 | language = "xml" 15 | is_default = "false" 16 | parent = "Sonar way" 17 | } 18 | 19 | resource "sonarqube_qualityprofile_activate_rule" "xml_rule" { 20 | key = sonarqube_qualityprofile.xml.key # .id also works 21 | rule = sonarqube_rule.allowed_maven_dependencies.id 22 | severity = "BLOCKER" 23 | } 24 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_qualityprofile_project_association/resource.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_qualityprofile" "main" { 2 | name = "my_quality_profile" 3 | language = "js" 4 | } 5 | 6 | resource "sonarqube_project" "main" { 7 | name = "SonarQube" 8 | project = "my_project" 9 | visibility = "public" 10 | } 11 | 12 | resource "sonarqube_qualityprofile_project_association" "main" { 13 | quality_profile = sonarqube_qualityprofile.main.name 14 | project = sonarqube_project.main.project 15 | language = "js" 16 | } 17 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_qualityprofile_usergroup_association/user-association.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_qualityprofile" "main" { 2 | name = "my_qualityprofile" 3 | language = "java" 4 | parent = "Sonar way" 5 | } 6 | 7 | resource "sonarqube_user" "qa_user" { 8 | login_name = "qa-user" 9 | name = "qa-user" 10 | password = "secret-sauce37!" 11 | } 12 | 13 | resource "sonarqube_qualityprofile_usergroup_association" "main" { 14 | profile_name = sonarqube_qualityprofile.main.id 15 | language = sonarqube_qualityprofile.language.id 16 | login_name = sonarqube_user.qa_user.id 17 | } 18 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_qualityprofile_usergroup_association/usergroup-association.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_qualityprofile" "main" { 2 | name = "my_qualityprofile" 3 | language = "java" 4 | parent = "Sonar way" 5 | } 6 | 7 | resource "sonarqube_group" "qa_team" { 8 | name = "QA-Team" 9 | description = "Quality Assurence Team" 10 | } 11 | 12 | resource "sonarqube_qualityprofile_usergroup_association" "main" { 13 | profile_name = sonarqube_qualityprofile.main.id 14 | language = sonarqube_qualityprofile.language.id 15 | group_name = sonarqube_group.qa_team.name 16 | } 17 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_rules/resource.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_rule" "rule" { 2 | key = "rule_test" 3 | markdown_description = "Description of my rule" 4 | name = "rule test" 5 | params = "FilePattern=**/pom.xml" 6 | prevent_reactivation = "false" 7 | severity = "CRITICAL" 8 | status = "READY" 9 | template_key = "xml:XPathCheck" 10 | type = "VULNERABILITY" 11 | } 12 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_setting/multi-field-values.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_setting" "multi_field_setting" { 2 | key = "sonar.issue.ignore.multicriteria" 3 | field_values = [ 4 | { 5 | "ruleKey" : "foo", 6 | "resourceKey" : "bar" 7 | }, 8 | { 9 | "ruleKey" : "foo2", 10 | "resourceKey" : "bar2" 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_setting/multi-value.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_setting" "multi_value_setting" { 2 | key = "sonar.global.exclusions" 3 | values = ["foo", "bar/**/*.*"] 4 | } 5 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_user/local.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_user" "user" { 2 | login_name = "terraform-test" 3 | name = "terraform-test" 4 | password = "secret-sauce37!" 5 | } 6 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_user/remote.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_user" "remote_user" { 2 | login_name = "terraform-test" 3 | name = "terraform-test" 4 | email = "terraform-test@sonarqube.com" 5 | is_local = false 6 | } 7 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_user_external_identity/resource.tf: -------------------------------------------------------------------------------- 1 | ## Example: change the external identity to SAML 2 | 3 | resource "sonarqube_user" "remote_user" { 4 | login_name = "terraform-test" 5 | name = "terraform-test" 6 | email = "terraform-test@sonarqube.com" 7 | is_local = false 8 | } 9 | 10 | resource "sonarqube_user_external_identity" "remote_user" { 11 | login_name = sonarqube_user.remote_user.login_name 12 | external_identity = "terraform-test@sonarqube.com" 13 | external_provider = "saml" 14 | } 15 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_user_token/global-analysis-token.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_user_token" "token" { 2 | name = "my-token" 3 | type = "GLOBAL_ANALYSIS_TOKEN" 4 | expiration_date = "2099-01-01" 5 | } 6 | 7 | output "global_analysis_token" { 8 | value = sonarqube_user_token.token.token 9 | } 10 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_user_token/project-analysis-token.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_user_token" "token" { 2 | name = "my-token" 3 | type = "PROJECT_ANALYSIS_TOKEN" 4 | project_key = "my-project" 5 | } 6 | 7 | output "project_analysis_token" { 8 | value = sonarqube_user_token.token.token 9 | } 10 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_user_token/user-token.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_user" "user" { 2 | login_name = "terraform-test" 3 | name = "terraform-test" 4 | password = "secret-sauce37!" 5 | } 6 | 7 | resource "sonarqube_user_token" "token" { 8 | login_name = sonarqube_user.user.login_name 9 | name = "my-token" 10 | } 11 | 12 | output "user_token" { 13 | value = sonarqube_user_token.token.token 14 | } 15 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_webhook/project-webhook.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_project" "project" { 2 | name = "project" 3 | project = "project" 4 | visibility = "public" 5 | } 6 | 7 | resource "sonarqube_webhook" "webhook" { 8 | name = "terraform-webhook" 9 | url = "https://my-webhook-destination.example.com" 10 | project = sonarqube_project.project.name 11 | } 12 | -------------------------------------------------------------------------------- /examples/resources/sonarqube_webhook/webhook.tf: -------------------------------------------------------------------------------- 1 | resource "sonarqube_webhook" "webhook" { 2 | name = "terraform-webhook" 3 | url = "https://my-webhook-destination.example.com" 4 | } 5 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/jdamata/terraform-provider-sonarqube 2 | 3 | go 1.24 4 | 5 | require ( 6 | github.com/hashicorp/go-cleanhttp v0.5.2 7 | github.com/hashicorp/go-retryablehttp v0.7.7 8 | github.com/hashicorp/go-version v1.7.0 9 | github.com/hashicorp/terraform-plugin-sdk/v2 v2.37.0 10 | github.com/hashicorp/terraform-plugin-testing v1.13.1 11 | golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 12 | ) 13 | 14 | require ( 15 | github.com/ProtonMail/go-crypto v1.1.6 // indirect 16 | github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect 17 | github.com/cloudflare/circl v1.6.0 // indirect 18 | github.com/kr/pretty v0.3.0 // indirect 19 | github.com/rogpeppe/go-internal v1.13.1 // indirect 20 | github.com/tidwall/match v1.1.1 // indirect 21 | github.com/tidwall/pretty v1.2.0 // indirect 22 | github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect 23 | github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect 24 | golang.org/x/sync v0.14.0 // indirect 25 | golang.org/x/tools v0.22.0 // indirect 26 | ) 27 | 28 | require ( 29 | github.com/agext/levenshtein v1.2.3 // indirect 30 | github.com/fatih/color v1.16.0 // indirect 31 | github.com/golang/protobuf v1.5.4 // indirect 32 | github.com/google/go-cmp v0.7.0 // indirect 33 | github.com/hashicorp/errwrap v1.1.0 // indirect 34 | github.com/hashicorp/go-checkpoint v0.5.0 // indirect 35 | github.com/hashicorp/go-cty v1.5.0 // indirect 36 | github.com/hashicorp/go-hclog v1.6.3 // indirect 37 | github.com/hashicorp/go-multierror v1.1.1 // indirect 38 | github.com/hashicorp/go-plugin v1.6.3 // indirect 39 | github.com/hashicorp/go-uuid v1.0.3 // indirect 40 | github.com/hashicorp/hc-install v0.9.2 // indirect 41 | github.com/hashicorp/hcl/v2 v2.23.0 // indirect 42 | github.com/hashicorp/logutils v1.0.0 // indirect 43 | github.com/hashicorp/terraform-exec v0.23.0 // indirect 44 | github.com/hashicorp/terraform-json v0.25.0 // indirect 45 | github.com/hashicorp/terraform-plugin-go v0.27.0 // indirect 46 | github.com/hashicorp/terraform-plugin-log v0.9.0 47 | github.com/hashicorp/terraform-registry-address v0.2.5 // indirect 48 | github.com/hashicorp/terraform-svchost v0.1.1 // indirect 49 | github.com/hashicorp/yamux v0.1.1 // indirect 50 | github.com/mattn/go-colorable v0.1.14 // indirect 51 | github.com/mattn/go-isatty v0.0.20 // indirect 52 | github.com/mitchellh/copystructure v1.2.0 // indirect 53 | github.com/mitchellh/go-testing-interface v1.14.1 // indirect 54 | github.com/mitchellh/go-wordwrap v1.0.1 // indirect 55 | github.com/mitchellh/mapstructure v1.5.0 // indirect 56 | github.com/mitchellh/reflectwalk v1.0.2 // indirect 57 | github.com/oklog/run v1.1.0 // indirect 58 | github.com/tidwall/gjson v1.17.0 59 | github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect 60 | github.com/zclconf/go-cty v1.16.2 // indirect 61 | golang.org/x/crypto v0.38.0 // indirect 62 | golang.org/x/mod v0.24.0 // indirect 63 | golang.org/x/net v0.39.0 // indirect 64 | golang.org/x/sys v0.33.0 // indirect 65 | golang.org/x/text v0.25.0 // indirect 66 | google.golang.org/appengine v1.6.8 // indirect 67 | google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect 68 | google.golang.org/grpc v1.72.1 // indirect 69 | google.golang.org/protobuf v1.36.6 // indirect 70 | ) 71 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | 6 | "github.com/hashicorp/terraform-plugin-sdk/v2/plugin" 7 | "github.com/jdamata/terraform-provider-sonarqube/sonarqube" 8 | ) 9 | 10 | func main() { 11 | 12 | var debug bool 13 | 14 | flag.BoolVar(&debug, "debug", false, "set to true to run the provider with support for debuggers like delve") 15 | flag.Parse() 16 | 17 | plugin.Serve( 18 | &plugin.ServeOpts{ 19 | Debug: debug, 20 | ProviderAddr: "registry.terraform.io/jdamata/sonarqube", 21 | ProviderFunc: sonarqube.Provider, 22 | }, 23 | ) 24 | } 25 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_group.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 5 | ) 6 | 7 | func dataSourceSonarqubeGroup() *schema.Resource { 8 | return &schema.Resource{ 9 | Description: "Use this data source to get a Sonarqube Group resource", 10 | Read: dataSourceSonarqubeGroupRead, 11 | Schema: map[string]*schema.Schema{ 12 | "name": { 13 | Type: schema.TypeString, 14 | Required: true, 15 | Description: "The name of the group.", 16 | }, 17 | "description": { 18 | Type: schema.TypeString, 19 | Computed: true, 20 | Description: "The group description.", 21 | }, 22 | }, 23 | } 24 | } 25 | 26 | func dataSourceSonarqubeGroupRead(d *schema.ResourceData, m interface{}) error { 27 | d.SetId(d.Get("name").(string)) 28 | return resourceSonarqubeGroupRead(d, m) 29 | } 30 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_group_members_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func testAccSonarqubeGroupMembersDataSourceConfig(rnd string, groupName string, loginName string) string { 11 | return fmt.Sprintf(` 12 | resource "sonarqube_user" "%[1]s_user" { 13 | login_name = "%[3]s" 14 | name = "Test User" 15 | email = "terraform-test@sonarqube.com" 16 | password = "secret-Sauce!" 17 | } 18 | 19 | resource "sonarqube_group" "%[1]s_group" { 20 | name = "%[2]s" 21 | } 22 | 23 | resource "sonarqube_group_member" "%[1]s" { 24 | name = sonarqube_group.%[1]s_group.name 25 | login_name = sonarqube_user.%[1]s_user.login_name 26 | } 27 | 28 | data "sonarqube_group_members" "%[1]s" { 29 | group = sonarqube_group.%[1]s_group.name 30 | depends_on = [sonarqube_group_member.%[1]s] 31 | }`, rnd, groupName, loginName) 32 | } 33 | 34 | func TestAccSonarqubeGroupMembersDataSource(t *testing.T) { 35 | rnd := generateRandomResourceName() 36 | name := "data.sonarqube_group_members." + rnd 37 | 38 | resource.Test(t, resource.TestCase{ 39 | PreCheck: func() { testAccPreCheck(t) }, 40 | Providers: testAccProviders, 41 | Steps: []resource.TestStep{ 42 | { 43 | Config: testAccSonarqubeGroupMembersDataSourceConfig(rnd, "testAccSonarqubeGroup", "testAccSonarqubeUser"), 44 | Check: resource.ComposeTestCheckFunc( 45 | resource.TestCheckResourceAttr(name, "members.#", "1"), 46 | resource.TestCheckResourceAttr(name, "members.0.login_name", "testAccSonarqubeUser"), 47 | ), 48 | }, 49 | }, 50 | }) 51 | } 52 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_group_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func testAccSonarqubeGroupDataSourceConfig(rnd string, name string, description string) string { 11 | return fmt.Sprintf(` 12 | resource "sonarqube_group" "%[1]s" { 13 | name = "%[2]s" 14 | description = "%[3]s" 15 | } 16 | 17 | data "sonarqube_group" "%[1]s" { 18 | name = sonarqube_group.%[1]s.name 19 | }`, rnd, name, description) 20 | } 21 | 22 | func TestAccSonarqubeGroupDataSource(t *testing.T) { 23 | rnd := generateRandomResourceName() 24 | name := "data.sonarqube_group." + rnd 25 | 26 | resource.Test(t, resource.TestCase{ 27 | PreCheck: func() { testAccPreCheck(t) }, 28 | Providers: testAccProviders, 29 | Steps: []resource.TestStep{ 30 | { 31 | Config: testAccSonarqubeGroupDataSourceConfig(rnd, "testAccSonarqubeGroupDataSource", "Terraform Test Group Data-source"), 32 | Check: resource.ComposeTestCheckFunc( 33 | resource.TestCheckResourceAttr(name, "name", "testAccSonarqubeGroupDataSource"), 34 | resource.TestCheckResourceAttr(name, "description", "Terraform Test Group Data-source"), 35 | ), 36 | }, 37 | }, 38 | }) 39 | } 40 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_groups.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "fmt" 7 | "net/http" 8 | "net/url" 9 | "strings" 10 | 11 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 12 | ) 13 | 14 | func dataSourceSonarqubeGroups() *schema.Resource { 15 | return &schema.Resource{ 16 | Description: "Use this data source to get Sonarqube group resources", 17 | Read: dataSourceSonarqubeGroupsRead, 18 | Schema: map[string]*schema.Schema{ 19 | "search": { 20 | Type: schema.TypeString, 21 | Optional: true, 22 | Description: "Search groups by name.", 23 | }, 24 | "groups": { 25 | Type: schema.TypeList, 26 | Computed: true, 27 | Elem: &schema.Resource{ 28 | Schema: map[string]*schema.Schema{ 29 | "name": { 30 | Type: schema.TypeString, 31 | Computed: true, 32 | Description: "The name of the group.", 33 | }, 34 | "description": { 35 | Type: schema.TypeString, 36 | Computed: true, 37 | Description: "The group description.", 38 | }, 39 | }, 40 | }, 41 | Description: "The list of groups.", 42 | }, 43 | }, 44 | } 45 | } 46 | 47 | func dataSourceSonarqubeGroupsRead(d *schema.ResourceData, m interface{}) error { 48 | d.SetId(fmt.Sprintf("%d", schema.HashString(d.Get("search")))) 49 | 50 | groupsReadResponse, err := readGroupsFromApi(d, m) 51 | if err != nil { 52 | return err 53 | } 54 | 55 | errs := []error{} 56 | errs = append(errs, d.Set("groups", flattenReadGroupsResponse(groupsReadResponse.Groups))) 57 | 58 | return errors.Join(errs...) 59 | } 60 | 61 | func readGroupsFromApi(d *schema.ResourceData, m interface{}) (*GetGroup, error) { 62 | sonarQubeURL := m.(*ProviderConfiguration).sonarQubeURL 63 | sonarQubeURL.Path = strings.TrimSuffix(sonarQubeURL.Path, "/") + "/api/user_groups/search" 64 | 65 | RawQuery := url.Values{ 66 | "ps": []string{"500"}, 67 | } 68 | 69 | if search, ok := d.GetOk("search"); ok { 70 | RawQuery.Add("q", search.(string)) 71 | } 72 | 73 | sonarQubeURL.RawQuery = RawQuery.Encode() 74 | 75 | resp, err := httpRequestHelper( 76 | m.(*ProviderConfiguration).httpClient, 77 | "GET", 78 | sonarQubeURL.String(), 79 | http.StatusOK, 80 | "readGroupsFromApi", 81 | ) 82 | if err != nil { 83 | return nil, fmt.Errorf("readGroupsFromApi: Failed to read Sonarqube groups: %+v", err) 84 | } 85 | defer resp.Body.Close() 86 | 87 | // Decode response into struct 88 | groupsReadResponse := GetGroup{} 89 | err = json.NewDecoder(resp.Body).Decode(&groupsReadResponse) 90 | if err != nil { 91 | return nil, fmt.Errorf("readGroupsFromApi: Failed to decode json into struct: %+v", err) 92 | } 93 | 94 | return &groupsReadResponse, nil 95 | } 96 | 97 | func flattenReadGroupsResponse(groups []Group) []interface{} { 98 | groupsList := []interface{}{} 99 | 100 | for _, group := range groups { 101 | values := map[string]interface{}{ 102 | "name": group.Name, 103 | "description": group.Description, 104 | } 105 | 106 | groupsList = append(groupsList, values) 107 | } 108 | 109 | return groupsList 110 | } 111 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_groups_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func testAccSonarqubeGroupsDataSourceConfig(rnd string, name string, description string) string { 11 | return fmt.Sprintf(` 12 | resource "sonarqube_group" "%[1]s" { 13 | name = "%[2]s" 14 | description = "%[3]s" 15 | } 16 | 17 | data "sonarqube_groups" "%[1]s" { 18 | search = sonarqube_group.%[1]s.name 19 | }`, rnd, name, description) 20 | } 21 | 22 | func TestAccSonarqubeGroupsDataSource(t *testing.T) { 23 | rnd := generateRandomResourceName() 24 | name := "data.sonarqube_groups." + rnd 25 | 26 | resource.Test(t, resource.TestCase{ 27 | PreCheck: func() { testAccPreCheck(t) }, 28 | Providers: testAccProviders, 29 | Steps: []resource.TestStep{ 30 | { 31 | Config: testAccSonarqubeGroupsDataSourceConfig(rnd, "testAccSonarqubeGroupsDataSource", "Terraform Test Groups Data-source"), 32 | Check: resource.ComposeTestCheckFunc( 33 | resource.TestCheckResourceAttr(name, "groups.#", "1"), 34 | resource.TestCheckResourceAttr(name, "groups.0.name", "testAccSonarqubeGroupsDataSource"), 35 | resource.TestCheckResourceAttr(name, "groups.0.description", "Terraform Test Groups Data-source"), 36 | ), 37 | }, 38 | }, 39 | }) 40 | } 41 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_languages_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func testAccSonarqubeLanguagesDataSourceConfig(rnd string, languageKey string) string { 11 | return fmt.Sprintf(` 12 | data "sonarqube_languages" "%[1]s" { 13 | search = "%[2]s" 14 | }`, rnd, languageKey) 15 | } 16 | 17 | func TestAccSonarqubeLanguagesDataSource(t *testing.T) { 18 | rnd := generateRandomResourceName() 19 | name := "data.sonarqube_languages." + rnd 20 | 21 | resource.Test(t, resource.TestCase{ 22 | PreCheck: func() { testAccPreCheck(t) }, 23 | Providers: testAccProviders, 24 | Steps: []resource.TestStep{ 25 | { 26 | Config: testAccSonarqubeLanguagesDataSourceConfig(rnd, "terraform"), 27 | Check: resource.ComposeTestCheckFunc( 28 | resource.TestCheckResourceAttr(name, "languages.#", "1"), 29 | resource.TestCheckResourceAttr(name, "languages.0.key", "terraform"), 30 | resource.TestCheckResourceAttr(name, "languages.0.name", "Terraform"), 31 | ), 32 | }, 33 | }, 34 | }) 35 | } 36 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_permission_templates_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func testAccSonarqubePermissionTemplatesDataSourceConfig(rnd string, name string, description string, projectKeyPattern string) string { 11 | return fmt.Sprintf(` 12 | resource "sonarqube_permission_template" "%[1]s" { 13 | name = "%[2]s" 14 | description = "%[3]s" 15 | project_key_pattern = "%[4]s" 16 | } 17 | 18 | data "sonarqube_permission_templates" "%[1]s" { 19 | search = sonarqube_permission_template.%[1]s.name 20 | }`, rnd, name, description, projectKeyPattern) 21 | } 22 | 23 | func TestAccSonarqubePermissionTemplatesDataSource(t *testing.T) { 24 | rnd := generateRandomResourceName() 25 | name := "data.sonarqube_permission_templates." + rnd 26 | 27 | resource.Test(t, resource.TestCase{ 28 | PreCheck: func() { testAccPreCheck(t) }, 29 | Providers: testAccProviders, 30 | Steps: []resource.TestStep{ 31 | { 32 | Config: testAccSonarqubePermissionTemplatesDataSourceConfig(rnd, "testAccSonarqubePermissionTemplatesDataSource", "These are internal projects", "internal.*"), 33 | Check: resource.ComposeTestCheckFunc( 34 | resource.TestCheckResourceAttr(name, "permission_templates.#", "1"), 35 | resource.TestCheckResourceAttr(name, "permission_templates.0.name", "testAccSonarqubePermissionTemplatesDataSource"), 36 | resource.TestCheckResourceAttr(name, "permission_templates.0.description", "These are internal projects"), 37 | resource.TestCheckResourceAttr(name, "permission_templates.0.project_key_pattern", "internal.*"), 38 | ), 39 | }, 40 | }, 41 | }) 42 | } 43 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_portfolio.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 5 | ) 6 | 7 | func dataSourceSonarqubePortfolio() *schema.Resource { 8 | return &schema.Resource{ 9 | Description: "Use this data source to get a Sonarqube portfolio resource", 10 | Read: dataSourceSonarqubePortfolioRead, 11 | Schema: map[string]*schema.Schema{ 12 | "key": { 13 | Type: schema.TypeString, 14 | Required: true, 15 | Description: "The key of the portfolio", 16 | }, 17 | "name": { 18 | Type: schema.TypeString, 19 | Computed: true, 20 | Description: "Name of the portfolio", 21 | }, 22 | "description": { 23 | Type: schema.TypeString, 24 | Computed: true, 25 | Description: "Description of the portfolio", 26 | }, 27 | "qualifier": { 28 | Type: schema.TypeString, 29 | Computed: true, 30 | Description: "`VW` (portfolios always have this qualifier)", 31 | }, 32 | "visibility": { 33 | Type: schema.TypeString, 34 | Computed: true, 35 | Description: "Portfolio visibility", 36 | }, 37 | "selection_mode": { 38 | Type: schema.TypeString, 39 | Computed: true, 40 | Description: "How the Portfolio is populated. Possible values are `NONE`, `MANUAL`, `TAGS`, `REGEXP` or `REST`. [See docs](https://docs.sonarqube.org/9.8/project-administration/managing-portfolios/#populating-portfolios) for how Portfolio population works", 41 | }, 42 | "branch": { // Only active for TAGS, REGEXP and REST 43 | Type: schema.TypeString, 44 | Computed: true, 45 | Description: "Which branch is analyzed", 46 | }, 47 | "tags": { // Only active for TAGS 48 | Type: schema.TypeList, 49 | Computed: true, 50 | Elem: &schema.Schema{ 51 | Type: schema.TypeString, 52 | }, 53 | Description: "The list of tags used to populate the Portfolio. Only active when `selection_mode` is `TAGS`", 54 | }, 55 | "regexp": { // Only active for REGEXP 56 | Type: schema.TypeString, 57 | Computed: true, 58 | Description: "The regular expression used to populate the portfolio. Only active when `selection_mode` is `REGEXP`", 59 | }, 60 | }, 61 | } 62 | } 63 | 64 | func dataSourceSonarqubePortfolioRead(d *schema.ResourceData, m interface{}) error { 65 | d.SetId(d.Get("key").(string)) 66 | return resourceSonarqubePortfolioRead(d, m) 67 | } 68 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_project.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 5 | ) 6 | 7 | func dataSourceSonarqubeProject() *schema.Resource { 8 | return &schema.Resource{ 9 | Description: "Use this data source to get a Sonarqube project resource", 10 | Read: dataSourceSonarqubeProjectRead, 11 | Schema: map[string]*schema.Schema{ 12 | "name": { 13 | Type: schema.TypeString, 14 | Computed: true, 15 | Description: "Name of the project", 16 | }, 17 | "project": { 18 | Type: schema.TypeString, 19 | Required: true, 20 | Description: "The project key of the project", 21 | }, 22 | "visibility": { 23 | Type: schema.TypeString, 24 | Computed: true, 25 | Description: "Project visibility", 26 | }, 27 | }, 28 | } 29 | } 30 | 31 | func dataSourceSonarqubeProjectRead(d *schema.ResourceData, m interface{}) error { 32 | d.SetId(d.Get("project").(string)) 33 | return resourceSonarqubeProjectRead(d, m) 34 | } 35 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_project_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func testAccSonarqubeProjectDataSourceConfig(rnd string, name string, project string, visibility string) string { 11 | return fmt.Sprintf(` 12 | resource "sonarqube_project" "%[1]s" { 13 | name = "%[2]s" 14 | project = "%[3]s" 15 | visibility = "%[4]s" 16 | } 17 | data "sonarqube_project" "%[1]s" { 18 | project = sonarqube_project.%[1]s.id 19 | } 20 | `, rnd, name, project, visibility) 21 | } 22 | 23 | func TestAccSonarqubeProjectDataSource(t *testing.T) { 24 | rnd := generateRandomResourceName() 25 | name := "data.sonarqube_project." + rnd 26 | 27 | resource.Test(t, resource.TestCase{ 28 | PreCheck: func() { testAccPreCheck(t) }, 29 | Providers: testAccProviders, 30 | Steps: []resource.TestStep{ 31 | { 32 | Config: testAccSonarqubeProjectDataSourceConfig(rnd, "testAccSonarqubeProjectDataSource", "testAccSonarqubeProjectDataSource", "public"), 33 | Check: resource.ComposeTestCheckFunc( 34 | resource.TestCheckResourceAttr(name, "name", "testAccSonarqubeProjectDataSource"), 35 | resource.TestCheckResourceAttr(name, "project", "testAccSonarqubeProjectDataSource"), 36 | resource.TestCheckResourceAttr(name, "visibility", "public"), 37 | ), 38 | }, 39 | }, 40 | }) 41 | } 42 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_qualitygate.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 5 | ) 6 | 7 | func dataSourceSonarqubeQualityGate() *schema.Resource { 8 | return &schema.Resource{ 9 | Description: "Use this data source to get a Sonarqube qualitygate resource", 10 | Read: dataSourceSonarqubeQualityGateRead, 11 | Schema: map[string]*schema.Schema{ 12 | "name": { 13 | Type: schema.TypeString, 14 | Required: true, 15 | Description: "The name of the Quality Gate.", 16 | }, 17 | "copy_from": { 18 | Type: schema.TypeString, 19 | Computed: true, 20 | Description: "Origin of the Quality Gate", 21 | }, 22 | "is_default": { 23 | Type: schema.TypeBool, 24 | Computed: true, 25 | Description: "Quality Gate default.", 26 | }, 27 | "condition": { 28 | Type: schema.TypeList, 29 | Computed: true, 30 | Elem: &schema.Resource{ 31 | Schema: map[string]*schema.Schema{ 32 | "id": { 33 | Type: schema.TypeString, 34 | Computed: true, 35 | }, 36 | "metric": { 37 | Type: schema.TypeString, 38 | Required: true, 39 | }, 40 | "op": { 41 | Type: schema.TypeString, 42 | Required: true, 43 | }, 44 | "threshold": { 45 | Type: schema.TypeString, 46 | Required: true, 47 | }, 48 | }, 49 | }, 50 | Description: "List of Quality Gate conditions.", 51 | }, 52 | }, 53 | } 54 | } 55 | 56 | func dataSourceSonarqubeQualityGateRead(d *schema.ResourceData, m interface{}) error { 57 | d.SetId(d.Get("name").(string)) 58 | return resourceSonarqubeQualityGateRead(d, m) 59 | } 60 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_qualitygate_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func testAccSonarqubeQualityGateDataSourceConfig(rnd string, name string, copy_from string, metric string, op string, threshold string) string { 11 | if len(copy_from) > 0 { 12 | return fmt.Sprintf(` 13 | resource "sonarqube_qualitygate" "%[1]s" { 14 | name = "%[2]s" 15 | copy_from = "%[3]s" 16 | } 17 | 18 | data "sonarqube_qualitygate" "%[1]s" { 19 | name = sonarqube_qualitygate.%[1]s.name 20 | }`, rnd, name, copy_from) 21 | 22 | } else { 23 | 24 | return fmt.Sprintf(` 25 | resource "sonarqube_qualitygate" "%[1]s" { 26 | name = "%[2]s" 27 | condition { 28 | metric = "%[3]s" 29 | op = "%[4]s" 30 | threshold = "%[5]s" 31 | } 32 | } 33 | 34 | data "sonarqube_qualitygate" "%[1]s" { 35 | name = sonarqube_qualitygate.%[1]s.name 36 | }`, rnd, name, metric, op, threshold) 37 | } 38 | } 39 | 40 | func TestAccSonarqubeQualityGateDataSource(t *testing.T) { 41 | rnd := generateRandomResourceName() 42 | name := "data.sonarqube_qualitygate." + rnd 43 | 44 | resource.Test(t, resource.TestCase{ 45 | PreCheck: func() { testAccPreCheck(t) }, 46 | Providers: testAccProviders, 47 | Steps: []resource.TestStep{ 48 | // QualityGate with copy_from 49 | { 50 | Config: testAccSonarqubeQualityGateDataSourceConfig(rnd, "testAccSonarqubeQualityGateDataSourceCopy", "Sonar way", "", "", ""), 51 | Check: resource.ComposeTestCheckFunc( 52 | resource.TestCheckResourceAttr(name, "name", "testAccSonarqubeQualityGateDataSourceCopy"), 53 | ), 54 | }, 55 | // QualityGate with condition 56 | { 57 | Config: testAccSonarqubeQualityGateDataSourceConfig(rnd, "testAccSonarqubeQualityGateDataSourceCondition", "", "new_coverage", "LT", "50"), 58 | Check: resource.ComposeTestCheckFunc( 59 | resource.TestCheckResourceAttr(name, "name", "testAccSonarqubeQualityGateDataSourceCondition"), 60 | ), 61 | }, 62 | }, 63 | }) 64 | } 65 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_qualitygates_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func testAccSonarqubeQualityGatesDataSourceConfig(rnd string, name string, metric string, op string, threshold string) string { 11 | return fmt.Sprintf(` 12 | resource "sonarqube_qualitygate" "%[1]s" { 13 | name = "%[2]s" 14 | condition { 15 | metric = "%[3]s" 16 | op = "%[4]s" 17 | threshold = "%[5]s" 18 | } 19 | } 20 | 21 | data "sonarqube_qualitygates" "%[1]s" { 22 | name = sonarqube_qualitygate.%[1]s.name 23 | }`, rnd, name, metric, op, threshold) 24 | } 25 | 26 | func TestAccSonarqubeQualityGatesDataSource(t *testing.T) { 27 | rnd := generateRandomResourceName() 28 | name := "data.sonarqube_qualitygates." + rnd 29 | 30 | resource.Test(t, resource.TestCase{ 31 | PreCheck: func() { testAccPreCheck(t) }, 32 | Providers: testAccProviders, 33 | Steps: []resource.TestStep{ 34 | { 35 | Config: testAccSonarqubeQualityGatesDataSourceConfig(rnd, "testAccSonarqubeQualityGatesDataSource", "new_coverage", "LT", "50"), 36 | Check: resource.ComposeTestCheckFunc( 37 | resource.TestCheckResourceAttr(name, "quality_gates.#", "1"), 38 | resource.TestCheckResourceAttr(name, "quality_gates.0.name", "testAccSonarqubeQualityGatesDataSource"), 39 | resource.TestCheckResourceAttr(name, "quality_gates.0.condition.0.metric", "new_coverage"), 40 | resource.TestCheckResourceAttr(name, "quality_gates.0.condition.0.op", "LT"), 41 | resource.TestCheckResourceAttr(name, "quality_gates.0.condition.0.threshold", "50"), 42 | ), 43 | }, 44 | }, 45 | }) 46 | } 47 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_qualityprofile_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func testAccSonarqubeQualityProfileDataSourceConfig(rnd string, name string, language string) string { 11 | return fmt.Sprintf(` 12 | resource "sonarqube_qualityprofile" "%[1]s" { 13 | name = "%[2]s" 14 | language = "%[3]s" 15 | } 16 | 17 | data "sonarqube_qualityprofile" "%[1]s" { 18 | key = sonarqube_qualityprofile.%[1]s.id 19 | }`, rnd, name, language) 20 | } 21 | 22 | func testAccSonarqubeQualityProfileDataSourceConfigNoId(rnd string, name string, language string) string { 23 | return fmt.Sprintf(` 24 | resource "sonarqube_qualityprofile" "%[1]s" { 25 | name = "%[2]s" 26 | language = "%[3]s" 27 | } 28 | 29 | data "sonarqube_qualityprofile" "%[1]s" { 30 | name = sonarqube_qualityprofile.%[1]s.name 31 | language = sonarqube_qualityprofile.%[1]s.language 32 | }`, rnd, name, language) 33 | } 34 | 35 | func TestAccSonarqubeQualityProfileDataSource(t *testing.T) { 36 | rnd := generateRandomResourceName() 37 | name := "data.sonarqube_qualityprofile." + rnd 38 | 39 | resource.Test(t, resource.TestCase{ 40 | PreCheck: func() { testAccPreCheck(t) }, 41 | Providers: testAccProviders, 42 | Steps: []resource.TestStep{ 43 | { 44 | Config: testAccSonarqubeQualityProfileDataSourceConfig(rnd, "testAccSonarqubeQualityProfileDataSource", "js"), 45 | Check: resource.ComposeTestCheckFunc( 46 | resource.TestCheckResourceAttr(name, "name", "testAccSonarqubeQualityProfileDataSource"), 47 | resource.TestCheckResourceAttr(name, "language", "js"), 48 | ), 49 | }, 50 | }, 51 | }) 52 | } 53 | 54 | func TestAccSonarqubeQualityProfileDataSourceNoId(t *testing.T) { 55 | rnd := generateRandomResourceName() 56 | name := "data.sonarqube_qualityprofile." + rnd 57 | 58 | resource.Test(t, resource.TestCase{ 59 | PreCheck: func() { testAccPreCheck(t) }, 60 | Providers: testAccProviders, 61 | Steps: []resource.TestStep{ 62 | { 63 | Config: testAccSonarqubeQualityProfileDataSourceConfigNoId(rnd, "testAccSonarqubeQualityProfileDataSourceNoId", "cs"), 64 | Check: resource.ComposeTestCheckFunc( 65 | resource.TestCheckResourceAttr(name, "name", "testAccSonarqubeQualityProfileDataSourceNoId"), 66 | resource.TestCheckResourceAttr(name, "language", "cs"), 67 | ), 68 | }, 69 | }, 70 | }) 71 | } 72 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_qualityprofiles_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func testAccSonarqubeQualityProfilesDataSourceConfig(rnd string, name string, language string) string { 11 | return fmt.Sprintf(` 12 | resource "sonarqube_qualityprofile" "%[1]s" { 13 | name = "%[2]s" 14 | language = "%[3]s" 15 | } 16 | 17 | data "sonarqube_qualityprofiles" "%[1]s" { 18 | name = "%[2]s" 19 | language = "%[3]s" 20 | depends_on = [sonarqube_qualityprofile.%[1]s] 21 | }`, rnd, name, language) 22 | } 23 | 24 | func TestAccSonarqubeQualityProfilesDataSource(t *testing.T) { 25 | rnd := generateRandomResourceName() 26 | name := "data.sonarqube_qualityprofiles." + rnd 27 | 28 | resource.Test(t, resource.TestCase{ 29 | PreCheck: func() { testAccPreCheck(t) }, 30 | Providers: testAccProviders, 31 | Steps: []resource.TestStep{ 32 | { 33 | Config: testAccSonarqubeQualityProfilesDataSourceConfig(rnd, "testAccSonarqubeQualityProfilesDataSource", "js"), 34 | Check: resource.ComposeTestCheckFunc( 35 | resource.TestCheckResourceAttr(name, "quality_profiles.#", "1"), 36 | resource.TestCheckResourceAttr(name, "quality_profiles.0.name", "testAccSonarqubeQualityProfilesDataSource"), 37 | resource.TestCheckResourceAttr(name, "quality_profiles.0.language", "js"), 38 | ), 39 | }, 40 | }, 41 | }) 42 | } 43 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_rule.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 5 | ) 6 | 7 | func dataSourceSonarqubeRule() *schema.Resource { 8 | return &schema.Resource{ 9 | Description: "Use this data source to get a Sonarqube rule resource", 10 | Read: dataSourceSonarqubeRuleRead, 11 | Schema: map[string]*schema.Schema{ 12 | "key": { 13 | Type: schema.TypeString, 14 | Required: true, 15 | Description: "The key of the sonarqube rule. Should be :. https://next.sonarqube.com/sonarqube/web_api/api/rules?query=api%2Frules%2Fcreate", 16 | }, 17 | "markdown_description": { 18 | Type: schema.TypeString, 19 | Computed: true, 20 | Description: "Rule description", 21 | }, 22 | "name": { 23 | Type: schema.TypeString, 24 | Computed: true, 25 | Description: "Rule name", 26 | }, 27 | "severity": { 28 | Type: schema.TypeString, 29 | Computed: true, 30 | Description: "Rule severity", 31 | }, 32 | "status": { 33 | Type: schema.TypeString, 34 | Computed: true, 35 | Description: "Rule status", 36 | }, 37 | "template_key": { 38 | Type: schema.TypeString, 39 | Computed: true, 40 | Description: "Key of the template rule", 41 | }, 42 | "type": { 43 | Type: schema.TypeString, 44 | Computed: true, 45 | Description: "Rule type", 46 | }, 47 | }, 48 | } 49 | } 50 | 51 | func dataSourceSonarqubeRuleRead(d *schema.ResourceData, m interface{}) error { 52 | d.SetId(d.Get("key").(string)) 53 | return resourceSonarqubeRuleRead(d, m) 54 | } 55 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_rule_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func testAccSonarqubeRuleDataSourceConfig(rnd string, custom_key string, markdown_description string, name string, template_key string, severity string, status string, type_p string) string { 11 | return fmt.Sprintf(` 12 | resource "sonarqube_rule" "%[1]s" { 13 | custom_key = "%[2]s" 14 | markdown_description = "%[3]s" 15 | name = "%[4]s" 16 | template_key = "%[5]s" 17 | severity = "%[6]s" 18 | status = "%[7]s" 19 | type = "%[8]s" 20 | } 21 | 22 | data "sonarqube_rule" "%[1]s" { 23 | key = sonarqube_rule.%[1]s.id 24 | }`, rnd, custom_key, markdown_description, name, template_key, severity, status, type_p) 25 | } 26 | 27 | func TestAccSonarqubeRuleDataSource(t *testing.T) { 28 | rnd := generateRandomResourceName() 29 | name := "data.sonarqube_rule." + rnd 30 | 31 | resource.Test(t, resource.TestCase{ 32 | PreCheck: func() { testAccPreCheck(t) }, 33 | Providers: testAccProviders, 34 | Steps: []resource.TestStep{ 35 | { 36 | Config: testAccSonarqubeRuleDataSourceConfig(rnd, "basicRule", "markdown_description", "name", "xml:XPathCheck", "INFO", "READY", "VULNERABILITY"), 37 | Check: resource.ComposeTestCheckFunc( 38 | resource.TestCheckResourceAttr(name, "markdown_description", "markdown_description"), 39 | resource.TestCheckResourceAttr(name, "name", "name"), 40 | resource.TestCheckResourceAttr(name, "template_key", "xml:XPathCheck"), 41 | resource.TestCheckResourceAttr(name, "severity", "INFO"), 42 | resource.TestCheckResourceAttr(name, "status", "READY"), 43 | resource.TestCheckResourceAttr(name, "type", "VULNERABILITY"), 44 | ), 45 | }, 46 | }, 47 | }) 48 | } 49 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_user.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 5 | ) 6 | 7 | func dataSourceSonarqubeUser() *schema.Resource { 8 | return &schema.Resource{ 9 | Description: "Use this data source to get a Sonarqube User resource", 10 | Read: dataSourceSonarqubeUserRead, 11 | Schema: map[string]*schema.Schema{ 12 | "login_name": { 13 | Type: schema.TypeString, 14 | Required: true, 15 | Description: "The login name of the user", 16 | }, 17 | "name": { 18 | Type: schema.TypeString, 19 | Computed: true, 20 | Description: "The name of the user", 21 | }, 22 | "email": { 23 | Type: schema.TypeString, 24 | Computed: true, 25 | Description: "The email of the user", 26 | }, 27 | "is_local": { 28 | Type: schema.TypeBool, 29 | Computed: true, 30 | Description: "Whether the user is local", 31 | }, 32 | }, 33 | } 34 | } 35 | 36 | func dataSourceSonarqubeUserRead(d *schema.ResourceData, m interface{}) error { 37 | d.SetId(d.Get("login_name").(string)) 38 | return resourceSonarqubeUserRead(d, m) 39 | } 40 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_user_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func testAccSonarqubeUserDataSourceConfig(rnd string, name string, email string, password string) string { 11 | return fmt.Sprintf(` 12 | resource "sonarqube_user" "%[1]s" { 13 | login_name = "%[2]s" 14 | name = "%[2]s" 15 | email = "%[3]s" 16 | password = "%[4]s" 17 | } 18 | 19 | data "sonarqube_user" "%[1]s" { 20 | login_name = sonarqube_user.%[1]s.login_name 21 | }`, rnd, name, email, password) 22 | } 23 | 24 | func TestAccSonarqubeUserDataSource(t *testing.T) { 25 | rnd := generateRandomResourceName() 26 | name := "data.sonarqube_user." + rnd 27 | 28 | resource.Test(t, resource.TestCase{ 29 | PreCheck: func() { testAccPreCheck(t) }, 30 | Providers: testAccProviders, 31 | Steps: []resource.TestStep{ 32 | { 33 | Config: testAccSonarqubeUserDataSourceConfig(rnd, "testAccSonarqubeUserDataSource", "terraform-test-user-data-source@sonarqube.com", "secret-sauce37!"), 34 | Check: resource.ComposeTestCheckFunc( 35 | resource.TestCheckResourceAttr(name, "login_name", "testAccSonarqubeUserDataSource"), 36 | resource.TestCheckResourceAttr(name, "email", "terraform-test-user-data-source@sonarqube.com"), 37 | ), 38 | }, 39 | }, 40 | }) 41 | } 42 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_user_tokens_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func testAccSonarqubeUserTokensDataSourceConfig(rnd string, name string) string { 11 | return fmt.Sprintf(` 12 | resource "sonarqube_user" "%[1]s" { 13 | login_name = "%[2]s" 14 | name = "%[2]s" 15 | password = "secret-Sauce37!" 16 | } 17 | resource "sonarqube_user_token" "%[1]s" { 18 | login_name = sonarqube_user.%[1]s.login_name 19 | name = "%[2]s" 20 | } 21 | 22 | data "sonarqube_user_tokens" "%[1]s" { 23 | login_name = sonarqube_user.%[1]s.login_name 24 | depends_on = [sonarqube_user_token.%[1]s] 25 | }`, rnd, name) 26 | } 27 | 28 | func TestAccSonarqubeUserTokensDataSource(t *testing.T) { 29 | rnd := generateRandomResourceName() 30 | name := "data.sonarqube_user_tokens." + rnd 31 | 32 | resource.Test(t, resource.TestCase{ 33 | PreCheck: func() { testAccPreCheck(t) }, 34 | Providers: testAccProviders, 35 | Steps: []resource.TestStep{ 36 | { 37 | Config: testAccSonarqubeUserTokensDataSourceConfig(rnd, "testAccSonarqubeUserTokensDataSource"), 38 | Check: resource.ComposeTestCheckFunc( 39 | resource.TestCheckResourceAttr(name, "user_tokens.#", "1"), 40 | resource.TestCheckResourceAttr(name, "user_tokens.0.name", "testAccSonarqubeUserTokensDataSource"), 41 | ), 42 | }, 43 | }, 44 | }) 45 | } 46 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_users.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "fmt" 7 | "net/http" 8 | "net/url" 9 | "strings" 10 | 11 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 12 | ) 13 | 14 | func dataSourceSonarqubeUsers() *schema.Resource { 15 | return &schema.Resource{ 16 | Description: "Use this data source to get Sonarqube user resources", 17 | Read: dataSourceSonarqubeUsersRead, 18 | Schema: map[string]*schema.Schema{ 19 | "search": { 20 | Type: schema.TypeString, 21 | Optional: true, 22 | Description: "Search users by login, name and email.", 23 | }, 24 | "users": { 25 | Type: schema.TypeList, 26 | Computed: true, 27 | Elem: &schema.Resource{ 28 | Schema: map[string]*schema.Schema{ 29 | "login_name": { 30 | Type: schema.TypeString, 31 | Computed: true, 32 | Description: "The login name of the user.", 33 | }, 34 | "name": { 35 | Type: schema.TypeString, 36 | Computed: true, 37 | Description: "The name of the user.", 38 | }, 39 | "email": { 40 | Type: schema.TypeString, 41 | Computed: true, 42 | Description: "The email of the user.", 43 | }, 44 | "is_local": { 45 | Type: schema.TypeBool, 46 | Computed: true, 47 | Description: "Whether the user is local.", 48 | }, 49 | }, 50 | }, 51 | Description: "The list of users.", 52 | }, 53 | }, 54 | } 55 | } 56 | 57 | func dataSourceSonarqubeUsersRead(d *schema.ResourceData, m interface{}) error { 58 | d.SetId(fmt.Sprintf("%d", schema.HashString(d.Get("search")))) 59 | 60 | usersReadResponse, err := readUsersFromApi(d, m) 61 | if err != nil { 62 | return err 63 | } 64 | 65 | errs := []error{} 66 | errs = append(errs, d.Set("users", flattenReadUsersResponse(usersReadResponse.Users))) 67 | 68 | return errors.Join(errs...) 69 | } 70 | 71 | func readUsersFromApi(d *schema.ResourceData, m interface{}) (*GetUser, error) { 72 | sonarQubeURL := m.(*ProviderConfiguration).sonarQubeURL 73 | sonarQubeURL.Path = strings.TrimSuffix(sonarQubeURL.Path, "/") + "/api/users/search" 74 | 75 | RawQuery := url.Values{ 76 | "ps": []string{"500"}, 77 | } 78 | 79 | if search, ok := d.GetOk("search"); ok { 80 | RawQuery.Add("q", search.(string)) 81 | } 82 | 83 | sonarQubeURL.RawQuery = RawQuery.Encode() 84 | 85 | resp, err := httpRequestHelper( 86 | m.(*ProviderConfiguration).httpClient, 87 | "GET", 88 | sonarQubeURL.String(), 89 | http.StatusOK, 90 | "readUsersFromApi", 91 | ) 92 | if err != nil { 93 | return nil, fmt.Errorf("readUsersFromApi: Failed to read Sonarqube users: %+v", err) 94 | } 95 | defer resp.Body.Close() 96 | 97 | // Decode response into struct 98 | usersReadResponse := GetUser{} 99 | err = json.NewDecoder(resp.Body).Decode(&usersReadResponse) 100 | if err != nil { 101 | return nil, fmt.Errorf("readUsersFromApi: Failed to decode json into struct: %+v", err) 102 | } 103 | 104 | return &usersReadResponse, nil 105 | } 106 | 107 | func flattenReadUsersResponse(users []User) []interface{} { 108 | usersList := []interface{}{} 109 | 110 | for _, user := range users { 111 | values := map[string]interface{}{ 112 | "login_name": user.Login, 113 | "name": user.Name, 114 | "email": user.Email, 115 | "is_local": user.IsLocal, 116 | } 117 | 118 | usersList = append(usersList, values) 119 | } 120 | 121 | return usersList 122 | } 123 | -------------------------------------------------------------------------------- /sonarqube/data_source_sonarqube_users_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func testAccSonarqubeUsersDataSourceConfig(rnd string, name string, email string, password string) string { 11 | return fmt.Sprintf(` 12 | resource "sonarqube_user" "%[1]s" { 13 | login_name = "%[2]s" 14 | name = "%[2]s" 15 | email = "%[3]s" 16 | password = "%[4]s" 17 | } 18 | 19 | data "sonarqube_users" "%[1]s" { 20 | search = sonarqube_user.%[1]s.name 21 | }`, rnd, name, email, password) 22 | } 23 | 24 | func TestAccSonarqubeUsersDataSource(t *testing.T) { 25 | rnd := generateRandomResourceName() 26 | name := "data.sonarqube_users." + rnd 27 | 28 | resource.Test(t, resource.TestCase{ 29 | PreCheck: func() { testAccPreCheck(t) }, 30 | Providers: testAccProviders, 31 | Steps: []resource.TestStep{ 32 | { 33 | Config: testAccSonarqubeUsersDataSourceConfig(rnd, "testAccSonarqubeUsersDataSource", "terraform-test@sonarqube.com", "secret-sauce37!"), 34 | Check: resource.ComposeTestCheckFunc( 35 | resource.TestCheckResourceAttr(name, "users.#", "1"), 36 | resource.TestCheckResourceAttr(name, "users.0.login_name", "testAccSonarqubeUsersDataSource"), 37 | resource.TestCheckResourceAttr(name, "users.0.name", "testAccSonarqubeUsersDataSource"), 38 | resource.TestCheckResourceAttr(name, "users.0.email", "terraform-test@sonarqube.com"), 39 | resource.TestCheckResourceAttr(name, "users.0.is_local", "true"), 40 | ), 41 | }, 42 | }, 43 | }) 44 | } 45 | -------------------------------------------------------------------------------- /sonarqube/helper_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "strings" 7 | 8 | "github.com/hashicorp/terraform-plugin-testing/helper/acctest" 9 | ) 10 | 11 | func generateRandomResourceName() string { 12 | return acctest.RandStringFromCharSet(10, acctest.CharSetAlpha) 13 | } 14 | 15 | func generateHCLList(s []string) string { 16 | semiformat := fmt.Sprintf("%+q", s) // Turn the slice into a string that looks like ["one" "two" "three"] 17 | tokens := strings.Split(semiformat, " ") // Split this string by spaces 18 | return strings.Join(tokens, ", ") // Join the Slice together (that was split by spaces) with commas 19 | } 20 | 21 | // Turns the map into a string that looks like {"one": "two", "three": "four"} 22 | func generateHCLMap(m map[string]string) string { 23 | b := new(bytes.Buffer) 24 | fmt.Fprintf(b, "{") 25 | for key, value := range m { 26 | fmt.Fprintf(b, "\"%s\":\"%s\", ", key, value) 27 | } 28 | b.Truncate(b.Len() - 2) 29 | fmt.Fprintf(b, "}") 30 | return b.String() 31 | } 32 | -------------------------------------------------------------------------------- /sonarqube/httpHelpers.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "fmt" 7 | "github.com/hashicorp/go-retryablehttp" 8 | "net/http" 9 | "regexp" 10 | ) 11 | 12 | // ErrorResponse struct 13 | type ErrorResponse struct { 14 | Errors []ErrorMessage `json:"errors,omitempty"` 15 | } 16 | 17 | // ErrorMessage struct 18 | type ErrorMessage struct { 19 | Message string `json:"msg,omitempty"` 20 | } 21 | 22 | // Paging used in /search API endpoints 23 | type Paging struct { 24 | PageIndex int64 `json:"pageIndex"` 25 | PageSize int64 `json:"pageSize"` 26 | Total int64 `json:"total"` 27 | } 28 | 29 | // helper function to make api request to sonarqube 30 | func httpRequestHelper(client *retryablehttp.Client, method string, sonarqubeURL string, expectedResponseCode int, resource string) (http.Response, error) { 31 | // Prepare request 32 | req, err := retryablehttp.NewRequest(method, sonarqubeURL, http.NoBody) 33 | if err != nil { 34 | return http.Response{}, fmt.Errorf("failed to create request for resource %s: %w", resource, censorHttpError(err)) 35 | } 36 | 37 | // Execute request 38 | resp, err := client.Do(req) 39 | if err != nil { 40 | return http.Response{}, fmt.Errorf("failed to send request for resource %s: %w", resource, censorHttpError(err)) 41 | } 42 | 43 | // Check response code 44 | if resp.StatusCode != expectedResponseCode { 45 | if resp.Body == http.NoBody { 46 | // No error message in the body 47 | return *resp, fmt.Errorf("statusCode: %v does not match expectedResponseCode: %v for resource %s", resp.StatusCode, expectedResponseCode, resource) 48 | } 49 | 50 | // The response body has content, try to decode the error message 51 | errorResponse := ErrorResponse{} 52 | err = json.NewDecoder(resp.Body).Decode(&errorResponse) 53 | if err != nil { 54 | return *resp, fmt.Errorf("failed to decode error response json into struct for resource %s: %+v", resource, err) 55 | } 56 | if len(errorResponse.Errors) == 0 { 57 | return *resp, fmt.Errorf("statusCode: %v does not match expectedResponseCode for resource %s: %v. No error message found in the response body", resp.StatusCode, resource, expectedResponseCode) 58 | } 59 | return *resp, fmt.Errorf("API returned an error for resource %s: %+v", resource, errorResponse.Errors[0].Message) 60 | } 61 | 62 | return *resp, nil 63 | } 64 | 65 | func censorHttpError(error error) error { 66 | sanitizedError := sanitizeSensitiveURLs(error.Error()) 67 | return errors.New(sanitizedError) 68 | } 69 | 70 | var ( 71 | regexBasicAuth = regexp.MustCompile(`(https?://)([^:]+:)([^@]+)`) 72 | regexToken = regexp.MustCompile(`([&?]token=)([^&"' ]*)`) 73 | regexPassword = regexp.MustCompile(`([&?]password=)([^&"' ]*)`) 74 | regexSecret = regexp.MustCompile(`([&?]secret=)([^&"' ]*)`) 75 | ) 76 | 77 | func sanitizeSensitiveURLs(input string) string { 78 | outputString := regexBasicAuth.ReplaceAllString(input, "${1}***:***") 79 | 80 | outputString = regexToken.ReplaceAllString(outputString, "${1}***") 81 | outputString = regexPassword.ReplaceAllString(outputString, "${1}***") 82 | outputString = regexSecret.ReplaceAllString(outputString, "${1}***") 83 | 84 | return outputString 85 | } 86 | -------------------------------------------------------------------------------- /sonarqube/provider_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 8 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 9 | ) 10 | 11 | var testAccProvider *schema.Provider 12 | var testAccProviders map[string]*schema.Provider 13 | 14 | func init() { 15 | testAccProvider = Provider() 16 | testAccProviders = map[string]*schema.Provider{ 17 | "sonarqube": testAccProvider, 18 | } 19 | } 20 | 21 | func TestMain(m *testing.M) { 22 | resource.TestMain(m) 23 | } 24 | 25 | func TestProvider(t *testing.T) { 26 | if err := Provider().InternalValidate(); err != nil { 27 | t.Fatalf("err: %s", err) 28 | } 29 | } 30 | 31 | func TestProvider_impl(t *testing.T) { 32 | var _ *schema.Provider = Provider() 33 | } 34 | 35 | func testAccPreCheck(t *testing.T) { 36 | testSonarHost(t) 37 | if v := os.Getenv("SONAR_TOKEN"); v == "" { 38 | testSonarUser(t) 39 | testSonarPass(t) 40 | } 41 | } 42 | 43 | func testSonarUser(t *testing.T) { 44 | if v := os.Getenv("SONAR_USER"); v == "" { 45 | t.Fatal("SONAR_USER must be set for this acceptance test") 46 | } 47 | } 48 | 49 | func testSonarPass(t *testing.T) { 50 | if v := os.Getenv("SONAR_PASS"); v == "" { 51 | t.Fatal("SONAR_PASS must be set for this acceptance test") 52 | } 53 | } 54 | 55 | func testSonarHost(t *testing.T) { 56 | if v := os.Getenv("SONAR_HOST"); v == "" { 57 | t.Fatal("SONAR_HOST must be set for this acceptance test") 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /sonarqube/resource_sonarqube_alm_azure_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func init() { 11 | resource.AddTestSweepers("sonarqube_alm_azure", &resource.Sweeper{ 12 | Name: "sonarqube_alm_azure", 13 | F: testSweepSonarqubeAlmAzure, 14 | }) 15 | } 16 | 17 | // TODO: implement sweeper to clean up projects: https://www.terraform.io/docs/extend/testing/acceptance-tests/sweepers.html 18 | func testSweepSonarqubeAlmAzure(r string) error { 19 | return nil 20 | } 21 | 22 | func testAccSonarqubeAlmAzureName(rnd string, name string, url string) string { 23 | return fmt.Sprintf(` 24 | 25 | resource "sonarqube_alm_azure" "%[1]s" { 26 | key = "%[2]s" 27 | personal_access_token = "my_pat" 28 | url = "%[3]s" 29 | }`, rnd, name, url) 30 | } 31 | 32 | func TestAccSonarqubeAlmAzureName(t *testing.T) { 33 | rnd := generateRandomResourceName() 34 | name := "sonarqube_alm_azure." + rnd 35 | 36 | resource.Test(t, resource.TestCase{ 37 | PreCheck: func() { testAccPreCheck(t) }, 38 | Providers: testAccProviders, 39 | Steps: []resource.TestStep{ 40 | { 41 | Config: testAccSonarqubeAlmAzureName(rnd, "testAccSonarqubeAlmAzureName", "https://dev.azure.com/my-org"), 42 | Check: resource.ComposeTestCheckFunc( 43 | resource.TestCheckResourceAttr(name, "key", "testAccSonarqubeAlmAzureName"), 44 | resource.TestCheckResourceAttr(name, "url", "https://dev.azure.com/my-org"), 45 | ), 46 | }, 47 | { 48 | Config: testAccSonarqubeAlmAzureName(rnd, "testAccSonarqubeAlmAzureNameUpdate", "https://dev.azure.com/my-other-org"), 49 | Check: resource.ComposeTestCheckFunc( 50 | resource.TestCheckResourceAttr(name, "key", "testAccSonarqubeAlmAzureNameUpdate"), 51 | resource.TestCheckResourceAttr(name, "url", "https://dev.azure.com/my-other-org"), 52 | ), 53 | }, 54 | }, 55 | }) 56 | } 57 | -------------------------------------------------------------------------------- /sonarqube/resource_sonarqube_alm_github_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func init() { 11 | resource.AddTestSweepers("sonarqube_alm_github", &resource.Sweeper{ 12 | Name: "sonarqube_alm_github", 13 | F: testSweepSonarqubeAlmGithub, 14 | }) 15 | } 16 | 17 | // TODO: implement sweeper to clean up projects: https://www.terraform.io/docs/extend/testing/acceptance-tests/sweepers.html 18 | func testSweepSonarqubeAlmGithub(r string) error { 19 | return nil 20 | } 21 | 22 | func testAccSonarqubeAlmGithubName(rnd string, name string, appId string, clientId string) string { 23 | return fmt.Sprintf(` 24 | 25 | resource "sonarqube_alm_github" "%[1]s" { 26 | app_id = "%[3]s" 27 | client_id = "%[4]s" 28 | client_secret = "secret" 29 | key = "%[2]s" 30 | private_key = "myprivate_key" 31 | url = "https://api.github.com" 32 | webhook_secret = "mysecret" 33 | }`, rnd, name, appId, clientId) 34 | } 35 | 36 | func TestAccSonarqubeAlmGithubName(t *testing.T) { 37 | rnd := generateRandomResourceName() 38 | name := "sonarqube_alm_github." + rnd 39 | 40 | resource.Test(t, resource.TestCase{ 41 | PreCheck: func() { testAccPreCheck(t) }, 42 | Providers: testAccProviders, 43 | Steps: []resource.TestStep{ 44 | { 45 | Config: testAccSonarqubeAlmGithubName(rnd, "testAccSonarqubeAlmGithubName", "123456", "234567"), 46 | Check: resource.ComposeTestCheckFunc( 47 | resource.TestCheckResourceAttr(name, "key", "testAccSonarqubeAlmGithubName"), 48 | resource.TestCheckResourceAttr(name, "app_id", "123456"), 49 | resource.TestCheckResourceAttr(name, "client_id", "234567"), 50 | ), 51 | }, 52 | { 53 | Config: testAccSonarqubeAlmGithubName(rnd, "testAccSonarqubeAlmGithubNameUpdate", "654321", "765432"), 54 | Check: resource.ComposeTestCheckFunc( 55 | resource.TestCheckResourceAttr(name, "key", "testAccSonarqubeAlmGithubNameUpdate"), 56 | resource.TestCheckResourceAttr(name, "app_id", "654321"), 57 | resource.TestCheckResourceAttr(name, "client_id", "765432"), 58 | ), 59 | }, 60 | }, 61 | }) 62 | } 63 | -------------------------------------------------------------------------------- /sonarqube/resource_sonarqube_alm_gitlab_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func init() { 11 | resource.AddTestSweepers("sonarqube_alm_gitlab", &resource.Sweeper{ 12 | Name: "sonarqube_alm_gitlab", 13 | F: testSweepSonarqubeAlmGitlab, 14 | }) 15 | } 16 | 17 | // TODO: implement sweeper to clean up projects: https://www.terraform.io/docs/extend/testing/acceptance-tests/sweepers.html 18 | func testSweepSonarqubeAlmGitlab(r string) error { 19 | return nil 20 | } 21 | 22 | func testAccSonarqubeAlmGitlabName(rnd string, name string, personalAccessToken string) string { 23 | return fmt.Sprintf(` 24 | 25 | resource "sonarqube_alm_gitlab" "%[1]s" { 26 | personal_access_token = "%[3]s" 27 | key = "%[2]s" 28 | url = "https://%[3]s.gitlab.com/api/v4" 29 | }`, rnd, name, personalAccessToken) 30 | } 31 | 32 | func TestAccSonarqubeAlmGitlabName(t *testing.T) { 33 | rnd := generateRandomResourceName() 34 | name := "sonarqube_alm_gitlab." + rnd 35 | 36 | resource.Test(t, resource.TestCase{ 37 | PreCheck: func() { testAccPreCheck(t) }, 38 | Providers: testAccProviders, 39 | Steps: []resource.TestStep{ 40 | { 41 | Config: testAccSonarqubeAlmGitlabName(rnd, "testAccSonarqubeAlmGitlabName", "123456"), 42 | Check: resource.ComposeTestCheckFunc( 43 | resource.TestCheckResourceAttr(name, "key", "testAccSonarqubeAlmGitlabName"), 44 | resource.TestCheckResourceAttr(name, "personal_access_token", "123456"), 45 | resource.TestCheckResourceAttr(name, "url", "https://123456.gitlab.com/api/v4"), 46 | ), 47 | }, 48 | { 49 | Config: testAccSonarqubeAlmGitlabName(rnd, "testAccSonarqubeAlmGitlabNameUpdate", "654321"), 50 | Check: resource.ComposeTestCheckFunc( 51 | resource.TestCheckResourceAttr(name, "key", "testAccSonarqubeAlmGitlabNameUpdate"), 52 | resource.TestCheckResourceAttr(name, "personal_access_token", "654321"), 53 | resource.TestCheckResourceAttr(name, "url", "https://654321.gitlab.com/api/v4"), 54 | ), 55 | }, 56 | }, 57 | }) 58 | } 59 | -------------------------------------------------------------------------------- /sonarqube/resource_sonarqube_group_member_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func init() { 11 | resource.AddTestSweepers("sonarqube_group_member", &resource.Sweeper{ 12 | Name: "sonarqube_group_member", 13 | F: testSweepSonarqubeGroupMemberSweeper, 14 | }) 15 | } 16 | 17 | // TODO: implement sweeper to clean up groups: https://www.terraform.io/docs/extend/testing/acceptance-tests/sweepers.html 18 | func testSweepSonarqubeGroupMemberSweeper(r string) error { 19 | return nil 20 | } 21 | 22 | func testAccSonarqubeGroupMemberBasicConfig(rnd string, groupName string, loginName string) string { 23 | return fmt.Sprintf(` 24 | resource "sonarqube_user" "%[1]s_user" { 25 | login_name = "%[3]s" 26 | name = "Test User" 27 | email = "terraform-test@sonarqube.com" 28 | password = "secret-sauce!" 29 | } 30 | 31 | resource "sonarqube_group" "%[1]s_group" { 32 | name = "%[2]s" 33 | } 34 | 35 | resource "sonarqube_group_member" "%[1]s" { 36 | name = sonarqube_group.%[1]s_group.name 37 | login_name = sonarqube_user.%[1]s_user.login_name 38 | } 39 | `, rnd, groupName, loginName) 40 | } 41 | 42 | func TestAccSonarqubeGroupMemberBasic(t *testing.T) { 43 | rnd := generateRandomResourceName() 44 | name := "sonarqube_group_member." + rnd 45 | 46 | resource.Test(t, resource.TestCase{ 47 | PreCheck: func() { testAccPreCheck(t) }, 48 | Providers: testAccProviders, 49 | Steps: []resource.TestStep{ 50 | { 51 | Config: testAccSonarqubeGroupMemberBasicConfig(rnd, "testAccSonarqubeGroup", "testAccSonarqubeUser"), 52 | Check: resource.ComposeTestCheckFunc( 53 | resource.TestCheckResourceAttr(name, "name", "testAccSonarqubeGroup"), 54 | resource.TestCheckResourceAttr(name, "login_name", "testAccSonarqubeUser"), 55 | ), 56 | }, 57 | }, 58 | }) 59 | } 60 | -------------------------------------------------------------------------------- /sonarqube/resource_sonarqube_group_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func init() { 11 | resource.AddTestSweepers("sonarqube_group", &resource.Sweeper{ 12 | Name: "sonarqube_group", 13 | F: testSweepSonarqubeGroupSweeper, 14 | }) 15 | } 16 | 17 | // TODO: implement sweeper to clean up groups: https://www.terraform.io/docs/extend/testing/acceptance-tests/sweepers.html 18 | func testSweepSonarqubeGroupSweeper(r string) error { 19 | return nil 20 | } 21 | 22 | func testAccSonarqubeGroupBasicConfig(rnd string, name string, description string) string { 23 | return fmt.Sprintf(` 24 | resource "sonarqube_group" "%[1]s" { 25 | name = "%[2]s" 26 | description = "%[3]s" 27 | } 28 | `, rnd, name, description) 29 | } 30 | 31 | func TestAccSonarqubeGroupBasic(t *testing.T) { 32 | rnd := generateRandomResourceName() 33 | name := "sonarqube_group." + rnd 34 | groupName := "testAccSonarqubeGroup" + rnd 35 | groupDescription := "testAccSonarqubeDescription" + rnd 36 | 37 | resource.Test(t, resource.TestCase{ 38 | PreCheck: func() { testAccPreCheck(t) }, 39 | Providers: testAccProviders, 40 | Steps: []resource.TestStep{ 41 | { 42 | Config: testAccSonarqubeGroupBasicConfig(rnd, groupName, groupDescription), 43 | Check: resource.ComposeTestCheckFunc( 44 | resource.TestCheckResourceAttr(name, "name", groupName), 45 | resource.TestCheckResourceAttr(name, "description", groupDescription), 46 | ), 47 | }, 48 | }, 49 | }) 50 | } 51 | 52 | func TestAccSonarqubeGroupUpdate(t *testing.T) { 53 | rnd := generateRandomResourceName() 54 | name := "sonarqube_group." + rnd 55 | groupName := "testAccSonarqubeGroup" + rnd 56 | updatedGroupName := "testAccSonarqubeGroupUpdated" + rnd 57 | 58 | resource.Test(t, resource.TestCase{ 59 | PreCheck: func() { testAccPreCheck(t) }, 60 | Providers: testAccProviders, 61 | Steps: []resource.TestStep{ 62 | { 63 | Config: testAccSonarqubeGroupBasicConfig(rnd, groupName, "group description"), 64 | Check: resource.ComposeTestCheckFunc( 65 | resource.TestCheckResourceAttr(name, "name", groupName), 66 | resource.TestCheckResourceAttr(name, "description", "group description"), 67 | ), 68 | }, 69 | { 70 | Config: testAccSonarqubeGroupBasicConfig(rnd, groupName, "group description 2"), 71 | Check: resource.ComposeTestCheckFunc( 72 | resource.TestCheckResourceAttr(name, "name", groupName), 73 | resource.TestCheckResourceAttr(name, "description", "group description 2"), 74 | ), 75 | }, 76 | { 77 | Config: testAccSonarqubeGroupBasicConfig(rnd, updatedGroupName, "group description 3"), 78 | Check: resource.ComposeTestCheckFunc( 79 | resource.TestCheckResourceAttr(name, "name", updatedGroupName), 80 | resource.TestCheckResourceAttr(name, "description", "group description 3"), 81 | ), 82 | }, 83 | }, 84 | }) 85 | } 86 | 87 | func TestAccSonarqubeGroupImport(t *testing.T) { 88 | rnd := generateRandomResourceName() 89 | name := "sonarqube_group." + rnd 90 | groupName := "testAccSonarqubeGroup" + rnd 91 | groupDescription := "testAccSonarqubeGroupDescription" + rnd 92 | 93 | resource.Test(t, resource.TestCase{ 94 | PreCheck: func() { testAccPreCheck(t) }, 95 | Providers: testAccProviders, 96 | Steps: []resource.TestStep{ 97 | { 98 | Config: testAccSonarqubeGroupBasicConfig(rnd, groupName, groupDescription), 99 | }, 100 | { 101 | ResourceName: name, 102 | ImportState: true, 103 | Check: resource.ComposeTestCheckFunc( 104 | resource.TestCheckResourceAttr(name, "name", groupName), 105 | resource.TestCheckResourceAttr(name, "description", groupDescription), 106 | ), 107 | }, 108 | }, 109 | }) 110 | } 111 | -------------------------------------------------------------------------------- /sonarqube/resource_sonarqube_project_main_branch_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func init() { 11 | resource.AddTestSweepers("sonarqube_project_main_branch", &resource.Sweeper{ 12 | Name: "sonarqube_project_main_branch", 13 | F: testSweepSonarqubeProjectMainBranchSweeper, 14 | }) 15 | } 16 | 17 | // TODO: implement sweeper to clean up projects: https://www.terraform.io/docs/extend/testing/acceptance-tests/sweepers.html 18 | func testSweepSonarqubeProjectMainBranchSweeper(r string) error { 19 | return nil 20 | } 21 | 22 | func testAccSonarqubeProjectMainBranchName(rnd string, projName string, branchName string) string { 23 | return fmt.Sprintf(` 24 | resource "sonarqube_project" "%[1]s" { 25 | name = "%[2]s" 26 | project = "%[2]s" 27 | visibility = "public" 28 | } 29 | 30 | resource "sonarqube_project_main_branch" "%[1]s" { 31 | name = "%[3]s" 32 | project = sonarqube_project.%[1]s.project 33 | }`, rnd, projName, branchName) 34 | } 35 | 36 | func TestAccSonarqubeProjectMainBranchName(t *testing.T) { 37 | rnd := generateRandomResourceName() 38 | name := "sonarqube_project_main_branch." + rnd 39 | 40 | resource.Test(t, resource.TestCase{ 41 | PreCheck: func() { testAccPreCheck(t) }, 42 | Providers: testAccProviders, 43 | Steps: []resource.TestStep{ 44 | { 45 | Config: testAccSonarqubeProjectMainBranchName(rnd, "testAccSonarqubeProjectMainBranchName", "test"), 46 | Check: resource.ComposeTestCheckFunc( 47 | resource.TestCheckResourceAttr(name, "project", "testAccSonarqubeProjectMainBranchName"), 48 | resource.TestCheckResourceAttr(name, "name", "test"), 49 | ), 50 | }, 51 | { 52 | ResourceName: name, 53 | ImportState: true, 54 | ImportStateVerify: true, 55 | Check: resource.ComposeTestCheckFunc( 56 | resource.TestCheckResourceAttr(name, "project", "testAccSonarqubeProjectMainBranchName"), 57 | resource.TestCheckResourceAttr(name, "name", "test"), 58 | ), 59 | }, 60 | { 61 | Config: testAccSonarqubeProjectMainBranchName(rnd, "testAccSonarqubeProjectMainBranchName", "main"), 62 | Check: resource.ComposeTestCheckFunc( 63 | resource.TestCheckResourceAttr(name, "project", "testAccSonarqubeProjectMainBranchName"), 64 | resource.TestCheckResourceAttr(name, "name", "main"), 65 | ), 66 | }, 67 | { 68 | ResourceName: name, 69 | ImportState: true, 70 | ImportStateVerify: true, 71 | Check: resource.ComposeTestCheckFunc( 72 | resource.TestCheckResourceAttr(name, "project", "testAccSonarqubeProjectMainBranchName"), 73 | resource.TestCheckResourceAttr(name, "name", "main"), 74 | ), 75 | }, 76 | { 77 | Config: testAccSonarqubeProjectMainBranchName(rnd, "testAccSonarqubeProjectMainBranchName", "slash/branch"), 78 | Check: resource.ComposeTestCheckFunc( 79 | resource.TestCheckResourceAttr(name, "project", "testAccSonarqubeProjectMainBranchName"), 80 | resource.TestCheckResourceAttr(name, "name", "slash/branch"), 81 | ), 82 | }, 83 | { 84 | ResourceName: name, 85 | ImportState: true, 86 | ImportStateVerify: true, 87 | Check: resource.ComposeTestCheckFunc( 88 | resource.TestCheckResourceAttr(name, "project", "testAccSonarqubeProjectMainBranchName"), 89 | resource.TestCheckResourceAttr(name, "name", "slash/branch"), 90 | ), 91 | }, 92 | }, 93 | }) 94 | } 95 | -------------------------------------------------------------------------------- /sonarqube/resource_sonarqube_qualitygate_project_association_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func init() { 11 | resource.AddTestSweepers("sonarqube_qualitygate_project_association", &resource.Sweeper{ 12 | Name: "sonarqube_qualitygate_project_association", 13 | F: testSweepSonarqubeQualitygateProjectAssociationSweeper, 14 | }) 15 | } 16 | 17 | // TODO: implement sweeper to clean up projects: https://www.terraform.io/docs/extend/testing/acceptance-tests/sweepers.html 18 | func testSweepSonarqubeQualitygateProjectAssociationSweeper(r string) error { 19 | return nil 20 | } 21 | 22 | func testAccSonarqubeQualitygateProjectAssociationGateName(rnd string, name string) string { 23 | return fmt.Sprintf(` 24 | resource "sonarqube_qualitygate" "%[1]s" { 25 | name = "%[2]s" 26 | 27 | condition { 28 | metric = "new_coverage" 29 | op = "LT" 30 | threshold = "30" 31 | } 32 | } 33 | 34 | resource "sonarqube_project" "%[1]s" { 35 | name = "%[2]s" 36 | project = "%[2]s" 37 | visibility = "public" 38 | } 39 | 40 | resource "sonarqube_qualitygate_project_association" "%[1]s" { 41 | gatename = sonarqube_qualitygate.%[1]s.name 42 | projectkey = sonarqube_project.%[1]s.project 43 | }`, rnd, name) 44 | } 45 | 46 | func TestAccSonarqubeQualitygateProjectAssociationGateName(t *testing.T) { 47 | rnd := generateRandomResourceName() 48 | name := "sonarqube_qualitygate_project_association." + rnd 49 | 50 | resource.Test(t, resource.TestCase{ 51 | PreCheck: func() { testAccPreCheck(t) }, 52 | Providers: testAccProviders, 53 | Steps: []resource.TestStep{ 54 | { 55 | Config: testAccSonarqubeQualitygateProjectAssociationGateName(rnd, "testAccSonarqubeProjectAssociationGateName"), 56 | Check: resource.ComposeTestCheckFunc( 57 | resource.TestCheckResourceAttr(name, "gatename", "testAccSonarqubeProjectAssociationGateName"), 58 | resource.TestCheckResourceAttr(name, "projectkey", "testAccSonarqubeProjectAssociationGateName"), 59 | ), 60 | }, 61 | { 62 | ResourceName: name, 63 | ImportState: true, 64 | ImportStateVerify: true, 65 | Check: resource.ComposeTestCheckFunc( 66 | resource.TestCheckResourceAttr(name, "gatename", "testAccSonarqubeProjectAssociationGateName"), 67 | resource.TestCheckResourceAttr(name, "projectkey", "testAccSonarqubeProjectAssociationGateName"), 68 | ), 69 | }, 70 | }, 71 | }) 72 | } 73 | -------------------------------------------------------------------------------- /sonarqube/resource_sonarqube_qualitygate_usergroup_association_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/go-version" 8 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 9 | ) 10 | 11 | func init() { 12 | resource.AddTestSweepers("sonarqube_qualitygate_usergroup_association", &resource.Sweeper{ 13 | Name: "sonarqube_qualitygate_usergroup_association", 14 | F: testSweepSonarqubeQualitygateUsergroupAssociationSweeper, 15 | }) 16 | } 17 | 18 | // TODO: implement sweeper to clean up projects: https://www.terraform.io/docs/extend/testing/acceptance-tests/sweepers.html 19 | func testSweepSonarqubeQualitygateUsergroupAssociationSweeper(r string) error { 20 | return nil 21 | } 22 | func testAccPreCheckQualityGatePermissionFeature(t *testing.T) { 23 | sonarQubeVersion := testAccProvider.Meta().(*ProviderConfiguration).sonarQubeVersion 24 | 25 | minimumVersion, _ := version.NewVersion("9.2") 26 | if sonarQubeVersion.LessThan(minimumVersion) { 27 | t.Skipf("Skipping test of unsupported feature") 28 | } 29 | } 30 | 31 | func testAccSonarqubeQualitygateGroupAssociationGateName(rnd string, name string) string { 32 | return fmt.Sprintf(` 33 | resource "sonarqube_group" "%[1]s" { 34 | name = "%[2]s" 35 | description = "foo" 36 | } 37 | 38 | resource "sonarqube_qualitygate" "%[1]s" { 39 | name = "%[2]s" 40 | 41 | condition { 42 | metric = "new_coverage" 43 | op = "LT" 44 | threshold = "30" 45 | } 46 | } 47 | 48 | resource "sonarqube_qualitygate_usergroup_association" "%[1]s" { 49 | gatename = sonarqube_qualitygate.%[1]s.name 50 | group_name = sonarqube_group.%[1]s.name 51 | }`, rnd, name) 52 | } 53 | 54 | func TestAccSonarqubeQualitygateGroupAssociationGateName(t *testing.T) { 55 | rnd := generateRandomResourceName() 56 | name := "sonarqube_qualitygate_usergroup_association." + rnd 57 | 58 | resource.Test(t, resource.TestCase{ 59 | PreCheck: func() { testAccPreCheck(t); testAccPreCheckQualityGatePermissionFeature(t) }, 60 | Providers: testAccProviders, 61 | Steps: []resource.TestStep{ 62 | { 63 | Config: testAccSonarqubeQualitygateGroupAssociationGateName(rnd, "ping"), 64 | Check: resource.ComposeTestCheckFunc( 65 | resource.TestCheckResourceAttr(name, "gatename", "ping"), 66 | resource.TestCheckResourceAttr(name, "group_name", "ping"), 67 | ), 68 | }, 69 | }, 70 | }) 71 | } 72 | 73 | func testAccSonarqubeQualitygateUserAssociationGateName(rnd string, name string) string { 74 | return fmt.Sprintf(` 75 | resource "sonarqube_user" "%[1]s" { 76 | login_name = "%[2]s" 77 | name = "%[2]s" 78 | password = "secret-sauce37!" 79 | } 80 | 81 | resource "sonarqube_qualitygate" "%[1]s" { 82 | name = "%[2]s" 83 | 84 | condition { 85 | metric = "new_coverage" 86 | op = "LT" 87 | threshold = "30" 88 | } 89 | } 90 | 91 | resource "sonarqube_qualitygate_usergroup_association" "%[1]s" { 92 | gatename = sonarqube_qualitygate.%[1]s.name 93 | login_name = sonarqube_user.%[1]s.name 94 | }`, rnd, name) 95 | } 96 | 97 | func TestAccSonarqubeQualitygateUserAssociationGateName(t *testing.T) { 98 | rnd := generateRandomResourceName() 99 | name := "sonarqube_qualitygate_usergroup_association." + rnd 100 | 101 | resource.Test(t, resource.TestCase{ 102 | PreCheck: func() { testAccPreCheck(t); testAccPreCheckQualityGatePermissionFeature(t) }, 103 | Providers: testAccProviders, 104 | Steps: []resource.TestStep{ 105 | { 106 | Config: testAccSonarqubeQualitygateUserAssociationGateName(rnd, "pong"), 107 | Check: resource.ComposeTestCheckFunc( 108 | resource.TestCheckResourceAttr(name, "gatename", "pong"), 109 | resource.TestCheckResourceAttr(name, "login_name", "pong"), 110 | ), 111 | }, 112 | }, 113 | }) 114 | } 115 | -------------------------------------------------------------------------------- /sonarqube/resource_sonarqube_qualityprofile_activate_rule_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func init() { 11 | resource.AddTestSweepers("sonarqube_qualityprofile_activate_rule", &resource.Sweeper{ 12 | Name: "sonarqube_qualityprofile_activate_rule", 13 | F: testSweeepSonarqibeQualityprofileActivateRuleSweeper, 14 | }) 15 | } 16 | 17 | func testSweeepSonarqibeQualityprofileActivateRuleSweeper(r string) error { 18 | return nil 19 | } 20 | 21 | func testAccSonarqubeQualityprofileActivateRuleBasicConfig(rnd string, name string, key string, severity string) string { 22 | return fmt.Sprintf(` 23 | resource "sonarqube_qualityprofile" "%[1]s" { 24 | name = "%[2]s" 25 | language = "xml" 26 | } 27 | 28 | resource "sonarqube_rule" "%[1]s" { 29 | custom_key = "%[3]s" 30 | markdown_description = "My rule" 31 | name = "%[3]s" 32 | severity = "%[4]s" 33 | template_key = "xml:XPathCheck" 34 | type = "VULNERABILITY" 35 | } 36 | 37 | resource "sonarqube_qualityprofile_activate_rule" "%[1]s" { 38 | key = sonarqube_qualityprofile.%[1]s.key 39 | rule = sonarqube_rule.%[1]s.id 40 | severity = "%[4]s" 41 | }`, rnd, name, key, severity) 42 | } 43 | 44 | func TestAccSonarqubeQualityprofileActivateRuleBasic(t *testing.T) { 45 | rnd := generateRandomResourceName() 46 | name := "sonarqube_qualityprofile_activate_rule." + rnd 47 | 48 | resource.Test(t, resource.TestCase{ 49 | PreCheck: func() { testAccPreCheck(t) }, 50 | Providers: testAccProviders, 51 | Steps: []resource.TestStep{ 52 | { 53 | Config: testAccSonarqubeQualityprofileActivateRuleBasicConfig(rnd, "testProfile", "activateRule", "BLOCKER"), 54 | Check: resource.ComposeTestCheckFunc( 55 | resource.TestCheckResourceAttrSet(name, "key"), 56 | resource.TestCheckResourceAttrSet(name, "rule"), 57 | resource.TestCheckResourceAttr(name, "severity", "BLOCKER"), 58 | ), 59 | }, 60 | { 61 | ResourceName: name, 62 | ImportState: true, 63 | ImportStateVerify: true, 64 | ImportStateVerifyIgnore: []string{"key", "reset", "rule", "severity"}, 65 | Check: resource.ComposeTestCheckFunc( 66 | resource.TestCheckResourceAttrSet(name, "key"), 67 | resource.TestCheckResourceAttrSet(name, "rule"), 68 | resource.TestCheckResourceAttr(name, "severity", "BLOCKER"), 69 | ), 70 | }, 71 | }, 72 | }) 73 | } 74 | -------------------------------------------------------------------------------- /sonarqube/resource_sonarqube_qualityprofile_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func init() { 11 | resource.AddTestSweepers("sonarqube_qualityprofile", &resource.Sweeper{ 12 | Name: "sonarqube_qualityprofile", 13 | F: testSweepSonarqubeQualityProfileSweeper, 14 | }) 15 | } 16 | 17 | func testSweepSonarqubeQualityProfileSweeper(r string) error { 18 | return nil 19 | } 20 | 21 | func testAccSonarqubeQualityProfileBasicConfig(rnd string, name string, language string) string { 22 | return fmt.Sprintf(` 23 | resource "sonarqube_qualityprofile" "%[1]s" { 24 | name = "%[2]s" 25 | language = "%[3]s" 26 | }`, rnd, name, language) 27 | } 28 | 29 | func TestAccSonarqubeQualityProfileBasic(t *testing.T) { 30 | rnd := generateRandomResourceName() 31 | name := "sonarqube_qualityprofile." + rnd 32 | 33 | resource.Test(t, resource.TestCase{ 34 | PreCheck: func() { testAccPreCheck(t) }, 35 | Providers: testAccProviders, 36 | Steps: []resource.TestStep{ 37 | { 38 | Config: testAccSonarqubeQualityProfileBasicConfig(rnd, "testAccSonarqubeQualityProfile", "js"), 39 | Check: resource.ComposeTestCheckFunc( 40 | resource.TestCheckResourceAttr(name, "name", "testAccSonarqubeQualityProfile"), 41 | resource.TestCheckResourceAttr(name, "language", "js"), 42 | ), 43 | }, 44 | { 45 | ResourceName: name, 46 | ImportState: true, 47 | ImportStateVerify: true, 48 | Check: resource.ComposeTestCheckFunc( 49 | resource.TestCheckResourceAttr(name, "name", "testAccSonarqubeQualityProfile"), 50 | resource.TestCheckResourceAttr(name, "language", "js"), 51 | resource.TestCheckResourceAttrSet(name, "key"), 52 | ), 53 | }, 54 | }, 55 | }) 56 | } 57 | -------------------------------------------------------------------------------- /sonarqube/resource_sonarqube_rules_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func init() { 11 | resource.AddTestSweepers("sonarqube_rule", &resource.Sweeper{ 12 | Name: "sonarqube_rule", 13 | F: testSweepSonarqubeRuleSweeper, 14 | }) 15 | } 16 | 17 | func testSweepSonarqubeRuleSweeper(r string) error { 18 | return nil 19 | } 20 | 21 | func testAccSonarqubeRuleBasicConfig(rnd string, custom_key string, markdown_description string, name string, template_key string, severity string, status string, type_p string) string { 22 | return fmt.Sprintf(` 23 | resource "sonarqube_rule" "%[1]s" { 24 | custom_key = "%[2]s" 25 | markdown_description = "%[3]s" 26 | name = "%[4]s" 27 | template_key = "%[5]s" 28 | severity = "%[6]s" 29 | status = "%[7]s" 30 | type = "%[8]s" 31 | }`, rnd, custom_key, markdown_description, name, template_key, severity, status, type_p) 32 | } 33 | 34 | func TestAccSonarqubeRuleBasic(t *testing.T) { 35 | rnd := generateRandomResourceName() 36 | name := "sonarqube_rule." + rnd 37 | 38 | resource.Test(t, resource.TestCase{ 39 | PreCheck: func() { testAccPreCheck(t) }, 40 | Providers: testAccProviders, 41 | Steps: []resource.TestStep{ 42 | { 43 | Config: testAccSonarqubeRuleBasicConfig(rnd, "basicRule", "markdown_description", "name", "xml:XPathCheck", "INFO", "READY", "VULNERABILITY"), 44 | Check: resource.ComposeTestCheckFunc( 45 | resource.TestCheckResourceAttr(name, "custom_key", "basicRule"), 46 | resource.TestCheckResourceAttr(name, "markdown_description", "markdown_description"), 47 | resource.TestCheckResourceAttr(name, "name", "name"), 48 | resource.TestCheckResourceAttr(name, "template_key", "xml:XPathCheck"), 49 | resource.TestCheckResourceAttr(name, "severity", "INFO"), 50 | resource.TestCheckResourceAttr(name, "status", "READY"), 51 | resource.TestCheckResourceAttr(name, "type", "VULNERABILITY"), 52 | ), 53 | }, 54 | { 55 | ResourceName: name, 56 | ImportState: true, 57 | ImportStateVerify: true, 58 | ImportStateVerifyIgnore: []string{"custom_key", "prevent_reactivation"}, 59 | Check: resource.ComposeTestCheckFunc( 60 | resource.TestCheckResourceAttr(name, "custom_key", "basicRule"), 61 | resource.TestCheckResourceAttr(name, "markdown_description", "markdown_description"), 62 | resource.TestCheckResourceAttr(name, "name", "name"), 63 | resource.TestCheckResourceAttr(name, "template_key", "xml:XPathCheck"), 64 | resource.TestCheckResourceAttr(name, "severity", "INFO"), 65 | resource.TestCheckResourceAttr(name, "status", "READY"), 66 | resource.TestCheckResourceAttr(name, "type", "VULNERABILITY"), 67 | ), 68 | }, 69 | }, 70 | }) 71 | } 72 | -------------------------------------------------------------------------------- /sonarqube/resource_sonarqube_user_external_identity_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "regexp" 6 | "testing" 7 | 8 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 9 | ) 10 | 11 | func init() { 12 | resource.AddTestSweepers("sonarqube_user_external_identity", &resource.Sweeper{ 13 | Name: "sonarqube_user_external_identity", 14 | F: testSweepSonarqubeUserExteernalIdentitySweeper, 15 | }) 16 | } 17 | 18 | func testSweepSonarqubeUserExteernalIdentitySweeper(r string) error { 19 | return nil 20 | } 21 | 22 | func testAccSonarqubeUserExternalIdentityConfig(rnd string, login string, externalIdentity string, externalProvider string) string { 23 | return fmt.Sprintf(` 24 | resource "sonarqube_user" "%[1]s" { 25 | login_name = "%[2]s" 26 | name = "Test User" 27 | email = "terraform-test@sonarqube.com" 28 | is_local = false 29 | } 30 | 31 | resource "sonarqube_user_external_identity" "%[1]s" { 32 | login_name = sonarqube_user.%[1]s.login_name 33 | external_identity = "%[3]s" 34 | external_provider = "%[4]s" 35 | }`, rnd, login, externalIdentity, externalProvider) 36 | } 37 | 38 | func TestAccSonarqubeUserExternalIdentity(t *testing.T) { 39 | rnd := generateRandomResourceName() 40 | name := "sonarqube_user_external_identity." + rnd 41 | 42 | resource.Test(t, resource.TestCase{ 43 | PreCheck: func() { testAccPreCheck(t) }, 44 | Providers: testAccProviders, 45 | Steps: []resource.TestStep{ 46 | { 47 | Config: testAccSonarqubeUserExternalIdentityConfig(rnd, "testAccSonarqubeUser", "terraform-test@sonarqube.com", "sonarqube"), // Provider "sonarbube" is deprecated in 9.8. "LDAP" works in 9.8 but not in current LTS. 48 | Check: resource.ComposeTestCheckFunc( 49 | resource.TestCheckResourceAttr(name, "login_name", "testAccSonarqubeUser"), 50 | resource.TestCheckResourceAttr(name, "external_identity", "terraform-test@sonarqube.com"), 51 | resource.TestCheckResourceAttr(name, "external_provider", "sonarqube"), 52 | ), 53 | }, 54 | }, 55 | }) 56 | } 57 | 58 | func testAccSonarqubeUserExternalIdentityLocalUserConfig(rnd string, login string, externalIdentity string, externalProvider string) string { 59 | return fmt.Sprintf(` 60 | resource "sonarqube_user" "%[1]s" { 61 | login_name = "%[2]s" 62 | name = "Test User" 63 | email = "terraform-test@sonarqube.com" 64 | is_local = true 65 | password = "secret-sauce1" 66 | } 67 | 68 | resource "sonarqube_user_external_identity" "%[1]s" { 69 | login_name = sonarqube_user.%[1]s.login_name 70 | external_identity = "%[3]s" 71 | external_provider = "%[4]s" 72 | }`, rnd, login, externalIdentity, externalProvider) 73 | } 74 | 75 | func TestAccSonarqubeUserExternalLocalUserIdentity(t *testing.T) { 76 | rnd := generateRandomResourceName() 77 | 78 | resource.Test(t, resource.TestCase{ 79 | PreCheck: func() { testAccPreCheck(t) }, 80 | Providers: testAccProviders, 81 | Steps: []resource.TestStep{ 82 | { 83 | Config: testAccSonarqubeUserExternalIdentityLocalUserConfig(rnd, "testAccSonarqubeUser", "terraform-test@sonarqube.com", "sonarqube"), // Provider "sonarbube" is deprecated in 9.8. "LDAP" works in 9.8 but not in current LTS. 84 | ExpectError: regexp.MustCompile("error setting external identity: Sonarqube user 'testAccSonarqubeUser' is not 'external'"), 85 | }, 86 | }, 87 | }) 88 | } 89 | -------------------------------------------------------------------------------- /sonarqube/resource_sonarqube_user_test.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 8 | ) 9 | 10 | func init() { 11 | resource.AddTestSweepers("sonarqube_user", &resource.Sweeper{ 12 | Name: "sonarqube_user", 13 | F: testSweepSonarqubeUserSweeper, 14 | }) 15 | } 16 | 17 | func testSweepSonarqubeUserSweeper(r string) error { 18 | return nil 19 | } 20 | 21 | func testAccSonarqubeUserLocalConfig(rnd string, name string, email string, password string) string { 22 | return fmt.Sprintf(` 23 | resource "sonarqube_user" "%[1]s" { 24 | login_name = "%[2]s" 25 | name = "%[2]s" 26 | email = "%[3]s" 27 | password = "%[4]s" 28 | }`, rnd, name, email, password) 29 | } 30 | 31 | // Disable test for now 32 | // https://github.com/jdamata/terraform-provider-sonarqube/actions/runs/14957377030/job/42014850178?pr=305#step:7:1201 33 | func testAccSonarqubeUserLocal(t *testing.T) { 34 | rnd := generateRandomResourceName() 35 | name := "sonarqube_user." + rnd 36 | 37 | resource.Test(t, resource.TestCase{ 38 | PreCheck: func() { testAccPreCheck(t) }, 39 | Providers: testAccProviders, 40 | Steps: []resource.TestStep{ 41 | { 42 | Config: testAccSonarqubeUserLocalConfig(rnd, "testAccSonarqubeUserLocal", "terraform-test@sonarqube.com", "secret-sauce37!"), 43 | Check: resource.ComposeTestCheckFunc( 44 | resource.TestCheckResourceAttr(name, "name", "testAccSonarqubeUserLocal"), 45 | resource.TestCheckResourceAttr(name, "email", "terraform-test@sonarqube.com"), 46 | ), 47 | }, 48 | { 49 | Config: testAccSonarqubeUserLocalConfig(rnd, "testAccSonarqubeUserLocal", "terraform-test2@sonarqube.com", "secret-sauce38!"), 50 | Check: resource.ComposeTestCheckFunc( 51 | resource.TestCheckResourceAttr(name, "name", "testAccSonarqubeUserLocal"), 52 | resource.TestCheckResourceAttr(name, "email", "terraform-test2@sonarqube.com"), 53 | ), 54 | }, 55 | { 56 | ResourceName: name, 57 | ImportState: true, 58 | ImportStateVerify: true, 59 | ImportStateVerifyIgnore: []string{"password"}, 60 | Check: resource.ComposeTestCheckFunc( 61 | resource.TestCheckResourceAttr(name, "name", "testAccSonarqubeUserLocal"), 62 | ), 63 | }, 64 | }, 65 | }) 66 | } 67 | 68 | func testAccSonarqubeUserNotLocalConfig(rnd string, name string, email string) string { 69 | return fmt.Sprintf(` 70 | resource "sonarqube_user" "%[1]s" { 71 | login_name = "%[2]s" 72 | name = "%[2]s" 73 | email = "%[3]s" 74 | is_local = false 75 | }`, rnd, name, email) 76 | } 77 | 78 | func TestAccSonarqubeUserNotLocal(t *testing.T) { 79 | rnd := generateRandomResourceName() 80 | name := "sonarqube_user." + rnd 81 | 82 | resource.Test(t, resource.TestCase{ 83 | PreCheck: func() { testAccPreCheck(t) }, 84 | Providers: testAccProviders, 85 | Steps: []resource.TestStep{ 86 | { 87 | Config: testAccSonarqubeUserNotLocalConfig(rnd, "testAccSonarqubeUserNotLocal", "terraform-test@sonarqube.com"), 88 | Check: resource.ComposeTestCheckFunc( 89 | resource.TestCheckResourceAttr(name, "name", "testAccSonarqubeUserNotLocal"), 90 | resource.TestCheckResourceAttr(name, "email", "terraform-test@sonarqube.com"), 91 | ), 92 | }, 93 | { 94 | ResourceName: name, 95 | ImportState: true, 96 | ImportStateVerify: true, 97 | Check: resource.ComposeTestCheckFunc( 98 | resource.TestCheckResourceAttr(name, "name", "testAccSonarqubeUserNotLocal"), 99 | ), 100 | }, 101 | }, 102 | }) 103 | } 104 | -------------------------------------------------------------------------------- /sonarqube/util.go: -------------------------------------------------------------------------------- 1 | package sonarqube 2 | 3 | import ( 4 | "reflect" 5 | "sort" 6 | ) 7 | 8 | // Checks if two string slices are equal, optionally ignoring ordering 9 | func stringSlicesEqual(a, b []string, ignoreOrder bool) bool { 10 | if ignoreOrder { 11 | sort.Slice(a, func(i, j int) bool { 12 | return a[i] < a[j] 13 | }) 14 | sort.Slice(b, func(i, j int) bool { 15 | return b[i] < b[j] 16 | }) 17 | } 18 | 19 | return reflect.DeepEqual(a, b) 20 | } 21 | -------------------------------------------------------------------------------- /templates/index.md.tmpl: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "Provider: sonarqube" 3 | description: |- 4 | The sonarqube provider is used to configure sonarqube. The provider needs to be configured with a url, and either with user and password or token. 5 | --- 6 | 7 | # Provider configuration 8 | 9 | The sonarqube provider is used to configure sonarqube. The provider needs to be configured with a url, and either with user and password or token. 10 | 11 | ## Example: Authenticate with username and password 12 | 13 | ```terraform 14 | terraform { 15 | required_providers { 16 | sonarqube = { 17 | source = "jdamata/sonarqube" 18 | } 19 | } 20 | } 21 | 22 | provider "sonarqube" { 23 | user = "admin" 24 | pass = "admin" 25 | host = "http://127.0.0.1:9000" 26 | } 27 | ``` 28 | 29 | ## Example: Authenticate with token 30 | 31 | ```terraform 32 | terraform { 33 | required_providers { 34 | sonarqube = { 35 | source = "jdamata/sonarqube" 36 | } 37 | } 38 | } 39 | 40 | provider "sonarqube" { 41 | token = "d4at55a6f7r199bd707h39625685510880gbf7ff" 42 | host = "http://127.0.0.1:9000" 43 | } 44 | ``` 45 | 46 | ## Argument Reference 47 | 48 | The following arguments are supported: 49 | 50 | - `user` - (Optional) Sonarqube user. This can also be set via the `SONARQUBE_USER` environment variable. 51 | - `pass` - (Optional) Sonarqube pass. This can also be set via the `SONARQUBE_PASS` environment variable. 52 | - `token` - (Optional) Sonarqube token. This can also be set via the `SONARQUBE_TOKEN` environment variable. 53 | - `host` - (Required) Sonarqube url. This can be also be set via the `SONARQUBE_HOST` environment variable. 54 | - `installed_version` - (Optional) The version of the Sonarqube server. When specified, the provider will avoid requesting this from the 55 | server during the initialization process. This can be helpful when using the same Terraform code to install Sonarqube and configure it. 56 | - `tls_insecure_skip_verify` - (Optional) Allows ignoring insecure certificates when set to true. Defaults to false. Disabling TLS verification 57 | is dangerous and should only be done for local testing. 58 | - `anonymize_user_on_delete` - (Optional) Allows anonymizing users on destroy. Requires Sonarqube version >= `9.7`. This can be helpful 59 | to comply with regulations like [GDPR](https://en.wikipedia.org/wiki/General_Data_Protection_Regulation). 60 | -------------------------------------------------------------------------------- /templates/resources/new_code_periods.md.tmpl: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" 3 | subcategory: "" 4 | description: |- 5 | {{ .Description | plainmarkdown | trimspace | prefixlines " " }} 6 | --- 7 | 8 | # {{.Name}} ({{.Type}}) 9 | 10 | {{ .Description | trimspace }} 11 | 12 | ## Example Usage 13 | 14 | ### Example: Set the global new code period to a number of days 15 | {{ tffile "examples/resources/sonarqube_new_code_periods/global.tf" }} 16 | 17 | ### Example: create a project and set its new code period to a reference branch 18 | {{ tffile "examples/resources/sonarqube_new_code_periods/project.tf" }} 19 | 20 | {{ .SchemaMarkdown | trimspace }} 21 | -------------------------------------------------------------------------------- /templates/resources/permissions.md.tmpl: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" 3 | subcategory: "" 4 | description: |- 5 | {{ .Description | plainmarkdown | trimspace | prefixlines " " }} 6 | --- 7 | 8 | # {{.Name}} ({{.Type}}) 9 | 10 | {{ .Description | trimspace }} 11 | 12 | ## Example Usage 13 | 14 | ### Example: Set global admin permissions for a group called "my-admins" 15 | {{ tffile "examples/resources/sonarqube_permissions/global-admin.tf" }} 16 | 17 | ### Example: Set project admin permissions for a group called "my-project-admins" 18 | {{ tffile "examples/resources/sonarqube_permissions/project-admin.tf" }} 19 | 20 | ### Example: Set project admin permissions for a group called "my-project-admins on a permission template" 21 | {{ tffile "examples/resources/sonarqube_permissions/project-template.tf" }} 22 | 23 | ### Example: Set codeviewer & user permissions on project level for a user called "johndoe" 24 | {{ tffile "examples/resources/sonarqube_permissions/project-user.tf" }} 25 | 26 | {{ .SchemaMarkdown | trimspace }} 27 | -------------------------------------------------------------------------------- /templates/resources/project.md.tmpl: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" 3 | subcategory: "" 4 | description: |- 5 | {{ .Description | plainmarkdown | trimspace | prefixlines " " }} 6 | --- 7 | 8 | # {{.Name}} ({{.Type}}) 9 | 10 | {{ .Description | trimspace }} 11 | 12 | 13 | ## Example Usage 14 | ### Example: create a project 15 | {{ tffile "examples/resources/sonarqube_project/project.tf" }} 16 | 17 | ### Example: a project with associated settings 18 | {{ tffile "examples/resources/sonarqube_project/project-settings.tf" }} 19 | 20 | {{ .SchemaMarkdown | trimspace }} 21 | -------------------------------------------------------------------------------- /templates/resources/qualitygate.md.tmpl: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" 3 | subcategory: "" 4 | description: |- 5 | {{ .Description | plainmarkdown | trimspace | prefixlines " " }} 6 | --- 7 | 8 | # {{.Name}} ({{.Type}}) 9 | 10 | {{ .Description | trimspace }} 11 | 12 | 13 | ## Example Usage 14 | 15 | {{ tffile "examples/resources/sonarqube_qualitygate/resource.tf" }} 16 | 17 | **Disclaimer: Operator Requirement for Grade Rating Conditions** 18 | 19 | When working with grade rating conditions, (A-D), it is important to note that the "GT" (greater than) operator must be used for the `op` field. This is due to SonarQube's API design. More information can be found in this [issue](https://github.com/jdamata/terraform-provider-sonarqube/issues/171). 20 | 21 | For example, if you are using a grade rating metric such as `new_reliability_rating`, where A represents the highest rating and subsequent letters represent lower ratings, you need to supply the `op` field with "GT" via the provider. Using "LT" will return an error from SonarQube's API: 22 | 23 | ```terraform 24 | condition { 25 | metric = "new_reliability_rating" 26 | op = "GT" 27 | threshold = "1" 28 | } 29 | ``` 30 | 31 | {{ .SchemaMarkdown | trimspace }} 32 | -------------------------------------------------------------------------------- /templates/resources/qualitygate_usergroup_association.md.tmpl: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" 3 | subcategory: "" 4 | description: |- 5 | {{ .Description | plainmarkdown | trimspace | prefixlines " " }} 6 | --- 7 | 8 | # {{.Name}} ({{.Type}}) 9 | 10 | {{ .Description | trimspace }} 11 | 12 | ## Example Usage 13 | ### Example: create a quality gate user association 14 | {{ tffile "examples/resources/sonarqube_qualitygate_usergroup_association/user-association.tf" }} 15 | 16 | ### Example: create a quality gate group association 17 | {{ tffile "examples/resources/sonarqube_qualitygate_usergroup_association/usergroup-association.tf" }} 18 | 19 | {{ .SchemaMarkdown | trimspace }} 20 | -------------------------------------------------------------------------------- /templates/resources/qualityprofile_usergroup_association.md.tmpl: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" 3 | subcategory: "" 4 | description: |- 5 | {{ .Description | plainmarkdown | trimspace | prefixlines " " }} 6 | --- 7 | 8 | # {{.Name}} ({{.Type}}) 9 | 10 | {{ .Description | trimspace }} 11 | 12 | ## Example Usage 13 | ### Example: create a quality profile user association 14 | {{ tffile "examples/resources/sonarqube_qualityprofile_usergroup_association/user-association.tf" }} 15 | 16 | ### Example: create a quality profile group association 17 | {{ tffile "examples/resources/sonarqube_qualityprofile_usergroup_association/usergroup-association.tf" }} 18 | 19 | {{ .SchemaMarkdown | trimspace }} 20 | -------------------------------------------------------------------------------- /templates/resources/setting.md.tmpl: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" 3 | subcategory: "" 4 | description: |- 5 | {{ .Description | plainmarkdown | trimspace | prefixlines " " }} 6 | --- 7 | 8 | # {{.Name}} ({{.Type}}) 9 | 10 | {{ .Description | trimspace }} 11 | 12 | ## Example Usage 13 | ### Example: create a setting with multiple values 14 | {{ tffile "examples/resources/sonarqube_setting/multi-value.tf" }} 15 | 16 | ### Example: create a setting with multiple field values 17 | {{ tffile "examples/resources/sonarqube_setting/multi-field-values.tf" }} 18 | 19 | {{ .SchemaMarkdown | trimspace }} 20 | -------------------------------------------------------------------------------- /templates/resources/user.md.tmpl: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" 3 | subcategory: "" 4 | description: |- 5 | {{ .Description | plainmarkdown | trimspace | prefixlines " " }} 6 | --- 7 | 8 | # {{.Name}} ({{.Type}}) 9 | 10 | {{ .Description | trimspace }} 11 | 12 | ## Example Usage 13 | ### Example: create a local user 14 | {{ tffile "examples/resources/sonarqube_user/local.tf" }} 15 | 16 | ### Example: create a remote user 17 | {{ tffile "examples/resources/sonarqube_user/remote.tf" }} 18 | 19 | {{ .SchemaMarkdown | trimspace }} 20 | -------------------------------------------------------------------------------- /templates/resources/user_token.md.tmpl: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" 3 | subcategory: "" 4 | description: |- 5 | {{ .Description | plainmarkdown | trimspace | prefixlines " " }} 6 | --- 7 | 8 | # {{.Name}} ({{.Type}}) 9 | 10 | {{ .Description | trimspace }} 11 | 12 | ## Example Usage 13 | ### Example: create a user, user token and output the token value 14 | {{ tffile "examples/resources/sonarqube_user_token/user-token.tf" }} 15 | 16 | ### Example: create an expiring global analysis token and output the token value 17 | {{ tffile "examples/resources/sonarqube_user_token/global-analysis-token.tf" }} 18 | 19 | ### Example: create a project, project analysis token, and output the token value 20 | {{ tffile "examples/resources/sonarqube_user_token/project-analysis-token.tf" }} 21 | 22 | {{ .SchemaMarkdown | trimspace }} 23 | -------------------------------------------------------------------------------- /templates/resources/webhook.md.tmpl: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" 3 | subcategory: "" 4 | description: |- 5 | {{ .Description | plainmarkdown | trimspace | prefixlines " " }} 6 | --- 7 | 8 | # {{.Name}} ({{.Type}}) 9 | 10 | {{ .Description | trimspace }} 11 | 12 | ## Example Usage 13 | ### Example: create a webhook 14 | {{ tffile "examples/resources/sonarqube_webhook/webhook.tf" }} 15 | 16 | ### Example: create a webhook owned by a project 17 | {{ tffile "examples/resources/sonarqube_webhook/project-webhook.tf" }} 18 | 19 | {{ .SchemaMarkdown | trimspace }} 20 | -------------------------------------------------------------------------------- /tools/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/jdamata/terraform-provider-sonarqube/tools 2 | 3 | go 1.22.7 4 | toolchain go1.24.1 5 | 6 | require github.com/hashicorp/terraform-plugin-docs v0.20.1 7 | 8 | require ( 9 | github.com/BurntSushi/toml v1.2.1 // indirect 10 | github.com/Kunde21/markdownfmt/v3 v3.1.0 // indirect 11 | github.com/Masterminds/goutils v1.1.1 // indirect 12 | github.com/Masterminds/semver/v3 v3.2.0 // indirect 13 | github.com/Masterminds/sprig/v3 v3.2.3 // indirect 14 | github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect 15 | github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect 16 | github.com/armon/go-radix v1.0.0 // indirect 17 | github.com/bgentry/speakeasy v0.1.0 // indirect 18 | github.com/bmatcuk/doublestar/v4 v4.7.1 // indirect 19 | github.com/cloudflare/circl v1.3.7 // indirect 20 | github.com/fatih/color v1.16.0 // indirect 21 | github.com/google/uuid v1.3.0 // indirect 22 | github.com/hashicorp/cli v1.1.6 // indirect 23 | github.com/hashicorp/errwrap v1.1.0 // indirect 24 | github.com/hashicorp/go-checkpoint v0.5.0 // indirect 25 | github.com/hashicorp/go-cleanhttp v0.5.2 // indirect 26 | github.com/hashicorp/go-multierror v1.1.1 // indirect 27 | github.com/hashicorp/go-retryablehttp v0.7.7 // indirect 28 | github.com/hashicorp/go-uuid v1.0.3 // indirect 29 | github.com/hashicorp/go-version v1.7.0 // indirect 30 | github.com/hashicorp/hc-install v0.9.0 // indirect 31 | github.com/hashicorp/terraform-exec v0.21.0 // indirect 32 | github.com/hashicorp/terraform-json v0.23.0 // indirect 33 | github.com/huandu/xstrings v1.3.3 // indirect 34 | github.com/imdario/mergo v0.3.15 // indirect 35 | github.com/mattn/go-colorable v0.1.13 // indirect 36 | github.com/mattn/go-isatty v0.0.20 // indirect 37 | github.com/mattn/go-runewidth v0.0.9 // indirect 38 | github.com/mitchellh/copystructure v1.2.0 // indirect 39 | github.com/mitchellh/reflectwalk v1.0.2 // indirect 40 | github.com/posener/complete v1.2.3 // indirect 41 | github.com/shopspring/decimal v1.3.1 // indirect 42 | github.com/spf13/cast v1.5.0 // indirect 43 | github.com/yuin/goldmark v1.7.7 // indirect 44 | github.com/yuin/goldmark-meta v1.1.0 // indirect 45 | github.com/zclconf/go-cty v1.15.0 // indirect 46 | go.abhg.dev/goldmark/frontmatter v0.2.0 // indirect 47 | golang.org/x/crypto v0.35.0 // indirect 48 | golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect 49 | golang.org/x/mod v0.21.0 // indirect 50 | golang.org/x/sys v0.30.0 // indirect 51 | golang.org/x/text v0.22.0 // indirect 52 | gopkg.in/yaml.v2 v2.3.0 // indirect 53 | gopkg.in/yaml.v3 v3.0.1 // indirect 54 | ) 55 | -------------------------------------------------------------------------------- /tools/tools.go: -------------------------------------------------------------------------------- 1 | //go:build tools 2 | 3 | package tools 4 | 5 | import ( 6 | // Documentation generation 7 | _ "github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs" 8 | ) 9 | 10 | // * Run the docs generation tool 11 | //go:generate echo "Generate provider documentation..." 12 | //go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs generate 13 | --------------------------------------------------------------------------------