@@ -14,6 +14,7 @@ import (
14
14
"github.com/zededa/zedcloud-api/swagger_models"
15
15
"io/ioutil"
16
16
"log"
17
+ "strconv"
17
18
)
18
19
19
20
var edgeAppUrlExtension = "apps"
@@ -304,7 +305,7 @@ func rdAppManifestImagesEntry(d map[string]interface{}) (
304
305
cfg .Drvtype = rdEntryStr (d , "drvtype" )
305
306
cfg .Ignorepurge = rdEntryBool (d , "ignorepurge" )
306
307
cfg .Imagename = rdEntryStr (d , "imagename" )
307
- cfg .Maxsize = rdEntryStr ( d , "maxsize" )
308
+ cfg .Maxsize = strconv . FormatInt ( rdEntryInt64 ( d , "maxsize" ), 10 )
308
309
cfg .Mountpath = rdEntryStr (d , "mountpath" )
309
310
cfg .Params , err = rdAppManifestImageParams (d )
310
311
if err != nil {
@@ -399,21 +400,8 @@ func rdAppManifestUserDataTemplate(d map[string]interface{}) (
399
400
return val .(* swagger_models.UserDataTemplate ), nil
400
401
}
401
402
402
- func rdAppManifest (rd * schema.ResourceData ) (* swagger_models.VMManifest , error ) {
403
- // Manifest can come through manifest or manifest_file.
404
- // Only one of them must be specified.
405
- ok , val := rdEntryByKey (rd , "manifest" )
406
- if ! ok {
407
- // Key manifest not present in Resource Data. Check for manifest_file
408
- return rdEntryAppManifestFromFile (rd )
409
- }
410
- ok , _ = rdEntryByKey (rd , "manifest_file" )
411
- if ok {
412
- return nil , fmt .Errorf ("Both manifest and manifest_file are specified. " +
413
- "Only one of them must be specified." )
414
- }
403
+ func rdAppManifestEntry (d map [string ]interface {}) (interface {}, error ) {
415
404
var err error
416
- d := val .(map [string ]interface {})
417
405
cfg := swagger_models.VMManifest {}
418
406
cfg .AppType = appTypePtr (rdEntryStr (d , "apptype" ))
419
407
cfg .Configuration , err = rdAppManifestUserDataTemplate (d )
@@ -460,6 +448,26 @@ func rdAppManifest(rd *schema.ResourceData) (*swagger_models.VMManifest, error)
460
448
return & cfg , nil
461
449
}
462
450
451
+ func rdAppManifest (rd * schema.ResourceData ) (* swagger_models.VMManifest , error ) {
452
+ // Manifest can come through manifest or manifest_file.
453
+ // Only one of them must be specified.
454
+ ok , val := rdEntryByKey (rd , "manifest" )
455
+ if ! ok {
456
+ // Key manifest not present in Resource Data. Check for manifest_file
457
+ return rdEntryAppManifestFromFile (rd )
458
+ }
459
+ ok , _ = rdEntryByKey (rd , "manifest_file" )
460
+ if ok {
461
+ return nil , fmt .Errorf ("Both manifest and manifest_file are specified. " +
462
+ "Only one of them must be specified." )
463
+ }
464
+ val , err := rdEntryStructPtr (rd , "manifest" , rdAppManifestEntry )
465
+ if val == nil || err != nil {
466
+ return nil , err
467
+ }
468
+ return val .(* swagger_models.VMManifest ), nil
469
+ }
470
+
463
471
func rdUpdateAppCfg (cfg * swagger_models.App , d * schema.ResourceData ) error {
464
472
cfg .Title = rdEntryStrPtrOrNil (d , "title" )
465
473
cfg .Description = rdEntryStr (d , "description" )
@@ -485,7 +493,7 @@ func createEdgeAppResource(ctx context.Context, d *schema.ResourceData,
485
493
client := (meta .(Client )).Client
486
494
name := rdEntryStr (d , "name" )
487
495
id := rdEntryStr (d , "id" )
488
- errMsgPrefix := fmt .Sprintf ("[ERROR] App Instance %s (id: %s) Create Failed." ,
496
+ errMsgPrefix := fmt .Sprintf ("[ERROR] Edge App %s (id: %s) Create Failed." ,
489
497
name , id )
490
498
if client == nil {
491
499
return diag .Errorf ("%s nil Client" , errMsgPrefix )
@@ -502,6 +510,8 @@ func createEdgeAppResource(ctx context.Context, d *schema.ResourceData,
502
510
rspData := & swagger_models.ZsrvResponse {}
503
511
_ , err = client .SendReq ("POST" , edgeAppUrlExtension , cfg , rspData )
504
512
if err != nil {
513
+ log .Printf ("[ERROR] Edge App Create Failed: %s, %s Err: %s" ,
514
+ name , errMsgPrefix , err .Error ())
505
515
return diag .Errorf ("%s Err: %s" , errMsgPrefix , err .Error ())
506
516
}
507
517
log .Printf ("Edge App %s (ID: %s) Successfully created\n " ,
0 commit comments