github.com/opentofu/opentofu@v1.7.1/internal/cloud/backend_run_warning.go (about) 1 // Copyright (c) The OpenTofu Authors 2 // SPDX-License-Identifier: MPL-2.0 3 // Copyright (c) 2023 HashiCorp, Inc. 4 // SPDX-License-Identifier: MPL-2.0 5 6 package cloud 7 8 import ( 9 "context" 10 "fmt" 11 "strings" 12 13 tfe "github.com/hashicorp/go-tfe" 14 ) 15 16 const ( 17 changedPolicyEnforcementAction = "changed_policy_enforcements" 18 changedTaskEnforcementAction = "changed_task_enforcements" 19 ignoredPolicySetAction = "ignored_policy_sets" 20 ) 21 22 func (b *Cloud) renderRunWarnings(ctx context.Context, client *tfe.Client, runId string) error { 23 if b.CLI == nil { 24 return nil 25 } 26 27 result, err := client.RunEvents.List(ctx, runId, nil) 28 if err != nil { 29 return err 30 } 31 if result == nil { 32 return nil 33 } 34 35 // We don't have to worry about paging as the API doesn't support it yet 36 for _, re := range result.Items { 37 switch re.Action { 38 case changedPolicyEnforcementAction, changedTaskEnforcementAction, ignoredPolicySetAction: 39 if re.Description != "" { 40 b.CLI.Warn(b.Colorize().Color(strings.TrimSpace(fmt.Sprintf( 41 runWarningHeader, re.Description)) + "\n")) 42 } 43 } 44 } 45 46 return nil 47 } 48 49 const runWarningHeader = ` 50 [reset][yellow]Warning:[reset] %s 51 `