@@ -177,15 +177,8 @@ func flattenClusterInfo(info application.ClusterInfo) []map[string]interface{} {
177177func flattenClusterConfig (config application.ClusterConfig , d * schema.ResourceData ) []map [string ]interface {} {
178178 r := map [string ]interface {}{
179179 "username" : config .Username ,
180- "exec_provider_config" : flattenClusterConfigExecProviderConfig (config .ExecProviderConfig ),
181- }
182-
183- if stateClusterConfig , ok := d .GetOk ("config" ); ok {
184- scc := expandClusterConfig (stateClusterConfig .([]interface {})[0 ])
185-
186- r ["password" ] = scc .Password
187- r ["bearer_token" ] = scc .BearerToken
188- r ["tls_client_config" ] = flattenClusterConfigTLSClientConfig (scc )
180+ "exec_provider_config" : flattenClusterConfigExecProviderConfig (config .ExecProviderConfig , d ),
181+ "tls_client_config" : flattenClusterConfigTLSClientConfig (config .TLSClientConfig , d ),
189182 }
190183
191184 if config .AWSAuthConfig != nil {
@@ -197,37 +190,63 @@ func flattenClusterConfig(config application.ClusterConfig, d *schema.ResourceDa
197190 }
198191 }
199192
193+ // ArgoCD API does not return these fields as they may contain
194+ // sensitive data. Thus, we can't track the state of these
195+ // attributes and load them from state instead.
196+ // See https://github.com/argoproj/argo-cd/blob/8840929187f4dd7b9d9fd908ea5085a006895507/server/cluster/cluster.go#L448-L466
197+ if bt , ok := d .GetOk ("config.0.bearer_token" ); ok {
198+ r ["bearer_token" ] = bt .(string )
199+ }
200+
201+ if p , ok := d .GetOk ("config.0.password" ); ok {
202+ r ["password" ] = p .(string )
203+ }
204+
200205 return []map [string ]interface {}{r }
201206}
202207
203- func flattenClusterConfigTLSClientConfig (stateClusterConfig application.ClusterConfig ) []map [string ]interface {} {
204- return []map [string ]interface {}{
205- {
206- "ca_data" : string (stateClusterConfig .CAData ),
207- "cert_data" : string (stateClusterConfig .CertData ),
208- "key_data" : string (stateClusterConfig .KeyData ),
209- "insecure" : stateClusterConfig .Insecure ,
210- "server_name" : stateClusterConfig .ServerName ,
211- },
208+ func flattenClusterConfigTLSClientConfig (tcc application.TLSClientConfig , d * schema.ResourceData ) []map [string ]interface {} {
209+ c := map [string ]interface {}{
210+ "ca_data" : string (tcc .CAData ),
211+ "cert_data" : string (tcc .CertData ),
212+ "insecure" : tcc .Insecure ,
213+ "server_name" : tcc .ServerName ,
212214 }
215+
216+ // ArgoCD API does not return sensitive data. Thus, we can't track
217+ // the state of this attribute and load it from state instead.
218+ // See https://github.com/argoproj/argo-cd/blob/8840929187f4dd7b9d9fd908ea5085a006895507/server/cluster/cluster.go#L448-L466
219+ if kd , ok := d .GetOk ("config.0.tls_client_config.0.key_data" ); ok {
220+ c ["key_data" ] = kd .(string )
221+ }
222+
223+ return []map [string ]interface {}{c }
213224}
214225
215- func flattenClusterConfigExecProviderConfig (epc * application.ExecProviderConfig ) ( result []map [string ]interface {}) {
226+ func flattenClusterConfigExecProviderConfig (epc * application.ExecProviderConfig , d * schema. ResourceData ) []map [string ]interface {} {
216227 if epc == nil {
217- return
228+ return nil
218229 }
219230
220- result = []map [string ]interface {}{
221- {
222- "api_version" : epc .APIVersion ,
223- "args" : epc .Args ,
224- "command" : epc .Command ,
225- "env" : epc .Env ,
226- "install_hint" : epc .InstallHint ,
227- },
231+ c := map [string ]interface {}{
232+ "api_version" : epc .APIVersion ,
233+ "command" : epc .Command ,
234+ "install_hint" : epc .InstallHint ,
235+ }
236+
237+ // ArgoCD API does not return these fields as they may contain
238+ // sensitive data. Thus, we can't track the state of these
239+ // attributes and load them from state instead.
240+ // See https://github.com/argoproj/argo-cd/blob/8840929187f4dd7b9d9fd908ea5085a006895507/server/cluster/cluster.go#L454-L461
241+ if a , ok := d .GetOk ("config.0.exec_provider_config.0.args" ); ok {
242+ c ["args" ] = a .([]string )
243+ }
244+
245+ if a , ok := d .GetOk ("config.0.exec_provider_config.0.env" ); ok {
246+ c ["env" ] = a .([]string )
228247 }
229248
230- return
249+ return [] map [ string ] interface {}{ c }
231250}
232251
233252func flattenClusterMetadata (annotations , labels map [string ]string ) []map [string ]interface {} {
0 commit comments