diff --git a/lib/terraform/Taskfile.yml b/lib/terraform/Taskfile.yml index 9022688..3f59b00 100644 --- a/lib/terraform/Taskfile.yml +++ b/lib/terraform/Taskfile.yml @@ -74,3 +74,20 @@ tasks: msg: "Variables file does not exist: {{.TFVARS_FILE}}" cmds: - terraform apply -var-file {{.TFVARS_FILE}} {{.TF_ARGS}} + + refresh: + desc: Refresh the Terraform state to match the real-world infrastructure (safer via apply -refresh-only). + summary: | + Refreshes the Terraform state for a specified environment, using a file to load the variables. + Note: Upstream deprecates `terraform refresh`; use `terraform apply -refresh-only` to review changes before writing state. + Requires a variables file specific to the environment to be present. + Usage: task terraform:refresh -- ENVIRONMENT [terraform apply -refresh-only arguments] + Example: task terraform:refresh -- automation + dir: "{{.USER_WORKING_DIR}}" + silent: true + vars: *vars + preconditions: + - sh: test -f {{.TFVARS_FILE}} + msg: "Variables file does not exist: {{.TFVARS_FILE}}" + cmds: + - terraform apply -refresh-only -var-file {{.TFVARS_FILE}} {{.TF_ARGS}}