Remove testing user token when provider is configured

Created by: btleedev

Hi,

In my terraform scripts I have an optional GitLab resource that the user can create if a boolean is true/false. The problem I'm having is when

  1. the above boolean is false, AND
  2. the user provides a blank or invalid token, AND
  3. there are no GitLab resources to be looked up, created, updated, or deleted,

then the GitLab provider throws a 401 error. This is because when the provider is configured, it tests the credentials. Is there a specific reason it does this? The ask is for this test to be removed, or at least make the test optional via some attribute. See https://github.com/gitlabhq/terraform-provider-gitlab/blob/master/gitlab/config.go.

Let me know if I'm not thinking about this the right way.

Terraform Version

0.12.29

Affected Resource(s)

  • N/A - provider instantiation

Terraform Configuration Files

variable "gitlab_kubernetes_integration_enabled" {
  description = "Boolean to indicate whether to add the kubernetes cluster to a GitLab group"
  type = bool
}
variable "gitlab_auth_token" {
  description = "An auth token with permission to add the EKS environment to a GitLab group"
  type        = string
  default     = ""
}
variable "gitlab_base_url" {
  description = "The base url for the GitLab instance, EG: https://gitlab.com/api/v4"
  type        = string
  default     = "https://gitlab.com/api/v4"
}
provider "gitlab" {
  token = var.gitlab_auth_token
  base_url = var.gitlab_base_url
}
resource "gitlab_group_cluster" "bar" {
  count = var.gitlab_kubernetes_integration_enabled ? 1 : 0

  group                         = "my-group"
  name                          = "my-name"
  enabled                       = true
  managed                       = false
  kubernetes_api_url            = "https://localhost/"
  kubernetes_token              = "some-token"
  kubernetes_ca_cert            = "some-cert"
  kubernetes_authorization_type = "rbac"
  environment_scope             = "*"
}

Debug Output

Panic Output

Expected Behavior

When

  1. gitlab_kubernetes_integration_enabled is false, AND
  2. gitlab_auth_token is blank , AND
  3. there are no GitLab resources to be looked up, created, updated, or deleted.

Actual Behavior

What actually happened?

Error: GET https://git.nasdaq.com/api/v4/user: 401 {message: 401 Unauthorized}
  on .terraform/modules/eks-dcaas.eks-dcaas/providers.tf line 22, in provider "gitlab":
  22: provider "gitlab" {

Steps to Reproduce

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

  1. terraform plan
  2. specify gitlab_kubernetes_integration_enabled to false

Important Factoids

References

Edited by Timo Furrer