Skip to content

Commit 32fac9c

Browse files
author
Sébastien GLON
committed
replalce TypeList by TypeSet
1 parent edc9df9 commit 32fac9c

File tree

2 files changed

+71
-9
lines changed

2 files changed

+71
-9
lines changed

google/node_config.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package google
33
import (
44
"github.com/hashicorp/terraform/helper/schema"
55
"github.com/hashicorp/terraform/helper/validation"
6-
"google.golang.org/api/container/v1"
6+
container "google.golang.org/api/container/v1"
77
)
88

99
var schemaNodeConfig = &schema.Schema{
@@ -38,7 +38,7 @@ var schemaNodeConfig = &schema.Schema{
3838
},
3939

4040
"oauth_scopes": {
41-
Type: schema.TypeList,
41+
Type: schema.TypeSet,
4242
Optional: true,
4343
Computed: true,
4444
ForceNew: true,
@@ -48,6 +48,7 @@ var schemaNodeConfig = &schema.Schema{
4848
return canonicalizeServiceScope(v.(string))
4949
},
5050
},
51+
Set: stringScopeHashcode,
5152
},
5253

5354
"service_account": {
@@ -113,11 +114,11 @@ func expandNodeConfig(v interface{}) *container.NodeConfig {
113114
nc.LocalSsdCount = int64(v.(int))
114115
}
115116

116-
if v, ok := nodeConfig["oauth_scopes"]; ok {
117-
scopesList := v.([]interface{})
118-
scopes := []string{}
119-
for _, v := range scopesList {
120-
scopes = append(scopes, canonicalizeServiceScope(v.(string)))
117+
if scopes, ok := nodeConfig["oauth_scopes"]; ok {
118+
scopesSet := scopes.(*schema.Set)
119+
scopes := make([]string, scopesSet.Len())
120+
for i, scope := range scopesSet.List() {
121+
scopes[i] = canonicalizeServiceScope(scope.(string))
121122
}
122123

123124
nc.OauthScopes = scopes
@@ -181,7 +182,7 @@ func flattenNodeConfig(c *container.NodeConfig) []map[string]interface{} {
181182
})
182183

183184
if len(c.OauthScopes) > 0 {
184-
config[0]["oauth_scopes"] = c.OauthScopes
185+
config[0]["oauth_scopes"] = schema.NewSet(stringScopeHashcode, convertStringArrToInterface(c.OauthScopes))
185186
}
186187

187188
return config

google/resource_container_cluster_test.go

+62-1
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,31 @@ func TestAccContainerCluster_withNodeConfig(t *testing.T) {
232232
})
233233
}
234234

235+
func TestAccContainerCluster_withNodeConfigNotSorted(t *testing.T) {
236+
// Make an update with non sorted oauth_scopes
237+
resource.Test(t, resource.TestCase{
238+
PreCheck: func() { testAccPreCheck(t) },
239+
Providers: testAccProviders,
240+
CheckDestroy: testAccCheckContainerClusterDestroy,
241+
Steps: []resource.TestStep{
242+
{
243+
Config: testAccContainerCluster_withNodeConfigNotsorted,
244+
Check: resource.ComposeTestCheckFunc(
245+
testAccCheckContainerCluster(
246+
"google_container_cluster.with_node_config_not_sorted"),
247+
),
248+
},
249+
{
250+
Config: testAccContainerCluster_withNodeConfigNotsorted,
251+
Check: resource.ComposeTestCheckFunc(
252+
testAccCheckContainerCluster(
253+
"google_container_cluster.with_node_config_not_sorted"),
254+
),
255+
},
256+
},
257+
})
258+
}
259+
235260
func TestAccContainerCluster_withNodeConfigScopeAlias(t *testing.T) {
236261
t.Parallel()
237262

@@ -535,7 +560,9 @@ func testAccCheckContainerClusterDestroy(s *terraform.State) error {
535560
}
536561

537562
var setFields map[string]struct{} = map[string]struct{}{
538-
"additional_zones": struct{}{},
563+
"additional_zones": struct{}{},
564+
"node_config.0.oauth_scopes": struct{}{},
565+
"node_pool.0.node_config.0.oauth_scopes": struct{}{},
539566
}
540567

541568
func testAccCheckContainerCluster(n string) resource.TestCheckFunc {
@@ -975,6 +1002,40 @@ resource "google_container_cluster" "with_version" {
9751002
}`, clusterName)
9761003
}
9771004

1005+
var testAccContainerCluster_withNodeConfigNotsorted = fmt.Sprintf(`
1006+
resource "google_container_cluster" "with_node_config_not_sorted" {
1007+
name = "cluster-test-%s"
1008+
zone = "us-central1-f"
1009+
initial_node_count = 1
1010+
1011+
master_auth {
1012+
username = "mr.yoda"
1013+
password = "adoy.rm"
1014+
}
1015+
1016+
node_config {
1017+
machine_type = "n1-standard-1"
1018+
disk_size_gb = 15
1019+
local_ssd_count = 1
1020+
oauth_scopes = [
1021+
"https://www.googleapis.com/auth/compute",
1022+
"https://www.googleapis.com/auth/devstorage.read_only",
1023+
"https://www.googleapis.com/auth/logging.write",
1024+
"monitoring"
1025+
]
1026+
service_account = "default"
1027+
metadata {
1028+
foo = "bar"
1029+
}
1030+
image_type = "COS"
1031+
labels {
1032+
foo = "bar"
1033+
}
1034+
tags = ["foo", "bar"]
1035+
preemptible = true
1036+
}
1037+
}`, acctest.RandString(10))
1038+
9781039
var testAccContainerCluster_withNodeConfig = fmt.Sprintf(`
9791040
resource "google_container_cluster" "with_node_config" {
9801041
name = "cluster-test-%s"

0 commit comments

Comments
 (0)