Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default scopes when creating GKE clusters/node pools #924

Merged
merged 2 commits into from
Jan 8, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions google/node_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import (
"google.golang.org/api/container/v1"
)

// Matches gke-default scope from https://cloud.google.com/sdk/gcloud/reference/container/clusters/create
var defaultOauthScopes = []string{
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
"https://www.googleapis.com/auth/service.management.readonly",
"https://www.googleapis.com/auth/servicecontrol",
"https://www.googleapis.com/auth/trace.append",
}

var schemaNodeConfig = &schema.Schema{
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -104,9 +114,15 @@ var schemaNodeConfig = &schema.Schema{

func expandNodeConfig(v interface{}) *container.NodeConfig {
nodeConfigs := v.([]interface{})
nodeConfig := nodeConfigs[0].(map[string]interface{})
nc := &container.NodeConfig{
// Defaults can't be set on a list in the schema, so set the default on create here.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: technically, this is a set not a list.

OauthScopes: defaultOauthScopes,
}
if len(nodeConfigs) == 0 {
return nc
}

nc := &container.NodeConfig{}
nodeConfig := nodeConfigs[0].(map[string]interface{})

if v, ok := nodeConfig["machine_type"]; ok {
nc.MachineType = v.(string)
Expand Down
12 changes: 8 additions & 4 deletions google/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,6 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
cluster.AddonsConfig = expandClusterAddonsConfig(v)
}

if v, ok := d.GetOk("node_config"); ok {
cluster.NodeConfig = expandNodeConfig(v)
}

if v, ok := d.GetOk("enable_kubernetes_alpha"); ok {
cluster.EnableKubernetesAlpha = v.(bool)
}
Expand All @@ -511,6 +507,14 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
nodePools = append(nodePools, nodePool)
}
cluster.NodePools = nodePools
} else {
// Node Configs have default values that are set in the expand function,
// but can only be set if node pools are unspecified.
cluster.NodeConfig = expandNodeConfig([]interface{}{})
}

if v, ok := d.GetOk("node_config"); ok {
cluster.NodeConfig = expandNodeConfig(v)
}

if v, ok := d.GetOk("ip_allocation_policy"); ok {
Expand Down
5 changes: 1 addition & 4 deletions google/resource_container_node_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,7 @@ func expandNodePool(d *schema.ResourceData, prefix string) (*container.NodePool,
np := &container.NodePool{
Name: name,
InitialNodeCount: int64(nodeCount),
}

if v, ok := d.GetOk(prefix + "node_config"); ok {
np.Config = expandNodeConfig(v)
Config: expandNodeConfig(d.Get(prefix + "node_config")),
}

if v, ok := d.GetOk(prefix + "autoscaling"); ok {
Expand Down