@@ -75,7 +75,7 @@ func InitEnvForSqlDb(c echo.Context) error {
7575 }
7676
7777 if ! validProvidersForSqlDb [provider ] {
78- err := fmt .Errorf ("invalid request, provider must be one of [aws, azure, gcp, ncp ]" )
78+ err := fmt .Errorf ("invalid request, provider must be one of [aws, azure, gcp, ncpvpc ]" )
7979 log .Warn ().Msg (err .Error ())
8080 res := model.Response {
8181 Success : false ,
@@ -396,7 +396,7 @@ func CheckInfracodeForSqlDb(c echo.Context) error {
396396 // subcommand: plan
397397 ret , err := tofu .ExecuteTofuCommand (trId , reqId , "-chdir=" + workingDir , "plan" )
398398 if err != nil {
399- err2 := fmt .Errorf ("encountered an issue during the infracode checking process" )
399+ err2 := fmt .Errorf ("returned: %s" , ret )
400400 log .Error ().Err (err ).Msg (err2 .Error ()) // error
401401 res := model.Response {
402402 Success : false ,
@@ -424,7 +424,7 @@ func CheckInfracodeForSqlDb(c echo.Context) error {
424424// @Produce json
425425// @Param trId path string true "Terrarium ID" default(tr01)
426426// @Param x-request-id header string false "Custom request ID"
427- // @Success 201 {object} model.Response "Created "
427+ // @Success 200 {object} model.Response "OK "
428428// @Failure 400 {object} model.Response "Bad Request"
429429// @Failure 500 {object} model.Response "Internal Server Error"
430430// @Failure 503 {object} model.Response "Service Unavailable"
@@ -469,7 +469,7 @@ func CreateSqlDb(c echo.Context) error {
469469
470470 // global option to set working dir: -chdir=/home/ubuntu/dev/cloud-barista/mc-terrarium/.terrarium/{trId}/vpn/gcp-aws
471471 // subcommand: apply
472- ret , err : = tofu .ExecuteTofuCommandAsync (trId , reqId , "-chdir=" + workingDir , "apply" , "-auto-approve" )
472+ _ , err = tofu .ExecuteTofuCommand (trId , reqId , "-chdir=" + workingDir , "apply" , "-auto-approve" )
473473 if err != nil {
474474 err2 := fmt .Errorf ("failed, previous request in progress" )
475475 log .Error ().Err (err ).Msg (err2 .Error ()) // error
@@ -479,15 +479,39 @@ func CreateSqlDb(c echo.Context) error {
479479 }
480480 return c .JSON (http .StatusInternalServerError , res )
481481 }
482+
483+ // global option to set working dir: -chdir=/home/ubuntu/dev/cloud-barista/mc-terrarium/.terrarium/{trId}/sql-db
484+ // show: subcommand
485+ ret , err := tofu .ExecuteTofuCommand (trId , reqId , "-chdir=" + workingDir , "output" , "-json" , "sql_db_info" )
486+ if err != nil {
487+ err2 := fmt .Errorf ("failed to read resource info (detail: %s) specified as 'output' in the state file" , "refined" )
488+ log .Error ().Err (err ).Msg (err2 .Error ())
489+ res := model.Response {
490+ Success : false ,
491+ Message : err2 .Error (),
492+ }
493+ return c .JSON (http .StatusInternalServerError , res )
494+ }
495+
496+ var resourceInfo map [string ]interface {}
497+ err = json .Unmarshal ([]byte (ret ), & resourceInfo )
498+ if err != nil {
499+ log .Error ().Err (err ).Msg ("" ) // error
500+ res := model.Response {
501+ Success : false ,
502+ Message : "failed to unmarshal resource info" ,
503+ }
504+ return c .JSON (http .StatusInternalServerError , res )
505+ }
506+
482507 res := model.Response {
483508 Success : true ,
484- Message : "the request (id: " + reqId + ") is successfully accepted and still deploying resource " ,
485- Detail : ret ,
509+ Message : "refined read resource info (map) " ,
510+ Object : resourceInfo ,
486511 }
487-
488512 log .Debug ().Msgf ("%+v" , res ) // debug
489513
490- return c .JSON (http .StatusCreated , res )
514+ return c .JSON (http .StatusOK , res )
491515}
492516
493517// GetResourceInfoOfSqlDb godoc
0 commit comments