Let's say that there is a modification in the infrastructure, and you make a change to the resource file to match. When you run a terraform plan will it show that the change needs to be made or not?
I've done this test and it seems to not show a change being made, but wouldn't it need to go and grab that change from the architecture and place that change into state?
The example I'm thinking of is a modification of a tag on some AWS resource.
As a follow up question, what happens if the manual change to the AWS tag occurs after you've run plan but BEFORE you run apply?
By default, the planning operation visits each resource instance declared in the configuration or pre-existing in the state snapshot that was current when the plan started, and:
resourceblock to produce an object representing the resource instance's current configuration.If you specify the planning option
-refresh=falsethen that effectively disables step 2: the prior state is just whatever was recorded in the state snapshot that was current at the start of the plan, regardless of what might have changed in the remote system.If you specify the planning option
-refresh-onlythen that effectively disables step 3: Terraform pretends that no changes are required and so applying the plan would just save the "prior state" (the result of refreshing) as the current state in the newly-created state snapshot.Exactly what it means to "refresh" or "plan" a particular resource type is decided by the provider that resource type belongs to. For example, sometimes a remote API treats something as write-only and so the provider might respond to that by just assuming that the value from the previous state snapshot is still valid. However, in most cases a provider will detect changes made outside of Terraform and report them in step 2, causing them to be taken into account during step 3.
The other wrinkle is that Terraform will only ever refresh a resource instance that already exists in the input state snapshot. If something new was created outside of Terraform, the provider is unlikely to detect it unless it appears as a nested part of some other object that was previously created with this Terraform configuration, or explicitly imported into its state.