Created
November 5, 2021 12:55
-
-
Save Warns/054fa0d71e0a4dd4fb5540f4fc5ee9a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## tf/mv-state -- Moves a given resource from one root module to another via `terraform state mv`. | |
## Example: | |
## DEST_DIR=monitor \ | |
## DEST_WORKSPACE=dev \ | |
## SRC_DIR=k8s \ | |
## SRC_WORKSPACE=dev \ | |
## RESOURCE=module.datadog_monitors \ | |
## make tf/mv-state; | |
tf/mv-state: | |
cd ./components/terraform/$(DEST_DIR); \ | |
[[ "$(DEST_WORKSPACE)" != "default" ]] && terraform workspace select $(DEST_WORKSPACE); \ | |
terraform state pull > $(DEST_WORKSPACE)-`date +"%Y-%m-%d"`.tfstate; \ | |
cd ../$(SRC_DIR); \ | |
[[ "$(SRC_WORKSPACE)" != "default" ]] && terraform workspace select $(SRC_WORKSPACE); \ | |
terraform state mv -state-out=../$(DEST_DIR)/$(DEST_WORKSPACE)-`date +"%Y-%m-%d"`.tfstate $(RESOURCE) $(RESOURCE); \ | |
cd ../$(DEST_DIR); \ | |
terraform state push $(DEST_WORKSPACE)-`date +"%Y-%m-%d"`.tfstate; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment