Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Include information about imports in PlanSuccessStats #3621

Merged
Show file tree
Hide file tree
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
13 changes: 7 additions & 6 deletions server/events/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ type PolicySetStatus struct {
// Summary regexes
var (
reChangesOutside = regexp.MustCompile(`Note: Objects have changed outside of Terraform`)
rePlanChanges = regexp.MustCompile(`Plan: (\d+) to add, (\d+) to change, (\d+) to destroy.`)
rePlanChanges = regexp.MustCompile(`Plan: (?:(\d+) to import, )?(\d+) to add, (\d+) to change, (\d+) to destroy.`)
reNoChanges = regexp.MustCompile(`No changes. (Infrastructure is up-to-date|Your infrastructure matches the configuration).`)
)

Expand Down Expand Up @@ -631,8 +631,8 @@ type WorkflowHookCommandContext struct {

// PlanSuccessStats holds stats for a plan.
type PlanSuccessStats struct {
Add, Change, Destroy int
Changes, ChangesOutside bool
Import, Add, Change, Destroy int
Changes, ChangesOutside bool
}

func NewPlanSuccessStats(output string) PlanSuccessStats {
Expand All @@ -647,9 +647,10 @@ func NewPlanSuccessStats(output string) PlanSuccessStats {
// We can skip checking the error here as we can assume
// Terraform output will always render an integer on these
// blocks.
s.Add, _ = strconv.Atoi(m[1])
s.Change, _ = strconv.Atoi(m[2])
s.Destroy, _ = strconv.Atoi(m[3])
s.Import, _ = strconv.Atoi(m[1])
s.Add, _ = strconv.Atoi(m[2])
s.Change, _ = strconv.Atoi(m[3])
s.Destroy, _ = strconv.Atoi(m[4])
}

return s
Expand Down
24 changes: 24 additions & 0 deletions server/events/models/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ func TestPlanSuccess_Summary(t *testing.T) {
"dummy\nPlan: 100 to add, 111 to change, 222 to destroy.",
"Plan: 100 to add, 111 to change, 222 to destroy.",
},
{
"dummy\nPlan: 42 to import, 53 to add, 64 to change, 75 to destroy.",
"Plan: 42 to import, 53 to add, 64 to change, 75 to destroy.",
},
{
"Note: Objects have changed outside of Terraform\ndummy\nNo changes. Infrastructure is up-to-date.",
"\n**Note: Objects have changed outside of Terraform**\nNo changes. Infrastructure is up-to-date.",
Expand Down Expand Up @@ -629,6 +633,7 @@ func TestPlanSuccessStats(t *testing.T) {
Plan: 1 to add, 3 to change, 2 to destroy.`,
models.PlanSuccessStats{
Changes: true,

Add: 1,
Change: 3,
Destroy: 2,
Expand All @@ -651,6 +656,25 @@ func TestPlanSuccessStats(t *testing.T) {
ChangesOutside: true,
},
},
{
"with imports",
`Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
+ create
~ update in-place
- destroy
Terraform will perform the following actions:
- null_resource.hi[1]
Plan: 42 to import, 31 to add, 20 to change, 1 to destroy.`,
models.PlanSuccessStats{
Changes: true,

Import: 42,
Add: 31,
Change: 20,
Destroy: 1,
},
},
{
"changes and changes outside",
`Note: Objects have changed outside of Terraform
Expand Down