Any one tried this Plan to apply

E:g - let’s assume we are using AWS, i have to change my security group rule from port 80 to port 443,
I did terraform plan it said 1 item to change
but, in the meantime someone changes the port number from 80 to 443 manually
i do a change, what will happen, it will turn back to port 80, it will error, it will do nothing?
my understanding - since TF is a declarative language, terraform apply will notice the drift, and would understand 443 is already there, it will just update the state file and comes back

I sense that you intend this as just an example and that you’re looking for a general answer, rather than one focused just on security group rules.

The general answer to this is that there is no guarantee about what will happen: some underlying APIs offer mechanisms to perform conditional updates like this, where the corresponding provider might therefore be able to tell the remote system “update to 443 only if the previous value was 80”, where the remote system could then return an error if the previous value was not 80.

But many APIs offer no such feature, and so if the plan says that the new value will be 443 then the provider will just tell the remote API “update to 443”, and it will overwrite whatever value might be present at the time of that update.

This is true regardless of whether the value changed outside of Terraform matches the new desired state or if it is some other value. It’s always decided by the provider within the constraints of the API the provider is wrapping.

Given this, when using Terraform you should typically ensure that nothing else is trying to manage the same objects that Terraform is. Although Terraform and Terraform providers do make a best effort to detect and respond to unexpected changes, there is no way to reliably detect all possible changes to all APIs and so the only way to be sure is to give Terraform exclusive control over particular objects, and to ensure that only one Terraform configuration is in control of each object.

thank you for taking time and replying @apparentlymart