mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-06 17:16:44 +00:00
![Darren Haken](/assets/img/avatar_default.png)
This PR also switched us to using the beta API in all cases, and that had a side effect which is worth noting, note included here for posterity. ===== The problem is, we add a GPU, and as per the docs, GKE adds a taint to the node pool saying "don't schedule here unless you tolerate GPUs", which is pretty sensible. Terraform doesn't know about that, because it didn't ask for the taint to be added. So after apply, on refresh, it sees the state of the world (1 taint) and the state of the config (0 taints) and wants to set the world equal to the config. This introduces a diff, which makes the test fail - tests fail if there's a diff after they run. Taints are a beta feature, though. :) And since the config doesn't contain any taints, terraform didn't see any beta features in that node pool ... so it used to send the request to the v1 API. And since the v1 API didn't return anything about taints (since they're a beta feature), terraform happily checked the state of the world (0 taints I know about) vs the config (0 taints), and all was well. This PR makes every node pool refresh request hit the beta API. So now terraform finds out about the taints (which were always there) and the test fails (which it always should have done). The solution is probably to write a little bit of code which suppresses the report of the diff of any taint with value 'nvidia.com/gpu', but only if GPUs are enabled. I think that's something that can be done.
38 lines
1.2 KiB
Go
38 lines
1.2 KiB
Go
package google
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
"strings"
|
|
)
|
|
|
|
//These functions are used by both the `resource_container_node_pool` and `resource_container_cluster` for handling regional clusters
|
|
|
|
func isZone(location string) bool {
|
|
return len(strings.Split(location, "-")) == 3
|
|
}
|
|
|
|
func getLocation(d *schema.ResourceData, config *Config) (string, error) {
|
|
if v, isRegionalCluster := d.GetOk("region"); isRegionalCluster {
|
|
return v.(string), nil
|
|
} else {
|
|
// If region is not explicitly set, use "zone" (or fall back to the provider-level zone).
|
|
// For now, to avoid confusion, we require region to be set in the config to create a regional
|
|
// cluster rather than falling back to the provider-level region.
|
|
return getZone(d, config)
|
|
}
|
|
}
|
|
|
|
// getZone reads the "zone" value from the given resource data and falls back
|
|
// to provider's value if not given. If neither is provided, returns an error.
|
|
func getZone(d TerraformResourceData, config *Config) (string, error) {
|
|
res, ok := d.GetOk("zone")
|
|
if !ok {
|
|
if config.Zone != "" {
|
|
return config.Zone, nil
|
|
}
|
|
return "", fmt.Errorf("Cannot determine zone: set in this resource, or set provider-level zone.")
|
|
}
|
|
return GetResourceNameFromSelfLink(res.(string)), nil
|
|
}
|