Skip to content

Conversation

@kaovd
Copy link

@kaovd kaovd commented Jun 12, 2025

Implements functionality described in #307

Adds additional test to reflect checks

Have tested a local build and found it works fine

Correct configuration:
image

Erroneous configuration where environment var does not exist:

image

@kaovd kaovd force-pushed the task/OauthEnvironmentVariables branch from 710e81e to 275cabf Compare June 12, 2025 15:53
@DRuggeri
Copy link
Member

Hey there, @kaovd - thanks for the pull request! I'm looking at this change and am curious about the use case. I think this is already supported natively in terraform through two existing options:
erraform already supports environment variables natively through several mechanisms:

Option 1: Terraform Variables

variable "oauth_client_id" {
  type      = string
  sensitive = true
}

variable "oauth_client_secret" {
  type      = string
  sensitive = true
}

provider "restapi" {
  uri = "https://graph.microsoft.com"
  
  oauth_client_credentials {
    oauth_client_id      = var.oauth_client_id
    oauth_client_secret  = var.oauth_client_secret
    oauth_token_endpoint = "https://login.microsoftonline.com/..."
  }
}

Then set the values via environment variables (the strings can be variable interpolated from your shell, too):

export TF_VAR_oauth_client_id="your-client-id"
export TF_VAR_oauth_client_secret="your-secret"

Option 2: Using Terraform's env() function (TF 1.2 needed)

provider "restapi" {
  uri = "https://graph.microsoft.com"
  
  oauth_client_credentials {
    oauth_client_id      = env("MY_OAUTH_CLIENT_ID")
    oauth_client_secret  = env("MY_OAUTH_CLIENT_SECRET")
    oauth_token_endpoint = "https://login.microsoftonline.com/..."
  }
}

Is there something missing in the native capabilities that this would close out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants