Skip to content

"terraform plan" should consider refresh updates as needing to be applied #15419

@apparentlymart

Description

@apparentlymart

With the addition of data sources in 0.7, it became possible that a terraform plan -out=tfplan could discover that data source changes are present -- possibly then causing output changes -- even if no resources need to be changed as a result.

Currently there is a hole in the workflow where it's tricky to apply such updates.

Along with the existing logic in the plan command that checks if the diff is non-empty, we should also check to see if the state changed during the refresh step. If any changes are present, we should produce a special sort of plan that includes no changes but includes the updated state:

$ terraform plan -out=tfplan
(usual output from the refresh step elided)

Infrastructure is up-to-date, but changes were detected to data sources or resources
during refresh.

These changes have not yet been recorded in the persistent state. To synchronize the
state with the changes to real-world resources, and update any output whose value
depends on these changes, run the "apply" command:
    terraform apply tfplan

This plan will make no changes to real resources.

It's interesting to note here that it feels a little weird to not spell out exactly which changes this will make, but yet it's completely consistent with the amount of information we give about updates when there are resource changes to apply. Along with this, we may wish to consider including changes to outputs in the diff in both cases, so that people with configurations that are consumed downstream by terraform_remote_state can feel more confident about the impact of their changes on those downstream consumers.

Changes to outputs:
      aws_vpc_id:    "vpc-12345" => "vpc-54321"
      aws_subnet_id: "subnet-12345" => <computed>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions