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

Add a flag to optionally enable Github Markdown Formatting for diffs #1751

Merged

Conversation

enochlo
Copy link
Contributor

@enochlo enochlo commented Aug 10, 2021

Heavily inspired from #1325 and looking at #1395. Thanks @raxod502-plaid for the base for the regex.

I added the ability to optionally enable Atlantis to do some Github markdown diff formatting, to enable color coded comments. Also added some tests using the original PR as reference for correctness. This has been pretty useful for me, and hopefully will be useful for the users asking for a bit more Github friendliness :)

This flag will turn comments into something like this:

New Atlantis Comment Ran Plan for dir: `path/to/terraform` workspace: `default`
Show Output
Note: Objects have changed outside of Terraform

Terraform detected the following changes made outside of Terraform since the
last "terraform apply":

  # module.dev-roles.module.iam_assumable_roles_with_saml.aws_iam_role.role1[0] has been changed
! resource "aws_iam_role" "role1" {
        id                    = "User-Role1"
!       managed_policy_arns   = [
+           "arn:aws:iam::aws:policy/Policy1",
        ]
        name                  = "User-Role1"
+       tags                  = {
+           "Created-By" = "terraform"
+           "Owner"      = "[email protected]"
        }
        # (8 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }
  # module.dev-roles.module.iam_assumable_roles_with_saml.aws_iam_role.role2[0] has been changed
! resource "aws_iam_role" "role2" {
!       assume_role_policy    = jsonencode(
!           {
!               Statement = [
!                   {
!                       Principal = {
!                           Federated = [
-                               "arn:aws:iam::123456789000:saml-provider/Provider1",
                                "arn:aws:iam::123456789000:saml-provider/Provider2",
+                               "arn:aws:iam::123456789000:saml-provider/Provider1",
                            ]
                        }
                        # (4 unchanged elements hidden)
                    },
                ]
                # (1 unchanged element hidden)
            }
        )
        id                    = "User-Role2"
!       managed_policy_arns   = [
+           "arn:aws:iam::aws:policy/Policy2",
        ]
        name                  = "User-Role2"
+       tags                  = {
+           "Created-By" = "terraform"
+           "Owner"      = "[email protected]"
        }
        # (7 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }
  # module.dev-roles.module.iam_assumable_roles_with_saml.aws_iam_role.role3[0] has been changed
! resource "aws_iam_role" "admin" {
        id                    = "User-Role3"
!       managed_policy_arns   = [
+           "arn:aws:iam::aws:policy/Policy3",
        ]
        name                  = "User-Role3"
+       tags                  = {
+           "Created-By" = "terraform"
+           "Owner"      = "[email protected]"
        }
        # (8 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

Unless you have made equivalent changes to your configuration, or ignored the
relevant attributes using ignore_changes, the following plan may include
actions to undo or respond to these changes.

─────────────────────────────────────────────────────────────────────────────

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
! update in-place

Terraform will perform the following actions:

  # module.dev-roles.module.iam_assumable_roles_with_saml.aws_iam_role.role3[0] will be updated in-place
! resource "aws_iam_role" "admin" {
        id                    = "User-Role3"
        name                  = "User-Role3"
!       tags                  = {
-           "Created-By" = "terraform" -> null
-           "Owner"      = "[email protected]" -> null
        }
!       tags_all              = {
!           "Created-By"  = "terraform" -> "terraformasdasd"
-           "Owner"       = "[email protected]" -> null
+           "RandomTag"   = ";aslkdjlk"
            # (3 unchanged elements hidden)
        }
        # (8 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

  # module.dev-roles.module.iam_assumable_roles_with_saml.aws_iam_role.role1[0] will be updated in-place
! resource "aws_iam_role" "role1" {
        id                    = "User-Role1"
        name                  = "User-Role1"
!       tags                  = {
-           "Created-By" = "terraform" -> null
-           "Owner"      = "[email protected]" -> null
        }
!       tags_all              = {
!           "Created-By"  = "terraform" -> "terraformasdasd"
-           "Owner"       = "[email protected]" -> null
+           "RandomTag"   = ";aslkdjlk"
            # (3 unchanged elements hidden)
        }
        # (8 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

  # module.dev-roles.module.iam_assumable_roles_with_saml.aws_iam_role.role2[0] will be updated in-place
! resource "aws_iam_role" "role2" {
        id                    = "User-Role2"
        name                  = "User-Role2"
!       tags                  = {
-           "Created-By" = "terraform" -> null
-           "Owner"      = "[email protected]" -> null
        }
!       tags_all              = {
!           "Created-By"  = "terraform" -> "terraformasdasd"
-           "Owner"       = "[email protected]" -> null
+           "RandomTag"   = ";aslkdjlk"
            # (3 unchanged elements hidden)
        }
        # (8 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

Plan: 0 to add, 3 to change, 0 to destroy.
  • ▶️ To apply this plan, comment:
    • atlantis apply -d path/to/terraform
  • 🚮 To delete this plan click here
  • 🔁 To plan this project again, comment:
    • atlantis plan -d path/to/terraform

Note: Objects have changed outside of Terraform
Plan: 0 to add, 3 to change, 0 to destroy.


  • ⏩ To apply all unapplied plans from this pull request, comment:
    • atlantis apply
  • 🚮 To delete all plans and locks for the PR, comment:
    • atlantis unlock

@enochlo enochlo requested a review from a team as a code owner August 10, 2021 18:09
Copy link
Contributor

@nishkrishnan nishkrishnan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job! Thanks for contributing!

@enochlo
Copy link
Contributor Author

enochlo commented Aug 18, 2021

@nishkrishnan any next steps for me here to get this merged? :)

@nishkrishnan
Copy link
Contributor

@nishkrishnan any next steps for me here to get this merged? :)

I'm just going to leave it open for a bit for other maintainers to look at and then I'll merge it in.

Copy link
Contributor

@jamengual jamengual left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, thanks

@xavipanda
Copy link
Contributor

oh this one is such a great feature!! im looking forward to see it released to enable it! thank you so much

@nishkrishnan nishkrishnan merged commit 89236d8 into runatlantis:master Aug 30, 2021
philnielsen added a commit to philnielsen/helm-charts that referenced this pull request Sep 13, 2021
Add flag to enable runatlantis/atlantis#1751
so that we can use color comments. Defaulted to false so no change by
default.
@richstokes
Copy link
Contributor

What is the flag / how do you enable this feature?

lkysow pushed a commit to runatlantis/helm-charts that referenced this pull request Nov 8, 2021
Add flag to enable runatlantis/atlantis#1751
so that we can use color comments. Defaulted to false so no change by
default.
krrrr38 pushed a commit to krrrr38/atlantis that referenced this pull request Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants