Skip to content

Commit

Permalink
feat(plan): add the option -ignore-warning (#1423)
Browse files Browse the repository at this point in the history
* feat(plan): add the option `-ignore-warning`

* fix: set -ignore-warning
  • Loading branch information
suzuki-shunsuke authored Oct 4, 2024
1 parent 4ec8d91 commit 10d6eda
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ $ tfcmt [<global options>] plan [-patch] [-skip-no-changes] -- terraform plan [<
Name: "skip-no-changes",
Usage: "If there is no change tfcmt updates a label but doesn't post a comment",
},
&cli.BoolFlag{
Name: "ignore-warning",
Usage: "If skip-no-changes is enabled, comment is posted even if there is a warning. If skip-no-changes is disabled, warning is removed from the comment.",
},
&cli.BoolFlag{
Name: "disable-label",
Usage: "Disable to add or update a label",
Expand Down
4 changes: 4 additions & 0 deletions pkg/cli/var.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ func parseOpts(ctx *cli.Context, cfg *config.Config, envs []string) error { //no
cfg.Terraform.Plan.WhenNoChanges.DisableComment = ctx.Bool("skip-no-changes")
}

if ctx.IsSet("ignore-warning") {
cfg.Terraform.Plan.IgnoreWarning = ctx.Bool("ignore-warning")
}

vars := ctx.StringSlice("var")
vm := make(map[string]string, len(vars))
if err := parseVars(vars, envs, vm); err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type Plan struct {
WhenPlanError WhenPlanError `yaml:"when_plan_error"`
WhenParseError WhenParseError `yaml:"when_parse_error"`
DisableLabel bool `yaml:"disable_label"`
IgnoreWarning bool `yaml:"ignore_warning"`
}

// WhenAddOrUpdateOnly is a configuration to notify the plan result contains new or updated in place resources
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func (c *Controller) getNotifier(ctx context.Context) (notifier.Notifier, error)
Templates: c.Config.Templates,
Patch: c.Config.PlanPatch,
SkipNoChanges: c.Config.Terraform.Plan.WhenNoChanges.DisableComment,
IgnoreWarning: c.Config.Terraform.Plan.IgnoreWarning,
Masks: c.Config.Masks,
})
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/notifier/github/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type Config struct {
UseRawOutput bool
Patch bool
SkipNoChanges bool
IgnoreWarning bool
Masks []*config.Mask
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/notifier/github/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func (g *NotifyService) Plan(ctx context.Context, param *notifier.ParamExec) err
errMsgs = append(errMsgs, g.updateLabels(ctx, result)...)
}

if cfg.IgnoreWarning {
result.Warning = ""
}

template.SetValue(terraform.CommonTemplate{
Result: result.Result,
ChangedResult: result.ChangedResult,
Expand Down

0 comments on commit 10d6eda

Please sign in to comment.