Skip to content

Commit

Permalink
Return value
Browse files Browse the repository at this point in the history
  • Loading branch information
pratishshr committed Oct 21, 2019
1 parent 9bf916c commit ba81e76
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
6 changes: 6 additions & 0 deletions core/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ type Project struct {
HealthCheckPath string `json:"healthCheckPath"`
Env map[string]Env `json:"env"`
}

// Frontend defined the output for frontend infrastructure
type Frontend struct {
Bucket string `json:"bucket"`
URL string `json:"url"`
}
33 changes: 8 additions & 25 deletions infrastructure/internals/initialize/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package initialize
import (
"encoding/json"
"errors"
"fmt"

"strings"

Expand Down Expand Up @@ -73,20 +72,18 @@ type frontendTerraformOutput struct {
// }

// Run intitializes the infrastructure in the specified cloud provider.
func Run(project structs.Project, environment string) string {
func Run(project structs.Project, environment string) interface{} {
if !utils.CommandExists("terraform") {
logger.FailOnError(errors.New("terraform does not exist"), "Please install terraform on your device")
}

infrastructureInfo := Initialize(project, environment)

logger.LogOutput(infrastructureInfo)

return infrastructureInfo
}

// Initialize creates infrastructure for frontend and backend according the given input.
func Initialize(project structs.Project, environment string) string {
func Initialize(project structs.Project, environment string) interface{} {
if strings.EqualFold(project.Type, "frontend") {
out := CreateFrontend(project, environment)

Expand All @@ -104,7 +101,7 @@ func Initialize(project structs.Project, environment string) string {
}

// CreateFrontend creates infrastructure for frontend.
func CreateFrontend(project structs.Project, environment string) string {
func CreateFrontend(project structs.Project, environment string) structs.Frontend {
workspaceRoot := "/tmp"

terraformOutput := frontendTerraformOutput{}
Expand All @@ -122,24 +119,10 @@ func CreateFrontend(project structs.Project, environment string) string {

_ = json.Unmarshal([]byte(output), &terraformOutput)

fmt.Println(terraformOutput)

// result := utils.FrontendResult{
// Project: clientArgs.Project,
// Deployment: clientArgs.Deployment,
// Data: frontendTerraformOutput,
// }

// out, err := json.Marshal(result)

// if err != nil {
// logger.LogError(err, "Error Marshalling output")
// return "", err
// }

// logger.LogOutput(string(out))

// return string(out), err
frontend := structs.Frontend{
Bucket: terraformOutput.BucketName.Value,
URL: terraformOutput.FrontendWebURL.Value,
}

return ""
return frontend
}

0 comments on commit ba81e76

Please sign in to comment.