Skip to content

Commit fee7dcc

Browse files
authored
Merge pull request #2 from NipulM/impr/cost-est-implementation
Complete core cost estimation implementation with OpenInfraQuote
2 parents aecb89b + 25a2878 commit fee7dcc

7 files changed

Lines changed: 924 additions & 0 deletions

File tree

cmd/estimate.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/NipulM/oisbase/internal/config"
8+
"github.com/NipulM/oisbase/internal/estimator"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var estimateCmd = &cobra.Command{
13+
Use: "estimate",
14+
Short: "Estimate the cost of the project",
15+
Long: "Estimate the cost of the project using openinfraquote",
16+
Run: func(cmd *cobra.Command, args []string) {
17+
projectConfig, err := config.LoadConfig()
18+
if err != nil {
19+
fmt.Printf("Error: %v\n", err)
20+
return
21+
}
22+
23+
_, err = estimator.Estimate(projectConfig)
24+
if err != nil {
25+
fmt.Printf("Error: %v\n", err)
26+
os.Exit(1)
27+
}
28+
},
29+
30+
31+
}
32+
33+
func init() {
34+
rootCmd.AddCommand(estimateCmd)
35+
}

internal/estimator/estimator.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package estimator
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/AlecAivazis/survey/v2"
7+
"github.com/NipulM/oisbase/internal/config"
8+
)
9+
10+
func Estimate(config *config.ProjectConfig) (float64, error) {
11+
const (
12+
colourYellow = "\033[33m"
13+
colourReset = "\033[0m"
14+
)
15+
16+
fmt.Println(colourYellow + "Warning: Cost estimation requires a saved Terraform plan file generated via 'terraform plan -out=tf.plan'." + colourReset)
17+
18+
userApprovalPrompt := &survey.Confirm{
19+
Message: "Do you want to proceed with cost estimation using OpenInfraQuote?",
20+
}
21+
var userApproval bool
22+
survey.AskOne(userApprovalPrompt, &userApproval)
23+
if !userApproval {
24+
return 0, nil
25+
}
26+
27+
terraformPlan, err := GenerateOpenInfraQuotePlanForTerraformPlan(config)
28+
if err != nil {
29+
return 0, fmt.Errorf("failed to generate terraform plan: %w", err)
30+
}
31+
32+
fmt.Println(terraformPlan)
33+
34+
return 0, nil
35+
}

0 commit comments

Comments
 (0)