I was trying to do something similar and came across this post. Worked out a solution in the end so thought I should share for anyone else coming across this post.
variable "maintenance" { description = "Set to active, disabled or previous (Default)" type = string default = "previous"}# This is used so we can lookup the previous value of the maintenance setting in the state filedata "terraform_remote_state" "bc" { backend = "gcs" config = { bucket = "terraform-bucket" prefix = "terraform/state" } workspace = terraform.workspace # Set a default value in case of an empty state file defaults = { maintenance = "disabled" }}locals { maintenance_status = var.maintenance == "previous" ? data.terraform_remote_state.bc.outputs.maintenance : var.maintenance}# Used to expose the current value to subsequent tf runsoutput "maintenance" { value = example_resource.maintenance.status}
You can then change the setting using the command line, but if not specified it will use the previous valueterraform apply -var="maintenance=active"