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

Support atlantis refresh subcommand #2849

Open
1 task
nitrocode opened this issue Dec 22, 2022 · 7 comments
Open
1 task

Support atlantis refresh subcommand #2849

nitrocode opened this issue Dec 22, 2022 · 7 comments
Labels
feature New functionality/enhancement Stale

Comments

@nitrocode
Copy link
Member

nitrocode commented Dec 22, 2022

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Describe the user story

For terraform 0.15.4 and later, sometimes the attributes of managed resources are modified. When a terraform plan is run, we get a lot of information that frankly no one cares about and then finally the plan is appended beneath it.

In order to remove the text above the plan we have to run a terraform refresh.

This can be added to the plan workflow but I do not want to run it all the time since it's more calls to AWS than we need.

Ref https://support.hashicorp.com/hc/en-us/articles/4405950960147-New-Feature-Objects-have-changed-outside-of-Terraform-

Example of the "junk" with the no changes message

Note: Objects have changed outside of Terraform

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

  # module.xyz.module.this_green.aws_autoscaling_group.this[0] has changed
! resource "aws_autoscaling_group" "this" {
+       default_instance_warmup   = 0
!       desired_capacity          = 24 -> 0
        id                        = "xyz"
!       max_size                  = 72 -> 0
!       min_size                  = 15 -> 0
        name                      = "xyz"
        # (22 unchanged attributes hidden)

        # (8 unchanged blocks 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.

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

No changes. Your infrastructure matches the configuration.

Describe the solution you'd like

It would be best to have an option to run it like this.

atlantis plan --refresh-first

or

atlantis refresh

Related to this issue #2776

Describe the drawbacks of your solution

None

Describe alternatives you've considered

Run a refresh-only plan first

# create a refresh only plan
atlantis plan -- -refresh-only
# approval required
# apply the refresh only plan w/o merging the branch
atlantis apply -auto-merge-disabled
# create a new plan with an easier to review plan
atlantis plan
# apply the plan
atlantis apply

or

Run terraform refresh locally and then run atlantis plan in the PR.

@nitrocode nitrocode added the feature New functionality/enhancement label Dec 22, 2022
@bschaatsbergen
Copy link
Member

I believe that the terraform refresh command has been deprecated due to it being unsafe. Is this something we still want to work on? Also running atlantis plan or atlantis apply should result in the same behaviour according to the docs:

Terraform automatically performs the same refreshing actions as a part of creating a plan in both the terraform plan and terraform apply commands

@nitrocode
Copy link
Member Author

I believe that the terraform refresh command has been deprecated due to it being unsafe

Do you have a reference explaining that the refresh command is unsafe?

Is this something we still want to work on?

Yes, id personally like it.

Also running atlantis plan or atlantis apply should result in the same behaviour according to the docs:

Yes this is true. However, then you get a more complex plan to review. The refresh reduces the plan to the main resources that are changing.

@bschaatsbergen
Copy link
Member

It's mentioned in the documentation here: https://developer.hashicorp.com/terraform/cli/commands/refresh, I don't think that the warning should apply to Atlantis, as I expect that this more related to local development.

Anyhow, I would like to pick this up in the case that we still want this feature.

@nitrocode
Copy link
Member Author

Ah thank you for sharing that link. I did not know it was deprecated.

https://developer.hashicorp.com/terraform/tutorials/state/refresh

Though Terraform will continue to support the refresh subcommand in future versions, it is deprecated, and we encourage you to use the -refresh-only flag instead. This allows you to review any updates to your state file. Unlike the refresh subcommand, -refresh-only mode is supported in workspaces using Terraform Cloud as a remote backend, allowing your team to collaboratively review any modifications.

Then perhaps the workaround i included above is the best way forward.

@nitrocode
Copy link
Member Author

The downside of not implementing atlantis refresh is that you would need to get an approval first for the plan with all the junk before you could complete the lifecycle of a refresh only plan in order to create a new plan without the junk to make it easier to review....

This is the issue with the current workaround.

The ideal method would be that you could run atlantis refresh and it would either run terraform refresh && terraform plan or terraform plan -refresh-only && terraform apply && terraform plan (without merging the branch). Whether the former or latter is used, it's just an implementation detail.

@nitrocode nitrocode changed the title Support terraform refresh subcommand Support refresh subcommand Jan 8, 2023
@nitrocode nitrocode changed the title Support refresh subcommand Support atlantis refresh subcommand Jan 8, 2023
@dosubot dosubot bot added the Stale label Sep 26, 2024
@shblue21
Copy link

shblue21 commented Sep 27, 2024

Yes, refresh is a feature that TFC also supports, it just changes the way the command is executed.

  • before: terraform refresh
  • changed: terraform apply -refresh-only

Either way, it would be nice to be able to sync the tfstate file in atlantis.
This is an outdated issue, but it would be nice to see it added.

@nitrocode
Copy link
Member Author

Another option is to have atlantis detect the refresh, split it into 2 separate sections, and print. This ways it's obvious to the user what is going to change resources and what is going to refresh the state.

It's not an outdated issue. It's a still relevant issue that happens to be old. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality/enhancement Stale
Projects
None yet
Development

No branches or pull requests

3 participants