Skip to content

Commit 60ed69e

Browse files
authored
Merge pull request #111 from yunkon-kim/241115-02
Staging v0.0.16
2 parents f82a9de + 2951c72 commit 60ed69e

15 files changed

Lines changed: 77 additions & 29 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ secrets/**
5353
!secrets/template-*
5454
!secrets/.keep
5555
!secrets/README.md
56+
!secrets/load-ncp-cred-env.sh
5657

5758
# Ignore container volumes
5859
container-volume/

‎api/docs.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,8 +925,8 @@ const docTemplate = `{
925925
}
926926
],
927927
"responses": {
928-
"201": {
929-
"description": "Created",
928+
"200": {
929+
"description": "OK",
930930
"schema": {
931931
"$ref": "#/definitions/model.Response"
932932
}

‎api/swagger.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,8 +919,8 @@
919919
}
920920
],
921921
"responses": {
922-
"201": {
923-
"description": "Created",
922+
"200": {
923+
"description": "OK",
924924
"schema": {
925925
"$ref": "#/definitions/model.Response"
926926
}

‎api/swagger.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -897,8 +897,8 @@ paths:
897897
produces:
898898
- application/json
899899
responses:
900-
"201":
901-
description: Created
900+
"200":
901+
description: OK
902902
schema:
903903
$ref: '#/definitions/model.Response'
904904
"400":

‎docker-compose.yaml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ networks:
44

55
services:
66
mc-terrarium:
7-
image: cloudbaristaorg/mc-terrarium:0.0.10
7+
image: cloudbaristaorg/mc-terrarium:0.0.16
88
container_name: mc-terrarium
99
build:
1010
context: .
@@ -18,6 +18,7 @@ services:
1818
env_file:
1919
- ./secrets/credentials # AWS credentials
2020
- ./secrets/credential-azure.env # Azure credentials
21+
- ./secrets/credential-ncp.env # NCP credentials
2122
volumes:
2223
- ./secrets:/app/secrets:ro # GCP credentials
2324
- ./container-volume/mc-terrarium-container/.terrarium:/app/.terrarium

‎pkg/api/rest/handler/sql-db.go‎

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

‎pkg/api/rest/model/sql-db.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ type TfVarsSqlDb struct {
1111
DBEnginePort int `json:"db_engine_port,omitempty" example:"3306"`
1212
IngressCIDRBlock string `json:"ingress_cidr_block,omitempty" example:"0.0.0.0/0"`
1313
EgressCIDRBlock string `json:"egress_cidr_block,omitempty" example:"0.0.0.0/0"`
14-
DBEngineVersion string `json:"db_engine_version" example:"8.0.39"`
15-
DBInstanceSpec string `json:"db_instance_spec" example:"db.t3.micro"`
14+
DBEngineVersion string `json:"db_engine_version,omitempty" example:"8.0.39"`
15+
DBInstanceSpec string `json:"db_instance_spec,omitempty" example:"db.t3.micro"`
1616
DBAdminUsername string `json:"db_admin_username" example:"mydbadmin"`
1717
DBAdminPassword string `json:"db_admin_password" example:"Password1234!"`
1818
// DBInstanceID string `json:"db_instance_identifier" example:"mydbinstance"`

‎pkg/tofu/tofu.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func ExecuteTofuCommand(trId, reqId string, args ...string) (string, error) {
142142
if err != nil {
143143
log.Error().Msgf("Command execution failed: %v", err)
144144
setRunningStatus(trId, "Failed")
145-
return "", err
145+
return output, err
146146
}
147147
// log.Debug().Msgf("Command output: %s", output)
148148
setRunningStatus(trId, "Success")

‎secrets/load-ncp-cred-env.sh‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# Find the script directory
4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
ENV_FILE="$SCRIPT_DIR/credential-ncp.env"
6+
7+
# Check if .env file exists
8+
if [[ -f "$ENV_FILE" ]]; then
9+
while IFS= read -r line; do
10+
if [[ -n "$line" && ! "$line" =~ ^# ]]; then
11+
eval export "$line"
12+
fi
13+
done < "$ENV_FILE"
14+
echo "successfully loaded the NCP credential environment variables"
15+
else
16+
echo "error: dose not exist file, $ENV_FILE"
17+
fi

‎secrets/template-credential-ncp‎

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)