Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions internal/command/views/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
package views

import (
"encoding/json"
"fmt"
"strings"
"time"

"github.com/hashicorp/terraform/internal/command/arguments"
"github.com/hashicorp/terraform/internal/tfdiags"
Expand Down Expand Up @@ -97,18 +95,21 @@ func (v *InitJSON) Output(messageCode InitMessageCode, params ...any) {
return
}

current_timestamp := time.Now().UTC().Format(time.RFC3339)
json_data := map[string]string{
"@level": "info",
"@message": preppedMessage,
"@module": "terraform.ui",
"@timestamp": current_timestamp,
"type": "init_output",
"message_code": string(messageCode),
}

init_output, _ := json.Marshal(json_data)
v.view.view.streams.Println(string(init_output))
// Logged data includes by default:
// @level as "info"
// @module as "terraform.ui" (See NewJSONView)
// @timestamp formatted in the default way
//
// In the method below we:
// * Set @message as the first argument value
// * Annotate with extra data:
// "type":"init_output"
// "message_code":"<value>"
v.view.log.Info(
preppedMessage,
"type", "init_output",
"message_code", string(messageCode),
)
}

func (v *InitJSON) LogInitMessage(messageCode InitMessageCode, params ...any) {
Expand Down
Loading