Multiple cloudflare provider getting authentication error

Now I am likely doing something wrong but I cannot seem to figure out what that might be

Simply put I have 2 cloudflare providers both are aliased

provider "cloudflare" {
  alias     = "development"
  api_token = var.cloudflare_config.development_api_token
}

provider "cloudflare" {
  alias     = "production"
  api_token = var.cloudflare_config.production_api_token
}

terraform {
  required_version = ">= 1.0.0"

  required_providers {

    cloudflare = {
      source                = "cloudflare/cloudflare"
      version               = "3.32.0"
      configuration_aliases = [cloudflare.development, cloudflare.production]
    }
  }
}

I have data files & cloudflare_record resources and am getting the auth issue specifically on the production alias for a cloudflare_record

I have triple checked the api_token, zone ids etc etc they are all matching there respective zone

What makes it more strange is the data resource for the cloudflare_zone using production alias is working and in state just the production cloudflare_record itself throws the error

Not to mention all resources using development provider are working and in state.

Also before you say wrong zone_id/api_token I have those exact variables filled in other workspaces for production only (no alias on the provider) and working just fine.

resource "cloudflare_record" "app" {
  provider = cloudflare.production
  zone_id  = var.cloudflare_config.production_zone_id
  type     = "A"
  name     = "${kubernetes_namespace.environment_namespace.metadata[0].name}.${data.cloudflare_zone.production_zone.name}"
  value    = data.kubernetes_service.nginx.status[0].load_balancer[0].ingress[0].ip
}

Terraform Version: 1.3.3 (terraform cloud vpc driven)
Cloudflare Provider Version: 3.32.0

Hello there, for what it;s worth I had the same issue, and by chance I added a “default provider” and that worked lol

provider "cloudflare" {
  alias     = "development"
  api_token = var.cloudflare_config.development_api_token
}

provider "cloudflare" {
  alias     = "production"
  api_token = var.cloudflare_config.production_api_token
}

provider "cloudflare" {
  api_token = var.cloudflare_config.production_api_token
}

In the child module I also added

required_providers {
    cloudflare = {
      source                = "cloudflare/cloudflare"
      version               = "~> 4.0"
      configuration_aliases = [cloudflare.production, cloudflare.development]
    }
  }
1 Like

Thanks for the tip, I will give it a shot.