Skip to content

Commit

Permalink
Only highlight Terraform changes on GitHub (runatlantis#2337)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloconnor authored and krrrr38 committed Dec 16, 2022
1 parent 2af5b04 commit bba040d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
58 changes: 58 additions & 0 deletions server/events/markdown_renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2173,13 +2173,42 @@ Terraform will perform the following actions:
id = "redacted_redacted.redacted.redacted.io_A"
name = "redacted.redacted.redacted.io"
~ records = [
"foo",
- "redacted",
] -> (known after apply)
ttl = 300
type = "A"
zone_id = "redacted"
}
# helm_release.external_dns[0] will be updated in-place
~ resource "helm_release" "external_dns" {
id = "external-dns"
name = "external-dns"
~ values = [
- <<-EOT
image:
tag: "0.12.0"
pullSecrets:
- XXXXX
domainFilters: ["xxxxx","xxxxx"]
base64:
+dGhpcyBpcyBzb21lIHN0cmluZyBvciBzb21ldGhpbmcKCg==
EOT,
+ <<-EOT
image:
tag: "0.12.0"
pullSecrets:
- XXXXX
domainFilters: ["xxxxx","xxxxx"]
base64:
+dGhpcyBpcyBzb21lIHN0cmluZyBvciBzb21ldGhpbmcKCg==
EOT,
]
}
Plan: 1 to add, 1 to change, 1 to destroy.
`
cases := []struct {
Expand Down Expand Up @@ -2308,13 +2337,42 @@ Terraform will perform the following actions:
id = "redacted_redacted.redacted.redacted.io_A"
name = "redacted.redacted.redacted.io"
! records = [
"foo",
- "redacted",
] -> (known after apply)
ttl = 300
type = "A"
zone_id = "redacted"
}
# helm_release.external_dns[0] will be updated in-place
! resource "helm_release" "external_dns" {
id = "external-dns"
name = "external-dns"
! values = [
- <<-EOT
image:
tag: "0.12.0"
pullSecrets:
- XXXXX
domainFilters: ["xxxxx","xxxxx"]
base64:
+dGhpcyBpcyBzb21lIHN0cmluZyBvciBzb21ldGhpbmcKCg==
EOT,
+ <<-EOT
image:
tag: "0.12.0"
pullSecrets:
- XXXXX
domainFilters: ["xxxxx","xxxxx"]
base64:
+dGhpcyBpcyBzb21lIHN0cmluZyBvciBzb21ldGhpbmcKCg==
EOT,
]
}
Plan: 1 to add, 1 to change, 1 to destroy.
$$$
Expand Down
6 changes: 4 additions & 2 deletions server/events/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,12 @@ func (p *PlanSuccess) Summary() string {

// DiffMarkdownFormattedTerraformOutput formats the Terraform output to match diff markdown format
func (p PlanSuccess) DiffMarkdownFormattedTerraformOutput() string {
diffKeywordRegex := regexp.MustCompile(`(?m)^( +)([-+~])`)
diffKeywordRegex := regexp.MustCompile(`(?m)^( +)([-+~]\s)(.*)(\s->\s|<<|\{|\(known after apply\)|\[)(.*)`)
diffListRegex := regexp.MustCompile(`(?m)^( +)([-+~]\s)(".*",)`)
diffTildeRegex := regexp.MustCompile(`(?m)^~`)

formattedTerraformOutput := diffKeywordRegex.ReplaceAllString(p.TerraformOutput, "$2$1")
formattedTerraformOutput := diffKeywordRegex.ReplaceAllString(p.TerraformOutput, "$2$1$3$4$5")
formattedTerraformOutput = diffListRegex.ReplaceAllString(formattedTerraformOutput, "$2$1$3")
formattedTerraformOutput = diffTildeRegex.ReplaceAllString(formattedTerraformOutput, "!")

return formattedTerraformOutput
Expand Down

0 comments on commit bba040d

Please sign in to comment.