Partial deletion with provider dependent on child module output

Hello,

I am trying to find a better alternative to my current setup, in which I am defining a provider in the root module which is dependent on the output of a child module. This approach does work with “terraform destroy”, but not when trying to delete only a subset of the child modules from my configuration.

provider "helm": {
 kubernetes = {
  host = module.cluster.kubeconfig.clusters[0].cluster.server
  token = module.cluster.kubeconfig.clusters[0].user.token
 }
}

module "cluster" {
 source = ...
 [...]
}

module "configuration" {
 source = ...
 [...]
}

My goal would be to be able to easily shutdown the cluster but preserve the configuration module. I’ve tried to comment (#) out the cluster module:

provider "helm": {
 kubernetes = {
  host = module.cluster.kubeconfig.clusters[0].cluster.server
  token = module.cluster.kubeconfig.clusters[0].user.token
 }
}

#module "cluster" {
# source = ...
# [...]
#}

module "configuration" {
 source = ...
 [...]
}

Running “terraform apply” gives understandably the error message is “Reference to undeclared module: No module call named “cluster” is declared in the root module.” in the provider “helm”.

As a manual solution I would be able to copy paste the values to the provider “helm” manually, however, I was wondering if there is a better approach to perform that action especially in an automated CI/CD environment? Is my best (only?) bet to split the environment into two different folders to be able to run terraform destroy only on the root configuration containing the cluster module?