There's no need to fetch available container engine versions when var.kubernetes_version is explicitly defined.
Updates data blocks so we only retrieve engine versions when var.kubernetes_version is set to "latest".
Added Context 📃
We've noticed a planning issue when we try to create a GKE cluster, but the GCP project it's going to be created in doesn't exist yet i.e. we're creating a GKE cluster and it's host GCP project as part of the same plan.
Retrieving data.google_container_engine_versions.region.latest_master_version or data.google_container_engine_versions.zone.latest_master_version fails because they both rely on the host var.project_id existing to work. Buuuut if you're creating the cluster and project as part of the same plan, this won't be the case at plan time.
Counter-intuitively though, we still get this planning error even if we explicitly set a var.kubernetes_version, even though we shouldn't really need to retrieve all available container engine versions at that point. This PR address that by only creating the data blocks when we need to fetch the 'latest' var.kubernetes_version
Personal notes / thoughts ðŸ’
In an ideal world though, we probably shouldn't need to rely on this (which admittedly feels somewhat like a workaround), and instead have some way to fetch all container versions that doesn't really on the host project existing first?
The var.project_id is a little problematic here since it's also what we feed into the data.google_container_engine_versions.region.latest_master_version/data.google_container_engine_versions.zone.latest_master_version blocks, and we don't have a way to pass in a different project id to use for fetching google_container_engine_versions :/
But fixing that might be out of scope of what this PR is trying to address re. when we already know what k8 version we want
Summary / TL;DR 🎯
There's no need to fetch available container engine versions when
var.kubernetes_version
is explicitly defined. Updates data blocks so we only retrieve engine versions whenvar.kubernetes_version
is set to"latest"
.Added Context 📃
We've noticed a planning issue when we try to create a GKE cluster, but the GCP project it's going to be created in doesn't exist yet i.e. we're creating a GKE cluster and it's host GCP project as part of the same plan.
Retrieving
data.google_container_engine_versions.region.latest_master_version
ordata.google_container_engine_versions.zone.latest_master_version
fails because they both rely on the hostvar.project_id
existing to work. Buuuut if you're creating the cluster and project as part of the same plan, this won't be the case at plan time.Counter-intuitively though, we still get this planning error even if we explicitly set a
var.kubernetes_version
, even though we shouldn't really need to retrieve all available container engine versions at that point. This PR address that by only creating the data blocks when we need to fetch the 'latest'var.kubernetes_version
Personal notes / thoughts ðŸ’
In an ideal world though, we probably shouldn't need to rely on this (which admittedly feels somewhat like a workaround), and instead have some way to fetch all container versions that doesn't really on the host project existing first?
The
var.project_id
is a little problematic here since it's also what we feed into thedata.google_container_engine_versions.region.latest_master_version
/data.google_container_engine_versions.zone.latest_master_version
blocks, and we don't have a way to pass in a different project id to use for fetchinggoogle_container_engine_versions
:/But fixing that might be out of scope of what this PR is trying to address re. when we already know what k8 version we want