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

Provider warning for missing api_key, api_user, and user_name even when using NAMECHEAP_* environment variables #72

Open
matei-radu opened this issue Apr 26, 2023 · 1 comment
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@matei-radu
Copy link

Terraform Version

Terraform v1.4.5
on linux_amd64
+ provider registry.terraform.io/namecheap/namecheap v2.1.0

Namecheap provider version

namecheap/namecheap v2.1.0

Affected Resource(s)

The namecheap Terraform provider.

Terraform Configuration Files

Irrelevant for this report.

Debug Output

Irrelevant for this report.

Expected Behavior

The documentation, under Argument Reference, mentions that the provider arguments can be set via environment variables. This is, in fact, preferred as you shouldn't hard-code sensitive data in your Terraform configuration.

Thus, I expected to be able to declare an empty namecheap provider without any warnings:

provider namecheap {}

Actual Behavior

My IDE warns me that api_key, api_user, and user_name are required and missing:

Screenshot from 2023-04-26 18-58-12

Luckily, this is only a warning, because supplying the appropriate NAMECHEAP_* environment variables works as expected.

Steps to Reproduce

Given a Terraform config:

  1. Add namecheap version 2.1.0 as a required provider
terraform {
  required_providers {
    # Other provider data...
    
    namecheap = {
      source = "namecheap/namecheap"
      version = "2.1.0"
    }
  }
}
  1. Create a namecheap provider with no arguments:
provider namecheap {}
  1. Depending on the capabilities of your IDE, you should have a warning of sorts pop up. For reference, I'm using IntelliJ IDEA Ultimate with the official Terraform plugin.

Important Factoids

Looking at the provider source, the properties that are logically required are also programmatically flagged with Required: true, while also having a DefaultFunc pointing to the respective environment variable.

If a property has a default, why should it be required? Or if it is required, then what is the purpose of a default value?

I would recommend Replacing the Required: true with Optional: true because that is what these properties are. For inspiration, the AWS provider does the same. They don't use DefaultFunc but rather a configure function to ensure that the configuration is always complete, however the end result is the same.

@adamdecaf adamdecaf added enhancement New feature or request good first issue Good for newcomers bug Something isn't working and removed enhancement New feature or request labels May 8, 2023
@vetal2409
Copy link
Contributor

@matei-radu Thanks for reporting! We will take it to work!

@vetal2409 vetal2409 self-assigned this Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants