Skip to content

Commit 4a6ae1f

Browse files
committed
report output is optional and disabled by default
1 parent cfce98a commit 4a6ae1f

4 files changed

Lines changed: 11 additions & 2 deletions

File tree

cmd/agent.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import (
1919
)
2020

2121
var (
22-
autoExecute bool
22+
autoExecute bool
23+
reportOutput bool
2324
)
2425

2526
var agentCmd = &cobra.Command{
@@ -231,6 +232,7 @@ func executeCommand(ctx context.Context, c *websocket.Conn, cmd utils.AgentComma
231232
state := &utils.State{}
232233
state.IacconsoleApiUrl = os.Getenv("IACCONSOLE_API_URL")
233234
state.StateS3Path = "./state"
235+
state.ReportOutput = reportOutput
234236

235237
utils.ExecuteAgentCommand(ctx, c, cmd, state)
236238
}
@@ -298,4 +300,5 @@ func contains(s, substr string) bool {
298300
func init() {
299301
rootCmd.AddCommand(agentCmd)
300302
agentCmd.Flags().BoolVar(&autoExecute, "auto-execute", false, "Automatically approve and execute commands without prompting")
303+
agentCmd.Flags().BoolVar(&reportOutput, "report-output", false, "report terraform output to server")
301304
}

cmd/exec.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ var execCmd = &cobra.Command{
5757
s.Workspace, _ = cmd.Flags().GetString("workspace")
5858
s.IacconsoleApiUrl = IACCONSOLE_API_URL
5959
s.DimensionsFlags, _ = cmd.Flags().GetStringSlice("dimension")
60+
s.ReportOutput, _ = cmd.Flags().GetBool("report-output")
6061
s.UnitPath, _ = filepath.Abs(s.GetStringFromViperByOrgOrDefault("units_path") + "/" + s.OrgName + "/" + s.UnitName)
6162
if s.GetStringFromViperByOrgOrDefault("shared_modules_path") != "" {
6263
s.SharedModulesPath, _ = filepath.Abs(s.GetStringFromViperByOrgOrDefault("shared_modules_path"))
@@ -156,6 +157,7 @@ func init() {
156157
execCmd.Flags().StringP("org", "o", "", "specify org")
157158
execCmd.Flags().StringP("workspace", "w", "master", "specify workspace for IaCConsole DB")
158159
execCmd.Flags().BoolP("clean", "c", false, "remove tmp after execution")
160+
execCmd.Flags().Bool("report-output", false, "report terraform output to server")
159161
//viper.BindPFlag("org", execCmd.Flags().Lookup("org"))
160162
if err := execCmd.MarkFlagRequired("unit"); err != nil {
161163
log.Fatalf("Error marking flag 'unit' as required: %v", err)

utils/externals.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,11 @@ func (s *State) ReportHistory(ctx context.Context, cmdToExec string, cmdArgs []s
136136
}
137137

138138
var outputs map[string]interface{}
139+
if !s.ReportOutput {
140+
log.Println("Terraform output reporting is disabled")
141+
}
139142

140-
if exitCode == 0 && (cmdMainArg == "apply" || cmdMainArg == "destroy") {
143+
if s.ReportOutput && exitCode == 0 && (cmdMainArg == "apply" || cmdMainArg == "destroy") {
141144
// Run tofu output -json to gather outputs
142145
outputCmd := exec.Command(cmdToExec, "output", "-json")
143146
outputCmd.Dir = s.CmdWorkTempDir

utils/structures.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type State struct {
1414
StateS3Path string
1515
IacconsoleApiUrl string
1616
Workspace string
17+
ReportOutput bool
1718
}
1819

1920
type unitManifestStruct struct {

0 commit comments

Comments
 (0)