diff --git a/google/node_config.go b/google/node_config.go index 251317b485d..975849c18c1 100644 --- a/google/node_config.go +++ b/google/node_config.go @@ -11,6 +11,7 @@ var schemaNodeConfig = &schema.Schema{ Optional: true, Computed: true, ForceNew: true, + MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "machine_type": { diff --git a/google/resource_container_cluster.go b/google/resource_container_cluster.go index 50dda94d7c2..59ff63b6d0e 100644 --- a/google/resource_container_cluster.go +++ b/google/resource_container_cluster.go @@ -355,9 +355,6 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er } if v, ok := d.GetOk("node_config"); ok { nodeConfigs := v.([]interface{}) - if len(nodeConfigs) > 1 { - return fmt.Errorf("Cannot specify more than one node_config.") - } nodeConfig := nodeConfigs[0].(map[string]interface{}) cluster.NodeConfig = &container.NodeConfig{} diff --git a/google/resource_container_node_pool.go b/google/resource_container_node_pool.go index 0265bab7219..d08ceeb3afc 100644 --- a/google/resource_container_node_pool.go +++ b/google/resource_container_node_pool.go @@ -89,9 +89,6 @@ func resourceContainerNodePoolCreate(d *schema.ResourceData, meta interface{}) e if v, ok := d.GetOk("node_config"); ok { nodeConfigs := v.([]interface{}) - if len(nodeConfigs) > 1 { - return fmt.Errorf("Cannot specify more than one node_config.") - } nodeConfig := nodeConfigs[0].(map[string]interface{}) nodePool.Config = &container.NodeConfig{} @@ -104,6 +101,10 @@ func resourceContainerNodePoolCreate(d *schema.ResourceData, meta interface{}) e nodePool.Config.DiskSizeGb = int64(v.(int)) } + if v, ok = nodeConfig["local_ssd_count"]; ok { + nodePool.Config.LocalSsdCount = int64(v.(int)) + } + if v, ok := nodeConfig["oauth_scopes"]; ok { scopesList := v.([]interface{}) scopes := []string{} @@ -113,6 +114,39 @@ func resourceContainerNodePoolCreate(d *schema.ResourceData, meta interface{}) e nodePool.Config.OauthScopes = scopes } + + if v, ok = nodeConfig["service_account"]; ok { + nodePool.Config.ServiceAccount = v.(string) + } + + if v, ok = nodeConfig["metadata"]; ok { + m := make(map[string]string) + for k, val := range v.(map[string]interface{}) { + m[k] = val.(string) + } + nodePool.Config.Metadata = m + } + + if v, ok = nodeConfig["image_type"]; ok { + nodePool.Config.ImageType = v.(string) + } + + if v, ok = nodeConfig["labels"]; ok { + m := make(map[string]string) + for k, val := range v.(map[string]interface{}) { + m[k] = val.(string) + } + nodePool.Config.Labels = m + } + + if v, ok := nodeConfig["tags"]; ok { + tagsList := v.([]interface{}) + tags := []string{} + for _, v := range tagsList { + tags = append(tags, v.(string)) + } + nodePool.Config.Tags = tags + } } req := &container.CreateNodePoolRequest{ diff --git a/google/resource_container_node_pool_test.go b/google/resource_container_node_pool_test.go index 7728b75cd21..1a19e7afe53 100644 --- a/google/resource_container_node_pool_test.go +++ b/google/resource_container_node_pool_test.go @@ -123,6 +123,39 @@ func testAccCheckContainerNodePoolMatches(n string) resource.TestCheckFunc { } } +func nodepoolCheckMatch(attributes map[string]string, attr string, gcp interface{}) string { + if gcpList, ok := gcp.([]string); ok { + return nodepoolCheckListMatch(attributes, attr, gcpList) + } + tf := attributes[attr] + if tf != gcp { + return nodepoolMatchError(attr, tf, gcp) + } + return "" +} + +func nodepoolCheckListMatch(attributes map[string]string, attr string, gcpList []string) string { + num, err := strconv.Atoi(attributes[attr+".#"]) + if err != nil { + return fmt.Sprintf("Error in number conversion for attribute %s: %s", attr, err) + } + if num != len(gcpList) { + return fmt.Sprintf("NodePool has mismatched %s size.\nTF Size: %d\nGCP Size: %d", attr, num, len(gcpList)) + } + + for i, gcp := range gcpList { + if tf := attributes[fmt.Sprintf("%s.%d", attr, i)]; tf != gcp { + return nodepoolMatchError(fmt.Sprintf("%s[%d]", attr, i), tf, gcp) + } + } + + return "" +} + +func nodepoolMatchError(attr, tf string, gcp interface{}) string { + return fmt.Sprintf("NodePool has mismatched %s.\nTF State: %+v\nGCP State: %+v", attr, tf, gcp) +} + var testAccContainerNodePool_basic = fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "tf-cluster-nodepool-test-%s" @@ -190,36 +223,3 @@ resource "google_container_node_pool" "np_with_node_config_scope_alias" { oauth_scopes = ["compute-rw", "storage-ro", "logging-write", "monitoring"] } }`, acctest.RandString(10), acctest.RandString(10)) - -func nodepoolCheckMatch(attributes map[string]string, attr string, gcp interface{}) string { - if gcpList, ok := gcp.([]string); ok { - return nodepoolCheckListMatch(attributes, attr, gcpList) - } - tf := attributes[attr] - if tf != gcp { - return nodepoolMatchError(attr, tf, gcp) - } - return "" -} - -func nodepoolCheckListMatch(attributes map[string]string, attr string, gcpList []string) string { - num, err := strconv.Atoi(attributes[attr+".#"]) - if err != nil { - return fmt.Sprintf("Error in number conversion for attribute %s: %s", attr, err) - } - if num != len(gcpList) { - return fmt.Sprintf("NodePool has mismatched %s size.\nTF Size: %d\nGCP Size: %d", attr, num, len(gcpList)) - } - - for i, gcp := range gcpList { - if tf := attributes[fmt.Sprintf("%s.%d", attr, i)]; tf != gcp { - return nodepoolMatchError(fmt.Sprintf("%s[%d]", attr, i), tf, gcp) - } - } - - return "" -} - -func nodepoolMatchError(attr, tf string, gcp interface{}) string { - return fmt.Sprintf("NodePool has mismatched %s.\nTF State: %+v\nGCP State: %+v", attr, tf, gcp) -}