<p>I've created a GCP Composer environment <a href="https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/composer_environment" rel="nofollow noreferrer">using Terraform</a>:</p>
<pre><code>terraform {
  required_providers {
    google = {
      source = &quot;hashicorp/google&quot;
      version = &quot;3.5.0&quot;
    }
  }
}

provider &quot;google&quot; {
  credentials = file(&quot;my_key.json&quot;)
  project = &quot;my_project_id&quot;
  region  = &quot;us-east1&quot;
  zone    = &quot;us-east1-b&quot;
}

resource &quot;google_composer_environment&quot; &quot;my_composer_id&quot; {
  name   = &quot;my_composer_name&quot;
  region = &quot;us-east1&quot;
  config {
    node_count = 3
    node_config {
      zone         = &quot;us-east1-b&quot;
      machine_type = &quot;n1-standard-1&quot;
    }
  }
}
</code></pre>
<p>Composer also automatically creates a Kubernetes Engine cluster. Such cluster has a single node pool called <em>default-pool</em>. <strong>I'd like to <a href="https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_node_pool" rel="nofollow noreferrer">create a new node pool</a> inside the cluster created by Composer</strong>. Something like this:</p>
<pre><code>resource &quot;google_container_node_pool&quot; &quot;my_node_pool_id&quot; {
  name       = &quot;my_node_pool_name&quot;
  location   = &quot;us-east1&quot;
  cluster    = ????
  node_count = 0
  node_config {
    preemptible  = true
    machine_type = &quot;n1-standard-1&quot;
  }
  autoscaling  {
    min_node_count = 0
    max_node_count = 3
  }
}
</code></pre>
<p>However, as I didn't create the cluster in the Terraform file (as it was automatically created by Composer), I don't have the reference to it.</p>

Matheus Schaly
<p>Cluster name can be accessed via the key <a href="https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/composer_environment#config.0.gke_cluster" rel="nofollow noreferrer"><code>gke_cluster</code> available in the <code>config</code> section</a> of your Cloud Composer environment :</p>
<pre><code>resource &quot;google_container_node_pool&quot; &quot;my_node_pool_id&quot; {
  name       = &quot;my_node_pool_name&quot;
  location   = &quot;us-east1-b&quot;

  cluster    = element(
      split(&quot;/&quot;,
        lookup(
          google_composer_environment.my_composer_id.config[0],
          &quot;gke_cluster&quot;
        )
      ),
      5
    )

  // ...
}
</code></pre>
<p>The 5th element corresponds to the name of the GKE cluster.</p>
