99
1010 "github.com/hashicorp/go-cty/cty"
1111
12- "dario.cat/mergo "
12+ "github.com/google/uuid "
1313 "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1414 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
1515 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -48,7 +48,6 @@ func resourceKeycloakOpenidClient() *schema.Resource {
4848 "name" : {
4949 Type : schema .TypeString ,
5050 Optional : true ,
51- Computed : true ,
5251 },
5352 "enabled" : {
5453 Type : schema .TypeBool ,
@@ -58,7 +57,6 @@ func resourceKeycloakOpenidClient() *schema.Resource {
5857 "description" : {
5958 Type : schema .TypeString ,
6059 Optional : true ,
61- Computed : true ,
6260 },
6361 "access_type" : {
6462 Type : schema .TypeString ,
@@ -106,34 +104,33 @@ func resourceKeycloakOpenidClient() *schema.Resource {
106104 "standard_flow_enabled" : {
107105 Type : schema .TypeBool ,
108106 Optional : true ,
109- Computed : true ,
107+ Default : false ,
110108 },
111109 "implicit_flow_enabled" : {
112110 Type : schema .TypeBool ,
113111 Optional : true ,
114- Computed : true ,
112+ Default : false ,
115113 },
116114 "direct_access_grants_enabled" : {
117115 Type : schema .TypeBool ,
118116 Optional : true ,
119- Computed : true ,
117+ Default : false ,
120118 },
121119 "service_accounts_enabled" : {
122120 Type : schema .TypeBool ,
123121 Optional : true ,
124- Computed : true ,
122+ Default : false ,
125123 },
126124 "frontchannel_logout_enabled" : {
127125 Type : schema .TypeBool ,
128126 Optional : true ,
129- Computed : true ,
127+ Default : false ,
130128 },
131129 "valid_redirect_uris" : {
132130 Type : schema .TypeSet ,
133131 Elem : & schema.Schema {Type : schema .TypeString },
134132 Set : schema .HashString ,
135133 Optional : true ,
136- Computed : true ,
137134 },
138135 "valid_post_logout_redirect_uris" : {
139136 Type : schema .TypeSet ,
@@ -147,22 +144,18 @@ func resourceKeycloakOpenidClient() *schema.Resource {
147144 Elem : & schema.Schema {Type : schema .TypeString },
148145 Set : schema .HashString ,
149146 Optional : true ,
150- Computed : true ,
151147 },
152148 "root_url" : {
153149 Type : schema .TypeString ,
154150 Optional : true ,
155- Computed : true ,
156151 },
157152 "admin_url" : {
158153 Type : schema .TypeString ,
159154 Optional : true ,
160- Computed : true ,
161155 },
162156 "base_url" : {
163157 Type : schema .TypeString ,
164158 Optional : true ,
165- Computed : true ,
166159 },
167160 "service_account_user_id" : {
168161 Type : schema .TypeString ,
@@ -176,27 +169,22 @@ func resourceKeycloakOpenidClient() *schema.Resource {
176169 "access_token_lifespan" : {
177170 Type : schema .TypeString ,
178171 Optional : true ,
179- Computed : true ,
180172 },
181173 "client_offline_session_idle_timeout" : {
182174 Type : schema .TypeString ,
183175 Optional : true ,
184- Computed : true ,
185176 },
186177 "client_offline_session_max_lifespan" : {
187178 Type : schema .TypeString ,
188179 Optional : true ,
189- Computed : true ,
190180 },
191181 "client_session_idle_timeout" : {
192182 Type : schema .TypeString ,
193183 Optional : true ,
194- Computed : true ,
195184 },
196185 "client_session_max_lifespan" : {
197186 Type : schema .TypeString ,
198187 Optional : true ,
199- Computed : true ,
200188 },
201189 "exclude_session_state_from_auth_response" : {
202190 Type : schema .TypeBool ,
@@ -250,17 +238,16 @@ func resourceKeycloakOpenidClient() *schema.Resource {
250238 "consent_required" : {
251239 Type : schema .TypeBool ,
252240 Optional : true ,
253- Computed : true ,
241+ Default : false ,
254242 },
255243 "display_on_consent_screen" : {
256244 Type : schema .TypeBool ,
257245 Optional : true ,
258- Computed : true ,
246+ Default : false ,
259247 },
260248 "consent_screen_text" : {
261249 Type : schema .TypeString ,
262250 Optional : true ,
263- Computed : true ,
264251 },
265252 "authentication_flow_binding_overrides" : {
266253 Type : schema .TypeSet ,
@@ -342,12 +329,6 @@ func resourceKeycloakOpenidClient() *schema.Resource {
342329 Optional : true ,
343330 Default : false ,
344331 },
345- "import" : {
346- Type : schema .TypeBool ,
347- Optional : true ,
348- Default : false ,
349- ForceNew : true ,
350- },
351332 },
352333 CustomizeDiff : resourceKeycloakOpenidClientDiff (),
353334 }
@@ -603,25 +584,9 @@ func resourceKeycloakOpenidClientCreate(ctx context.Context, data *schema.Resour
603584 return diag .FromErr (err )
604585 }
605586
606- if data .Get ("import" ).(bool ) {
607- existingClient , err := keycloakClient .GetOpenidClientByClientId (ctx , client .RealmId , client .ClientId )
608- if err != nil {
609- return diag .FromErr (err )
610- }
611-
612- if err = mergo .Merge (client , existingClient ); err != nil {
613- return diag .FromErr (err )
614- }
615-
616- err = keycloakClient .UpdateOpenidClient (ctx , client )
617- if err != nil {
618- return diag .FromErr (err )
619- }
620- } else {
621- err = keycloakClient .NewOpenidClient (ctx , client )
622- if err != nil {
623- return diag .FromErr (err )
624- }
587+ err = keycloakClient .NewOpenidClient (ctx , client )
588+ if err != nil {
589+ return diag .FromErr (err )
625590 }
626591
627592 err = setOpenidClientData (ctx , keycloakClient , data , client )
@@ -648,10 +613,6 @@ func resourceKeycloakOpenidClientRead(ctx context.Context, data *schema.Resource
648613 return diag .FromErr (err )
649614 }
650615
651- if _ , ok := data .GetOk ("import" ); ! ok {
652- data .Set ("import" , false )
653- }
654-
655616 return nil
656617}
657618
@@ -687,9 +648,6 @@ func resourceKeycloakOpenidClientUpdate(ctx context.Context, data *schema.Resour
687648}
688649
689650func resourceKeycloakOpenidClientDelete (ctx context.Context , data * schema.ResourceData , meta interface {}) diag.Diagnostics {
690- if data .Get ("import" ).(bool ) {
691- return nil
692- }
693651 keycloakClient := meta .(* keycloak.KeycloakClient )
694652
695653 realmId := data .Get ("realm_id" ).(string )
@@ -703,18 +661,28 @@ func resourceKeycloakOpenidClientImport(ctx context.Context, d *schema.ResourceD
703661
704662 parts := strings .Split (d .Id (), "/" )
705663 if len (parts ) != 2 {
706- return nil , fmt .Errorf ("Invalid import. Supported import formats: {{realmId}}/{{openidClientId}}" )
664+ return nil , fmt .Errorf ("invalid import. Supported import formats: {{realmId}}/{{openidClientId}} or {{realmId}}/{{clientUuid }}" )
707665 }
708-
709- _ , err := keycloakClient .GetOpenidClient (ctx , parts [0 ], parts [1 ])
666+ if _ , err := uuid .Parse (parts [1 ]); err == nil {
667+ // {{realmId}}/{{clientUuid}}
668+ _ , err := keycloakClient .GetOpenidClient (ctx , parts [0 ], parts [1 ])
669+ if err != nil {
670+ return nil , err
671+ }
672+ d .SetId (parts [1 ])
673+ } else {
674+ // {{realmId}}/{{openidClientId}}
675+ c , err := keycloakClient .SearchOpenidClientExact (ctx , parts [0 ], parts [1 ])
676+ if err != nil {
677+ return nil , err
678+ }
679+ d .SetId (c .Id )
680+ }
681+ err := d .Set ("realm_id" , parts [0 ])
710682 if err != nil {
711683 return nil , err
712684 }
713685
714- d .Set ("realm_id" , parts [0 ])
715- d .Set ("import" , false )
716- d .SetId (parts [1 ])
717-
718686 diagnostics := resourceKeycloakOpenidClientRead (ctx , d , meta )
719687 if diagnostics .HasError () {
720688 return nil , errors .New (diagnostics [0 ].Summary )
0 commit comments