Skip to content

Commit 1f954e0

Browse files
Sébastien GLONdanawillow
Sébastien GLON
authored andcommitted
Add sort on google_container_cluster auth_scopes (#506)
* replalce TypeList by TypeSet * Add migrate function and test * CORRECT * remove migrate * fix tests
1 parent ec00813 commit 1f954e0

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

google/node_config.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -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

+5-3
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,9 @@ func testAccCheckContainerClusterDestroy(s *terraform.State) error {
535535
}
536536

537537
var setFields map[string]struct{} = map[string]struct{}{
538-
"additional_zones": struct{}{},
538+
"additional_zones": struct{}{},
539+
"node_config.0.oauth_scopes": struct{}{},
540+
"node_pool.0.node_config.0.oauth_scopes": struct{}{},
539541
}
540542

541543
func testAccCheckContainerCluster(n string) resource.TestCheckFunc {
@@ -991,10 +993,10 @@ resource "google_container_cluster" "with_node_config" {
991993
disk_size_gb = 15
992994
local_ssd_count = 1
993995
oauth_scopes = [
996+
"https://www.googleapis.com/auth/monitoring",
994997
"https://www.googleapis.com/auth/compute",
995998
"https://www.googleapis.com/auth/devstorage.read_only",
996-
"https://www.googleapis.com/auth/logging.write",
997-
"https://www.googleapis.com/auth/monitoring"
999+
"https://www.googleapis.com/auth/logging.write"
9981000
]
9991001
service_account = "default"
10001002
metadata {

0 commit comments

Comments
 (0)