jdamata / terraform-provider-sonarqube

Terraform provider for managing Sonarqube configuration
GNU General Public License v3.0
62 stars 54 forks source link

Sonarqube provider does not fulfill config from environment variables #115

Closed jwilliams-fn closed 1 year ago

jwilliams-fn commented 1 year ago

Terraform Version

1.3.7

Affected Provider

Terraform Configuration Files

terraform {
  required_providers {
    gitlab = {
      source  = "gitlabhq/gitlab"
      version = "3.19.0"
    }
    google-beta = {
      source  = "hashicorp/google-beta"
      version = "4.10.0"
    }
    null = {
      source  = "hashicorp/null"
      version = "3.1.0"
    }
    kubernetes = {
      source  = "hashicorp/kubernetes"
      version = "2.14.0"
    }
    sonarqube = {
      source = "jdamata/sonarqube"
      version = "0.15.6"
    }
  }
  required_version = ">= 1.1.0"
}

provider "sonarqube" {
  host = "https://sonarqube-${local.hostname}"  # Hostname changes depending on the deployment environment (e.g.: dev vs prod)
}

Expected Behavior

Sonarqube provider config should rely on environment variables for reading user, pass, token, host, etc. NOTE: Docs do mention that host is a required parameter, but if the SONAR_HOST env var could be used I don't see why there needs to be a provider block at all.

Our company runs in an environment where we do not use consistent usernames or passwords and all tokens rotate. We have no problem setting environment variables from kubernetes secrets though or on a one-off basis. All terraform code is checked into git so we avoid hard-coding passwords/token whenever possible.

Actual Behavior

Sonarqube provider returned the following errors:

╷                                                                                                                         
│ Error: Missing required argument
│
│   with provider["registry.terraform.io/jdamata/sonarqube"],
│   on <empty> line 0:
│   (source code not available)
│
│ "user": all of `pass,user` must be specified
╵
╷
│ Error: Invalid combination of arguments
│
│   with provider["registry.terraform.io/jdamata/sonarqube"],
│   on <empty> line 0:
│   (source code not available)
│
│ "token": one of `pass,token` must be specified

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform init
  2. terraform plan

References

jwilliams-fn commented 1 year ago

I should also add that if I do hardcode the token into the provider block, I still get the following error:

╷
│ Error: Missing required argument
│ 
│   with module.monolith.provider["registry.terraform.io/jdamata/sonarqube"],
│   on ../monolith/module.tf line 27, in provider "sonarqube":
│   27: provider "sonarqube" {
│ 
│ "user": all of `pass,user` must be specified
jdamata commented 1 year ago

Can you check if the doc/steps i have here works: https://github.com/jdamata/terraform-provider-sonarqube/pull/116

This works ok for me.

jwilliams-fn commented 1 year ago

Ok that worked. Not sure what I did wrong 🤔

Thanks for your patience with my mistake 😅 and also thank you for adding the example to the docs!

jwilliams-fn commented 1 year ago

Apologies re-opening. This worked with username/pass but it failed when I tried a token. Double checking before I forget

jwilliams-fn commented 1 year ago

OK nvm everything is working fine! Just had to unset the SONAR_USER/PASS