mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-07 09:36:44 +00:00
![Joe Selman](/assets/img/avatar_default.png)
* Add preemptible as an option to node config * Check for preemptible in test matching functions * Move flattenClusterNodeConfig to node_config * Handle bools properly when comparing in cluster and node pool tests * Use a supported image_type in cluster tests
185 lines
3.8 KiB
Go
185 lines
3.8 KiB
Go
package google
|
|
|
|
import (
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
"github.com/hashicorp/terraform/helper/validation"
|
|
"google.golang.org/api/container/v1"
|
|
)
|
|
|
|
var schemaNodeConfig = &schema.Schema{
|
|
Type: schema.TypeList,
|
|
Optional: true,
|
|
Computed: true,
|
|
ForceNew: true,
|
|
MaxItems: 1,
|
|
Elem: &schema.Resource{
|
|
Schema: map[string]*schema.Schema{
|
|
"machine_type": {
|
|
Type: schema.TypeString,
|
|
Optional: true,
|
|
Computed: true,
|
|
ForceNew: true,
|
|
},
|
|
|
|
"disk_size_gb": {
|
|
Type: schema.TypeInt,
|
|
Optional: true,
|
|
Computed: true,
|
|
ForceNew: true,
|
|
ValidateFunc: validation.IntAtLeast(10),
|
|
},
|
|
|
|
"local_ssd_count": {
|
|
Type: schema.TypeInt,
|
|
Optional: true,
|
|
Computed: true,
|
|
ForceNew: true,
|
|
ValidateFunc: validation.IntAtLeast(0),
|
|
},
|
|
|
|
"oauth_scopes": {
|
|
Type: schema.TypeList,
|
|
Optional: true,
|
|
Computed: true,
|
|
ForceNew: true,
|
|
Elem: &schema.Schema{
|
|
Type: schema.TypeString,
|
|
StateFunc: func(v interface{}) string {
|
|
return canonicalizeServiceScope(v.(string))
|
|
},
|
|
},
|
|
},
|
|
|
|
"service_account": {
|
|
Type: schema.TypeString,
|
|
Optional: true,
|
|
Computed: true,
|
|
ForceNew: true,
|
|
},
|
|
|
|
"metadata": {
|
|
Type: schema.TypeMap,
|
|
Optional: true,
|
|
ForceNew: true,
|
|
Elem: schema.TypeString,
|
|
},
|
|
|
|
"image_type": {
|
|
Type: schema.TypeString,
|
|
Optional: true,
|
|
Computed: true,
|
|
ForceNew: true,
|
|
},
|
|
|
|
"labels": {
|
|
Type: schema.TypeMap,
|
|
Optional: true,
|
|
ForceNew: true,
|
|
Elem: schema.TypeString,
|
|
},
|
|
|
|
"tags": {
|
|
Type: schema.TypeList,
|
|
Optional: true,
|
|
ForceNew: true,
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
},
|
|
|
|
"preemptible": {
|
|
Type: schema.TypeBool,
|
|
Optional: true,
|
|
ForceNew: true,
|
|
Default: false,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
func expandNodeConfig(v interface{}) *container.NodeConfig {
|
|
nodeConfigs := v.([]interface{})
|
|
nodeConfig := nodeConfigs[0].(map[string]interface{})
|
|
|
|
nc := &container.NodeConfig{}
|
|
|
|
if v, ok := nodeConfig["machine_type"]; ok {
|
|
nc.MachineType = v.(string)
|
|
}
|
|
|
|
if v, ok := nodeConfig["disk_size_gb"]; ok {
|
|
nc.DiskSizeGb = int64(v.(int))
|
|
}
|
|
|
|
if v, ok := nodeConfig["local_ssd_count"]; ok {
|
|
nc.LocalSsdCount = int64(v.(int))
|
|
}
|
|
|
|
if v, ok := nodeConfig["oauth_scopes"]; ok {
|
|
scopesList := v.([]interface{})
|
|
scopes := []string{}
|
|
for _, v := range scopesList {
|
|
scopes = append(scopes, canonicalizeServiceScope(v.(string)))
|
|
}
|
|
|
|
nc.OauthScopes = scopes
|
|
}
|
|
|
|
if v, ok := nodeConfig["service_account"]; ok {
|
|
nc.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)
|
|
}
|
|
nc.Metadata = m
|
|
}
|
|
|
|
if v, ok := nodeConfig["image_type"]; ok {
|
|
nc.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)
|
|
}
|
|
nc.Labels = m
|
|
}
|
|
|
|
if v, ok := nodeConfig["tags"]; ok {
|
|
tagsList := v.([]interface{})
|
|
tags := []string{}
|
|
for _, v := range tagsList {
|
|
tags = append(tags, v.(string))
|
|
}
|
|
nc.Tags = tags
|
|
}
|
|
// Preemptible Is Optional+Default, so it always has a value
|
|
nc.Preemptible = nodeConfig["preemptible"].(bool)
|
|
|
|
return nc
|
|
}
|
|
|
|
func flattenNodeConfig(c *container.NodeConfig) []map[string]interface{} {
|
|
config := []map[string]interface{}{
|
|
{
|
|
"machine_type": c.MachineType,
|
|
"disk_size_gb": c.DiskSizeGb,
|
|
"local_ssd_count": c.LocalSsdCount,
|
|
"service_account": c.ServiceAccount,
|
|
"metadata": c.Metadata,
|
|
"image_type": c.ImageType,
|
|
"labels": c.Labels,
|
|
"tags": c.Tags,
|
|
"preemptible": c.Preemptible,
|
|
},
|
|
}
|
|
|
|
if len(c.OauthScopes) > 0 {
|
|
config[0]["oauth_scopes"] = c.OauthScopes
|
|
}
|
|
|
|
return config
|
|
}
|