|
1 | 1 | package codefresh |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "fmt" |
| 4 | + "log" |
5 | 5 | cfClient "github.com/codefresh-io/terraform-provider-codefresh/client" |
6 | 6 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
7 | 7 | ) |
@@ -38,6 +38,7 @@ func resourceUser() *schema.Resource { |
38 | 38 | "personal": { |
39 | 39 | Type: schema.TypeList, |
40 | 40 | Optional: true, |
| 41 | + MaxItems: 1, |
41 | 42 | Elem: &schema.Resource{ |
42 | 43 | Schema: map[string]*schema.Schema{ |
43 | 44 | "first_name": { |
@@ -87,40 +88,33 @@ func resourceUser() *schema.Resource { |
87 | 88 | Computed: true, |
88 | 89 | }, |
89 | 90 | "login": { |
90 | | - Type: schema.TypeList, |
| 91 | + Type: schema.TypeSet, |
91 | 92 | Optional: true, |
92 | 93 | Elem: &schema.Resource{ |
93 | 94 | Schema: map[string]*schema.Schema{ |
94 | | - "credentials": { |
95 | | - Type: schema.TypeList, |
| 95 | + // "credentials": { |
| 96 | + // Type: schema.TypeList, |
| 97 | + // Optional: true, |
| 98 | + // MaxItems: 1, |
| 99 | + // Elem: &schema.Resource{ |
| 100 | + // Schema: map[string]*schema.Schema{ |
| 101 | + // "permissions": { |
| 102 | + // Type: schema.TypeList, |
| 103 | + // Optional: true, |
| 104 | + // Elem: &schema.Schema{ |
| 105 | + // Type: schema.TypeString, |
| 106 | + // }, |
| 107 | + // }, |
| 108 | + // }, |
| 109 | + // }, |
| 110 | + // }, |
| 111 | + "idp_id": { |
| 112 | + Type: schema.TypeString, |
96 | 113 | Optional: true, |
97 | | - Elem: &schema.Resource{ |
98 | | - Schema: map[string]*schema.Schema{ |
99 | | - "permissions": { |
100 | | - Type: schema.TypeList, |
101 | | - Optional: true, |
102 | | - Elem: &schema.Schema{ |
103 | | - Type: schema.TypeString, |
104 | | - }, |
105 | | - }, |
106 | | - }, |
107 | | - }, |
108 | 114 | }, |
109 | | - "idp": { |
110 | | - Type: schema.TypeList, |
| 115 | + "sso": { |
| 116 | + Type: schema.TypeBool, |
111 | 117 | Optional: true, |
112 | | - Elem: &schema.Resource{ |
113 | | - Schema: map[string]*schema.Schema{ |
114 | | - "idp_id": { |
115 | | - Type: schema.TypeString, |
116 | | - Optional: true, |
117 | | - }, |
118 | | - "client_type": { |
119 | | - Type: schema.TypeString, |
120 | | - Optional: true, |
121 | | - }, |
122 | | - }, |
123 | | - }, |
124 | 118 | }, |
125 | 119 | }, |
126 | 120 | }, |
@@ -247,16 +241,12 @@ func flattenUserLogins(logins *[]cfClient.Login) []map[string]interface{} { |
247 | 241 | var res = make([]map[string]interface{}, len(*logins)) |
248 | 242 | for i, login := range *logins { |
249 | 243 | m := make(map[string]interface{}) |
250 | | - m["credentials"] = []map[string]interface{}{ |
251 | | - {"permissions": login.Credentials.Permissions}, |
252 | | - } |
| 244 | + // m["credentials"] = []map[string]interface{}{ |
| 245 | + // {"permissions": login.Credentials.Permissions}, |
| 246 | + // } |
253 | 247 |
|
254 | | - m["idp"] = []map[string]interface{}{ |
255 | | - { |
256 | | - "idp_id": login.IDP.ID, |
257 | | - "client_type": login.IDP.ClientType, |
258 | | - }, |
259 | | - } |
| 248 | + m["idp_id"] = login.IDP.ID |
| 249 | + m["sso"] = login.Sso |
260 | 250 |
|
261 | 251 | res[i] = m |
262 | 252 | } |
@@ -287,22 +277,39 @@ func mapResourceToUser(d *schema.ResourceData) *cfClient.NewUser { |
287 | 277 | } |
288 | 278 | } |
289 | 279 |
|
290 | | - logins := d.Get("login").([]interface{}) |
291 | | - |
292 | | - for idx := range logins { |
293 | | - |
294 | | - permissions := convertStringArr(d.Get(fmt.Sprintf("login.%v.credentials.0.permissions", idx)).([]interface{})) |
295 | | - login := cfClient.Login{ |
296 | | - Credentials: cfClient.Credentials{ |
297 | | - Permissions: permissions, |
298 | | - }, |
299 | | - IDP: cfClient.IDP{ |
300 | | - ID: d.Get(fmt.Sprintf("login.%v.idp.0.idp_id", idx)).(string), |
301 | | - ClientType: d.Get(fmt.Sprintf("login.%v.idp.0.client_type", idx)).(string), |
302 | | - }, |
303 | | - } |
304 | | - user.Logins = append(user.Logins, login) |
| 280 | + if logins, ok := d.GetOk("login"); ok { |
| 281 | + loginsList := logins.(*schema.Set).List() |
| 282 | + for _, loginDataI := range loginsList { |
| 283 | + if loginData, isMap := loginDataI.(map[string]interface{}); isMap { |
| 284 | + idpID := loginData["idp_id"].(string) |
| 285 | + login := cfClient.Login{ |
| 286 | + // Credentials: cfClient.Credentials{ |
| 287 | + // Permissions: loginData.Get("credentials.permissions").([]string), |
| 288 | + // }, |
| 289 | + IDP: cfClient.IDP{ |
| 290 | + ID: idpID, |
| 291 | + }, |
| 292 | + Sso: loginData["sso"].(bool), |
| 293 | + } |
| 294 | + user.Logins = append(user.Logins, login) |
| 295 | + log.Printf("[DEBUG] login = %v", login) |
| 296 | + } |
| 297 | + } |
305 | 298 | } |
| 299 | + // logins := d.Get("login").(*schema.Set) |
| 300 | + |
| 301 | + // for idx := range logins { |
| 302 | + |
| 303 | + // permissions := convertStringArr(d.Get(fmt.Sprintf("login.%v.credentials.0.permissions", idx)).([]interface{})) |
| 304 | + // login := cfClient.Login{ |
| 305 | + // Credentials: cfClient.Credentials{ |
| 306 | + // Permissions: permissions, |
| 307 | + // }, |
| 308 | + // Idp: d.Get(fmt.Sprintf("login.%v.idp_id", idx)).(string), |
| 309 | + // Sso: d.Get(fmt.Sprintf("login.%v.sso", idx)).(bool), |
| 310 | + // } |
| 311 | + // user.Logins = append(user.Logins, login) |
| 312 | + // } |
306 | 313 |
|
307 | 314 | return user |
308 | 315 | } |
0 commit comments