@@ -5,8 +5,10 @@ package container
55import (
66 "testing"
77
8+ "github.com/google/go-cmp/cmp"
89 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
910 "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
11+
1012 container "google.golang.org/api/container/v1beta1"
1113)
1214
@@ -290,3 +292,161 @@ func TestContainerCluster_NodeVersionCustomizeDiff(t *testing.T) {
290292 }
291293 }
292294}
295+
296+ func TestContainerCluster_flattenUserManagedKeysConfig (t * testing.T ) {
297+ t .Parallel ()
298+
299+ cases := []struct {
300+ name string
301+ config * container.UserManagedKeysConfig
302+ want []map [string ]interface {}
303+ }{
304+ {
305+ name : "nil" ,
306+ },
307+ {
308+ name : "empty" ,
309+ config : & container.UserManagedKeysConfig {},
310+ },
311+ {
312+ name : "cluster_ca" ,
313+ config : & container.UserManagedKeysConfig {
314+ ClusterCa : "value" ,
315+ },
316+ want : []map [string ]interface {}{
317+ {
318+ "cluster_ca" : "value" ,
319+ "etcd_api_ca" : "" ,
320+ "etcd_peer_ca" : "" ,
321+ "aggregation_ca" : "" ,
322+ "control_plane_disk_encryption_key" : "" ,
323+ "gkeops_etcd_backup_encryption_key" : "" ,
324+ },
325+ },
326+ },
327+ {
328+ name : "etcd_api_ca" ,
329+ config : & container.UserManagedKeysConfig {
330+ EtcdApiCa : "value" ,
331+ },
332+ want : []map [string ]interface {}{
333+ {
334+ "cluster_ca" : "" ,
335+ "etcd_api_ca" : "value" ,
336+ "etcd_peer_ca" : "" ,
337+ "aggregation_ca" : "" ,
338+ "control_plane_disk_encryption_key" : "" ,
339+ "gkeops_etcd_backup_encryption_key" : "" ,
340+ },
341+ },
342+ },
343+ {
344+ name : "etcd_peer_ca" ,
345+ config : & container.UserManagedKeysConfig {
346+ EtcdPeerCa : "value" ,
347+ },
348+ want : []map [string ]interface {}{
349+ {
350+ "cluster_ca" : "" ,
351+ "etcd_api_ca" : "" ,
352+ "etcd_peer_ca" : "value" ,
353+ "aggregation_ca" : "" ,
354+ "control_plane_disk_encryption_key" : "" ,
355+ "gkeops_etcd_backup_encryption_key" : "" ,
356+ },
357+ },
358+ },
359+ {
360+ name : "aggregation_ca" ,
361+ config : & container.UserManagedKeysConfig {
362+ AggregationCa : "value" ,
363+ },
364+ want : []map [string ]interface {}{
365+ {
366+ "cluster_ca" : "" ,
367+ "etcd_api_ca" : "" ,
368+ "etcd_peer_ca" : "" ,
369+ "aggregation_ca" : "value" ,
370+ "control_plane_disk_encryption_key" : "" ,
371+ "gkeops_etcd_backup_encryption_key" : "" ,
372+ },
373+ },
374+ },
375+ {
376+ name : "control_plane_disk_encryption_key" ,
377+ config : & container.UserManagedKeysConfig {
378+ ControlPlaneDiskEncryptionKey : "value" ,
379+ },
380+ want : []map [string ]interface {}{
381+ {
382+ "cluster_ca" : "" ,
383+ "etcd_api_ca" : "" ,
384+ "etcd_peer_ca" : "" ,
385+ "aggregation_ca" : "" ,
386+ "control_plane_disk_encryption_key" : "value" ,
387+ "gkeops_etcd_backup_encryption_key" : "" ,
388+ },
389+ },
390+ },
391+ {
392+ name : "gkeops_etcd_backup_encryption_key" ,
393+ config : & container.UserManagedKeysConfig {
394+ GkeopsEtcdBackupEncryptionKey : "value" ,
395+ },
396+ want : []map [string ]interface {}{
397+ {
398+ "cluster_ca" : "" ,
399+ "etcd_api_ca" : "" ,
400+ "etcd_peer_ca" : "" ,
401+ "aggregation_ca" : "" ,
402+ "control_plane_disk_encryption_key" : "" ,
403+ "gkeops_etcd_backup_encryption_key" : "value" ,
404+ },
405+ },
406+ },
407+ {
408+ name : "service_account_signing_keys" ,
409+ config : & container.UserManagedKeysConfig {
410+ ServiceAccountSigningKeys : []string {"value" },
411+ },
412+ want : []map [string ]interface {}{
413+ {
414+ "cluster_ca" : "" ,
415+ "etcd_api_ca" : "" ,
416+ "etcd_peer_ca" : "" ,
417+ "aggregation_ca" : "" ,
418+ "control_plane_disk_encryption_key" : "" ,
419+ "gkeops_etcd_backup_encryption_key" : "" ,
420+ "service_account_signing_keys" : schema .NewSet (schema .HashString , []interface {}{"value" }),
421+ },
422+ },
423+ },
424+ {
425+ name : "service_account_verification_keys" ,
426+ config : & container.UserManagedKeysConfig {
427+ ServiceAccountVerificationKeys : []string {"value" },
428+ },
429+ want : []map [string ]interface {}{
430+ {
431+ "cluster_ca" : "" ,
432+ "etcd_api_ca" : "" ,
433+ "etcd_peer_ca" : "" ,
434+ "aggregation_ca" : "" ,
435+ "control_plane_disk_encryption_key" : "" ,
436+ "gkeops_etcd_backup_encryption_key" : "" ,
437+ "service_account_verification_keys" : schema .NewSet (schema .HashString , []interface {}{"value" }),
438+ },
439+ },
440+ },
441+ }
442+
443+ for _ , tc := range cases {
444+ t .Run (tc .name , func (t * testing.T ) {
445+ t .Parallel ()
446+ got := flattenUserManagedKeysConfig (tc .config )
447+ if diff := cmp .Diff (got , tc .want ); diff != "" {
448+ t .Errorf ("flattenUserManagedKeysConfig(%s) returned unexpected diff. +got, -want:\n %s" , tc .name , diff )
449+ }
450+ })
451+ }
452+ }
0 commit comments