Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment variable config not working #26

Closed
jackmtpt opened this issue May 15, 2024 · 6 comments · Fixed by #29
Closed

Environment variable config not working #26

jackmtpt opened this issue May 15, 2024 · 6 comments · Fixed by #29

Comments

@jackmtpt
Copy link

iqUrl := os.Getenv("IQ_SERVER_URL")

Looking at that code it seems like it should be possible to configure the url/username/password via env vars, rather than requiring them to be in plain-text in the configuration files (which for security is obviously unacceptable).

Am I just doing something wrong or are they not meant to work for normal use, and only for the integration tests?

@grahamhar
Copy link
Contributor

grahamhar commented May 15, 2024

Hi @jackmtpt,

Fellow user here. Please could you post the provider block configuration you are using? Also the operating system your are working on.

@jackmtpt
Copy link
Author

terraform {
  required_providers {
    sonatypeiq = {
      source  = "sonatype-nexus-community/sonatypeiq"
      version = "= 0.6.0"
    }
  }
}

If I don't define a provider block for it then I get the following output:

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: Missing required argument
│
│ The argument "password" is required, but was not set.
╵
╷
│ Error: Missing required argument
│
│ The argument "url" is required, but was not set.
╵
╷
│ Error: Missing required argument
│
│ The argument "username" is required, but was not set.
╵

I'm running on Windows, via PowerShell, with the env vars set locally.

Adding this block makes it work:

provider "sonatypeiq" {
  url      = "https://my.url.com"
  username = "user"
  password = "pass"
}

but I want to read the values from the env vars, not hard-code them.

My env vars from powershell:

> ls env:IQ*

Name                           Value
----                           -----
IQ_SERVER_URL                  https://my.url.com
IQ_SERVER_USERNAME             user
IQ_SERVER_PASSWORD             pass

@jackmtpt
Copy link
Author

In fact actually it looks like adding this provider block is sufficient to convince the provider to use the env vars:

provider "sonatypeiq" {
  url      = ""
  username = ""
  password = ""
}

So possibly the issue is that the validation is just too strict - it shouldn't require any value at all to provided if the env vars are present.

@grahamhar
Copy link
Contributor

What happens if you just put an empty provider block?

provider "sonatypeiq" {}

@jackmtpt
Copy link
Author

Sadly that doesn't work either - it just prompts me for the values. With -input=false it just errors out with a slightly different message than if the provider block isn't present at all:

│ Error: Missing required argument
│
│   on provider.tf line 26, in provider "sonatypeiq":
│   26: provider "sonatypeiq" {
│
│ The argument "password" is required, but no definition was found.
╵
╷
│ Error: Missing required argument
│
│   on provider.tf line 26, in provider "sonatypeiq":
│   26: provider "sonatypeiq" {
│
│ The argument "url" is required, but no definition was found.
╵
╷
│ Error: Missing required argument
│
│   on provider.tf line 26, in provider "sonatypeiq":
│   26: provider "sonatypeiq" {
│
│ The argument "username" is required, but no definition was found.
╵

@grahamhar
Copy link
Contributor

Thanks for providing the extra info I'll try to take a stab at fixing this with that extra information. I don't have a windows environment to test on but hopefully I can work it 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 a pull request may close this issue.

2 participants