@@ -160,7 +160,7 @@ func resourceIBMIAMServiceAPIkeyCreate(d *schema.ResourceData, meta interface{})
160160 }
161161
162162 apiKey , response , err := iamIdentityClient .CreateAPIKey (createAPIKeyOptions )
163- if err != nil {
163+ if err != nil || apiKey == nil {
164164 return fmt .Errorf ("[DEBUG] Service API Key creation Error: %s\n %s" , err , response )
165165 }
166166
@@ -188,29 +188,46 @@ func resourceIBMIAMServiceAPIKeyRead(d *schema.ResourceData, meta interface{}) e
188188 }
189189
190190 apiKey , response , err := iamIdentityClient .GetAPIKey (getAPIKeyOptions )
191- if err != nil {
191+ if err != nil || apiKey == nil {
192192 if response != nil && response .StatusCode == 404 {
193193 d .SetId ("" )
194194 return nil
195195 }
196196 return fmt .Errorf ("[DEBUG] Error retrieving Service API Key: %s\n %s" , err , response )
197197 }
198-
199- d .Set ("name" , * apiKey .Name )
200- d .Set ("iam_service_id" , * apiKey .IamID )
198+ if apiKey .Name != nil {
199+ d .Set ("name" , * apiKey .Name )
200+ }
201+ if apiKey .IamID != nil {
202+ d .Set ("iam_service_id" , * apiKey .IamID )
203+ }
201204 if apiKey .Description != nil {
202205 d .Set ("description" , * apiKey .Description )
203206 }
204- d .Set ("account_id" , * apiKey .AccountID )
207+ if apiKey .AccountID != nil {
208+ d .Set ("account_id" , * apiKey .AccountID )
209+ }
205210 if * apiKey .Apikey != "" {
206211 d .Set ("apikey" , * apiKey .Apikey )
207212 }
208- d .Set ("crn" , * apiKey .CRN )
209- d .Set ("entity_tag" , * apiKey .EntityTag )
210- d .Set ("locked" , * apiKey .Locked )
211- d .Set ("created_by" , * apiKey .CreatedBy )
212- d .Set ("created_at" , apiKey .CreatedAt .String ())
213- d .Set ("modified_at" , apiKey .ModifiedAt .String ())
213+ if apiKey .CRN != nil {
214+ d .Set ("crn" , * apiKey .CRN )
215+ }
216+ if apiKey .EntityTag != nil {
217+ d .Set ("entity_tag" , * apiKey .EntityTag )
218+ }
219+ if apiKey .Locked != nil {
220+ d .Set ("locked" , * apiKey .Locked )
221+ }
222+ if apiKey .CreatedBy != nil {
223+ d .Set ("created_by" , * apiKey .CreatedBy )
224+ }
225+ if apiKey .CreatedAt != nil {
226+ d .Set ("created_at" , apiKey .CreatedAt .String ())
227+ }
228+ if apiKey .ModifiedAt != nil {
229+ d .Set ("modified_at" , apiKey .ModifiedAt .String ())
230+ }
214231
215232 return nil
216233}
@@ -228,7 +245,7 @@ func resourceIBMIAMServiceAPIKeyUpdate(d *schema.ResourceData, meta interface{})
228245 }
229246
230247 apiKey , resp , err := iamIdentityClient .GetAPIKey (getAPIKeyOptions )
231- if err != nil {
248+ if err != nil || apiKey == nil {
232249 return fmt .Errorf ("[DEBUG] Error retrieving Service API Key: %s\n %s" , err , resp )
233250 }
234251
0 commit comments