Skip to content

Commit ebe2ef5

Browse files
Fix bug in processing App Manifest (#43)
1 parent ca40a14 commit ebe2ef5

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

provider/resource_edgeapp.go

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/zededa/zedcloud-api/swagger_models"
1515
"io/ioutil"
1616
"log"
17+
"strconv"
1718
)
1819

1920
var edgeAppUrlExtension = "apps"
@@ -304,7 +305,7 @@ func rdAppManifestImagesEntry(d map[string]interface{}) (
304305
cfg.Drvtype = rdEntryStr(d, "drvtype")
305306
cfg.Ignorepurge = rdEntryBool(d, "ignorepurge")
306307
cfg.Imagename = rdEntryStr(d, "imagename")
307-
cfg.Maxsize = rdEntryStr(d, "maxsize")
308+
cfg.Maxsize = strconv.FormatInt(rdEntryInt64(d, "maxsize"), 10)
308309
cfg.Mountpath = rdEntryStr(d, "mountpath")
309310
cfg.Params, err = rdAppManifestImageParams(d)
310311
if err != nil {
@@ -399,21 +400,8 @@ func rdAppManifestUserDataTemplate(d map[string]interface{}) (
399400
return val.(*swagger_models.UserDataTemplate), nil
400401
}
401402

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) {
415404
var err error
416-
d := val.(map[string]interface{})
417405
cfg := swagger_models.VMManifest{}
418406
cfg.AppType = appTypePtr(rdEntryStr(d, "apptype"))
419407
cfg.Configuration, err = rdAppManifestUserDataTemplate(d)
@@ -460,6 +448,26 @@ func rdAppManifest(rd *schema.ResourceData) (*swagger_models.VMManifest, error)
460448
return &cfg, nil
461449
}
462450

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+
463471
func rdUpdateAppCfg(cfg *swagger_models.App, d *schema.ResourceData) error {
464472
cfg.Title = rdEntryStrPtrOrNil(d, "title")
465473
cfg.Description = rdEntryStr(d, "description")
@@ -485,7 +493,7 @@ func createEdgeAppResource(ctx context.Context, d *schema.ResourceData,
485493
client := (meta.(Client)).Client
486494
name := rdEntryStr(d, "name")
487495
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.",
489497
name, id)
490498
if client == nil {
491499
return diag.Errorf("%s nil Client", errMsgPrefix)
@@ -502,6 +510,8 @@ func createEdgeAppResource(ctx context.Context, d *schema.ResourceData,
502510
rspData := &swagger_models.ZsrvResponse{}
503511
_, err = client.SendReq("POST", edgeAppUrlExtension, cfg, rspData)
504512
if err != nil {
513+
log.Printf("[ERROR] Edge App Create Failed: %s, %s Err: %s",
514+
name, errMsgPrefix, err.Error())
505515
return diag.Errorf("%s Err: %s", errMsgPrefix, err.Error())
506516
}
507517
log.Printf("Edge App %s (ID: %s) Successfully created\n",

provider/resourcedatautils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func rdEntryList(rd interface{}, key string) []interface{} {
275275
if ok {
276276
return setVal.List()
277277
}
278-
panic("Key %s Value %+v - neither a list not a set")
278+
panic("Key %s Value %+v - neither a list nor a set")
279279
}
280280

281281
type rdFuncMapToEntry func(d map[string]interface{}) (interface{}, error)

0 commit comments

Comments
 (0)