Skip to content

Commit

Permalink
Use !~ for updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dflook committed Dec 11, 2023
1 parent a9ad47b commit 49623b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion image/src/github_pr_comment/plan_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def format_diff(plan_text: str) -> str:
count=1
))

replaced = replaced.replace('~', '!')
replaced = replaced.replace('~ ', '!~')

replaced = re.sub(
r'(?P<leading_space>\s+)\# (?P<trailing>\(.*hidden)',
Expand Down
23 changes: 12 additions & 11 deletions tests/test_diff_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@ def test_diff():
expected = '''
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
! update in-place
!~ update in-place
- destroy
-/+ destroy and then create replacement
+/- create replacement and then destroy
Terraform will perform the following actions:
# aws_s3_object.update will be updated in-place
! resource "aws_s3_object" "update" {
! content = "hello" -> "update"
!~ resource "aws_s3_object" "update" {
!~ content = "hello" -> "update"
id = "test-plan-colours-test-object"
tags = {}
+ version_id = (known after apply)
Expand All @@ -116,9 +116,9 @@ def test_diff():
# random_string.create_before_delete must be replaced
+/- resource "random_string" "create_before_delete" {
! id = "BW8p" -> (known after apply)
! length = 4 -> 3 # forces replacement
! result = "BW8p" -> (known after apply)
!~ id = "BW8p" -> (known after apply)
!~ length = 4 -> 3 # forces replacement
!~ result = "BW8p" -> (known after apply)
# (9 unchanged attributes hidden)
}
Expand All @@ -141,9 +141,9 @@ def test_diff():
# random_string.delete_before_create must be replaced
-/+ resource "random_string" "delete_before_create" {
! id = "S@M" -> (known after apply)
! length = 3 -> 4 # forces replacement
! result = "S@M" -> (known after apply)
!~ id = "S@M" -> (known after apply)
!~ length = 3 -> 4 # forces replacement
!~ result = "S@M" -> (known after apply)
# (9 unchanged attributes hidden)
}
Expand All @@ -152,7 +152,7 @@ def test_diff():
Changes to Outputs:
+ add = "hello"
- delete = "goodbye" -> null
! update = "hello" -> "update"
!~ update = "hello" -> "update"
'''

print(format_diff(plan))
Expand Down Expand Up @@ -230,7 +230,7 @@ def test_heredoc():
- destroy
-/+ destroy and then create replacement
+/- create replacement and then destroy
! update in-place
!~ update in-place
Terraform will perform the following actions:
Expand Down Expand Up @@ -287,4 +287,5 @@ def test_heredoc():
Plan: 3 to add, 1 to change, 3 to destroy.'''

print(format_diff(plan))
assert format_diff(plan) == expected

0 comments on commit 49623b6

Please sign in to comment.