|
8 | 8 | "log" |
9 | 9 | "net/http" |
10 | 10 | "os" |
| 11 | + "sort" |
11 | 12 | "strings" |
12 | 13 | "time" |
13 | 14 |
|
@@ -920,18 +921,38 @@ func expandAKSManagedClusterV3Identity(p []interface{}) *infrapb.Identity { |
920 | 921 | if len(p) == 0 || p[0] == nil { |
921 | 922 | return obj |
922 | 923 | } |
| 924 | + |
923 | 925 | in := p[0].(map[string]interface{}) |
924 | 926 |
|
925 | | - if v, ok := in["type"].(string); ok && len(v) > 0 { |
| 927 | + if v, ok := in["type"].(string); ok && v != "" { |
926 | 928 | obj.Type = v |
927 | 929 | } |
928 | | - if v, ok := in["user_assigned_identities"].(map[string]interface{}); ok { |
929 | | - obj.UserAssignedIdentities = make(map[string]*structpb.Struct) |
930 | | - for identity := range v { |
931 | | - x, _ := structpb.NewStruct(map[string]interface{}{}) |
932 | | - obj.UserAssignedIdentities[identity] = x |
| 930 | + |
| 931 | + raw, ok := in["user_assigned_identities"].(map[string]interface{}) |
| 932 | + if !ok { |
| 933 | + return obj |
| 934 | + } |
| 935 | + |
| 936 | + obj.UserAssignedIdentities = make(map[string]*structpb.Struct, len(raw)) |
| 937 | + |
| 938 | + for id, v := range raw { |
| 939 | + val := strings.TrimSpace(fmt.Sprintf("%v", v)) |
| 940 | + |
| 941 | + if val == "" || val == "{}" { |
| 942 | + obj.UserAssignedIdentities[id] = &structpb.Struct{} |
| 943 | + continue |
| 944 | + } |
| 945 | + |
| 946 | + var m map[string]interface{} |
| 947 | + if err := json.Unmarshal([]byte(val), &m); err != nil || len(m) == 0 { |
| 948 | + obj.UserAssignedIdentities[id] = &structpb.Struct{} |
| 949 | + continue |
933 | 950 | } |
| 951 | + |
| 952 | + st, _ := structpb.NewStruct(m) |
| 953 | + obj.UserAssignedIdentities[id] = st |
934 | 954 | } |
| 955 | + |
935 | 956 | return obj |
936 | 957 | } |
937 | 958 |
|
@@ -2919,25 +2940,47 @@ func flattenAKSV3ManagedClusterIdentity(in *infrapb.Identity, p []interface{}) [ |
2919 | 2940 | if in == nil { |
2920 | 2941 | return nil |
2921 | 2942 | } |
| 2943 | + |
2922 | 2944 | obj := map[string]interface{}{} |
2923 | 2945 | if len(p) != 0 && p[0] != nil { |
2924 | 2946 | obj = p[0].(map[string]interface{}) |
2925 | 2947 | } |
2926 | 2948 |
|
2927 | | - if len(in.Type) > 0 { |
| 2949 | + if in.Type != "" { |
2928 | 2950 | obj["type"] = in.Type |
2929 | 2951 | } |
2930 | 2952 |
|
2931 | | - if in.UserAssignedIdentities != nil && len(in.UserAssignedIdentities) > 0 { |
2932 | | - identity := map[string]string{} |
2933 | | - for k := range in.UserAssignedIdentities { |
2934 | | - identity[k] = "" |
| 2953 | + if len(in.UserAssignedIdentities) == 0 { |
| 2954 | + return []interface{}{obj} |
| 2955 | + } |
| 2956 | + |
| 2957 | + keys := make([]string, 0, len(in.UserAssignedIdentities)) |
| 2958 | + for k := range in.UserAssignedIdentities { |
| 2959 | + keys = append(keys, k) |
| 2960 | + } |
| 2961 | + sort.Strings(keys) |
| 2962 | + |
| 2963 | + out := make(map[string]string, len(keys)) |
| 2964 | + |
| 2965 | + for _, k := range keys { |
| 2966 | + st := in.UserAssignedIdentities[k] |
| 2967 | + |
| 2968 | + if st == nil || len(st.Fields) == 0 { |
| 2969 | + out[k] = "{}" |
| 2970 | + continue |
| 2971 | + } |
| 2972 | + |
| 2973 | + b, err := json.Marshal(st.AsMap()) |
| 2974 | + if err != nil { |
| 2975 | + out[k] = "{}" |
| 2976 | + continue |
2935 | 2977 | } |
2936 | | - obj["user_assigned_identities"] = identity |
| 2978 | + |
| 2979 | + out[k] = string(b) |
2937 | 2980 | } |
2938 | 2981 |
|
| 2982 | + obj["user_assigned_identities"] = out |
2939 | 2983 | return []interface{}{obj} |
2940 | | - |
2941 | 2984 | } |
2942 | 2985 |
|
2943 | 2986 | func flattenAKSV3ManagedClusterProperties(in *infrapb.ManagedClusterProperties, p []interface{}) []interface{} { |
|
0 commit comments