namecheap / terraform-provider-namecheap

Terraform provider for Namecheap
Apache License 2.0
146 stars 30 forks source link

Namecheap Provider not using provided API Credentials on initialization in .tf file #75

Open HubertMajewski opened 1 year ago

HubertMajewski commented 1 year ago

When setting up the Namecheap Provider, the following options are provided to set the API user and API key: api_user, api_key. Yet, they do not seem to be used in the actual configuration of the provider per this error:

╷
│ Error: error configuring plugin: rpc error: code = Unknown desc = error initializing provider: namecheap: some credentials information are missing: NAMECHEAP_API_USER,NAMECHEAP_API_KEY
│ 
│   with acme_certificate.cert,
│   on main.tf line 107, in resource "acme_certificate" "cert":
│  107: resource "acme_certificate" "cert" {
│ 
╵

Following example config:

provider "namecheap" {
  user_name = "myUser"
  api_user = "myUser"
  api_key = "myKey"
  client_ip = "1.1.1.1"
  use_sandbox = false
}

...

resource "acme_certificate" "cert" {
  account_key_pem          = acme_registration.reg.account_key_pem
  common_name              = "domain.com"
  certificate_p12_password = random_password.cert.result

  dns_challenge {
    provider = "namecheap"
  }
}
maksym-nazarenko commented 8 months ago

it looks like the acme_certificate resource expects DNS providers to be configured via environment variables, so config {} block is used otherwise:

resource "acme_certificate" "certificate" {
  #...

  dns_challenge {
    provider = "route53"

    config = {
      AWS_ACCESS_KEY_ID     = var.aws_access_key
      AWS_SECRET_ACCESS_KEY = var.aws_secret_key
      AWS_SESSION_TOKEN     = var.aws_security_token
      AWS_DEFAULT_REGION    = "us-east-1"  # OPTIONAL
    }
  }

  #...
}