@@ -20,7 +20,15 @@ func resourceRancher2Cluster() *schema.Resource {
2020 Importer : & schema.ResourceImporter {
2121 State : resourceRancher2ClusterImport ,
2222 },
23- Schema : clusterFields (),
23+ Schema : clusterFields (),
24+ SchemaVersion : 1 ,
25+ StateUpgraders : []schema.StateUpgrader {
26+ {
27+ Type : resourceRancher2ClusterResourceV0 ().CoreConfigSchema ().ImpliedType (),
28+ Upgrade : resourceRancher2ClusterStateUpgradeV0 ,
29+ Version : 0 ,
30+ },
31+ },
2432 // Setting default timeouts to be liberal in order to accommodate managed Kubernetes providers like EKS, GKE, and AKS
2533 Timeouts : & schema.ResourceTimeout {
2634 Create : schema .DefaultTimeout (30 * time .Minute ),
@@ -30,6 +38,66 @@ func resourceRancher2Cluster() *schema.Resource {
3038 }
3139}
3240
41+ func resourceRancher2ClusterResourceV0 () * schema.Resource {
42+ return & schema.Resource {
43+ Schema : clusterFieldsV0 (),
44+ }
45+ }
46+
47+ func resourceRancher2ClusterStateUpgradeV0 (rawState map [string ]interface {}, meta interface {}) (map [string ]interface {}, error ) {
48+ if rkeConfigs , ok := rawState ["rke_config" ].([]interface {}); ok && len (rkeConfigs ) > 0 {
49+ for i1 := range rkeConfigs {
50+ if rkeConfig , ok := rkeConfigs [i1 ].(map [string ]interface {}); ok && len (rkeConfig ) > 0 {
51+ if services , ok := rkeConfig ["services" ].([]interface {}); ok && len (services ) > 0 {
52+ for i2 := range services {
53+ if service , ok := services [i2 ].(map [string ]interface {}); ok && len (service ) > 0 {
54+ if kubeApis , ok := service ["kube_api" ].([]interface {}); ok && len (kubeApis ) > 0 {
55+ for i3 := range kubeApis {
56+ if kubeAPI , ok := kubeApis [i3 ].(map [string ]interface {}); ok && len (kubeAPI ) > 0 {
57+ if eventRates , ok := kubeAPI ["event_rate_limit" ].([]interface {}); ok && len (eventRates ) > 0 {
58+ for i4 := range eventRates {
59+ if eventRate , ok := eventRates [i4 ].(map [string ]interface {}); ok && len (eventRate ) > 0 {
60+ if config , ok := eventRate ["configuration" ].(map [string ]interface {}); ok {
61+ newValue := ""
62+ if len (config ) > 0 {
63+ conf , err := mapInterfaceToYAML (config )
64+ if err == nil {
65+ newValue = conf
66+ }
67+ }
68+ rawState ["rke_config" ].([]interface {})[i1 ].(map [string ]interface {})["services" ].([]interface {})[i2 ].(map [string ]interface {})["kube_api" ].([]interface {})[i3 ].(map [string ]interface {})["event_rate_limit" ].([]interface {})[i4 ].(map [string ]interface {})["configuration" ] = newValue
69+ }
70+ }
71+ }
72+ }
73+ if secretEncs , ok := kubeAPI ["secrets_encryption_config" ].([]interface {}); ok && len (secretEncs ) > 0 {
74+ for i4 := range secretEncs {
75+ if secretEnc , ok := secretEncs [i4 ].(map [string ]interface {}); ok && len (secretEnc ) > 0 {
76+ if config , ok := secretEnc ["custom_config" ].(map [string ]interface {}); ok {
77+ newValue := ""
78+ if len (config ) > 0 {
79+ conf , err := mapInterfaceToYAML (config )
80+ if err == nil {
81+ newValue = conf
82+ }
83+ }
84+ rawState ["rke_config" ].([]interface {})[i1 ].(map [string ]interface {})["services" ].([]interface {})[i2 ].(map [string ]interface {})["kube_api" ].([]interface {})[i3 ].(map [string ]interface {})["secrets_encryption_config" ].([]interface {})[i4 ].(map [string ]interface {})["custom_config" ] = newValue
85+ }
86+ }
87+ }
88+ }
89+ }
90+ }
91+ }
92+ }
93+ }
94+ }
95+ }
96+ }
97+ }
98+ return rawState , nil
99+ }
100+
33101func resourceRancher2ClusterCreate (d * schema.ResourceData , meta interface {}) error {
34102 client , err := meta .(* Config ).ManagementClient ()
35103 if err != nil {
0 commit comments