Snowflake provider initialization with count=0 - Why does Snowflake provider still try to connect?

Hey everyone,
I’m running into an issue with provider initialization that I’m hoping someone can help explain or suggest workarounds for.

I have a platform module that optionally includes Snowflake resources. When I don’t need Snowflake (no credentials available), I set count = 0 on the module, but the Snowflake provider still tries to initialize and connect, causing the entire terraform plan/apply to fail.

provider "snowflake" {
  organization_name = var.snowflake_org
  account_name      = var.snowflake_account
  user              = var.snowflake_user
  password          = var.snowflake_password
}
 
module "snowflake_integration" {
  count = var.snowflake_enabled ? 1 : 0
  source = "./modules/snowflake-integration"
  ...
} 

Even with count = 0, I get connection errors because the provider tries to validate credentials during initialization.

So my questions are:

- Why do providers initialize even when no resources use them? Is terraform not considering the count parameter?

  • Is there a way to conditionally initialize providers without splitting modules?

Also, workarounds I’ve tried:

- Dummy credentials: still tries to connect and cannot.

  • Provider aliases: as dummy credentials.
  • Separate modules: could work, but ideally we want to have a single main module with feature flags.

Optional integrations shouldn’t require credentials when disabled.
Am I missing something obvious here? Do you have any way to solve this? Could terragrunt help?
Thanks for any insights!

Hi @m.marchingegno,

The snowflake provider is configured before we can evaluate any snowflake resources. It’s not until we reach those resources are we able to evaluate their expansion to determine how many instances there are.

There currently isn’t any way to conditionally configure a provider in Terraform, that would have to be implemented by the provider itself.