OPENSHIFT_4_VSPHERE_GITHUB_USER ?= $(GITHUB_USER)
OPENSHIFT_4_VSPHERE_GITHUB_TOKEN ?= $(GITHUB_TOKEN)
OPENSHIFT_4_VSPHERE_GIT_TF_DEPLOY_PROJECT ?= "https://$(OPENSHIFT_4_VSPHERE_GITHUB_USER):$(OPENSHIFT_4_VSPHERE_GITHUB_TOKEN)@github.com/open-cluster-management/tf_openshift_4.git"
OPENSHIFT_4_VSPHERE_GIT_TF_DEPLOY_BRANCH ?= master
OPENSHIFT_4_VSPHERE_DEPLOY_DIR ?= .deploy-openshift4-vsphere/
OPENSHIFT_4_VSPHERE_TERRAFORM_VARS_FILE ?= .deploy-openshift4-vsphere.tfvars
OPENSHIFT_4_VSPHERE_TERRAFORM_VERSION ?= 0.12.18

.PHONY: deploy/openshift4/vsphere
## Deploy openshift on vSphere
deploy/openshift4/vsphere:
	@$(GIT) clone -b $(OPENSHIFT_4_VSPHERE_GIT_TF_DEPLOY_BRANCH) $(OPENSHIFT_4_VSPHERE_GIT_TF_DEPLOY_PROJECT) $(OPENSHIFT_4_VSPHERE_DEPLOY_DIR)
	@$(SELF) terraform:apply TERRAFORM_VARS_FILE=$(OPENSHIFT_4_VSPHERE_TERRAFORM_VARS_FILE) TERRAFORM_DIR=$(OPENSHIFT_4_VSPHERE_DEPLOY_DIR)/vsphere-upi TERRAFORM_VER=$(OPENSHIFT_4_VSPHERE_TERRAFORM_VERSION)
	@echo "bootstrap_complete = true" >> $(OPENSHIFT_4_VSPHERE_TERRAFORM_VARS_FILE)
	@$(SELF) terraform:apply TERRAFORM_VARS_FILE=$(OPENSHIFT_4_VSPHERE_TERRAFORM_VARS_FILE) TERRAFORM_DIR=$(OPENSHIFT_4_VSPHERE_DEPLOY_DIR)/vsphere-upi TERRAFORM_VER=$(OPENSHIFT_4_VSPHERE_TERRAFORM_VERSION)
	@sed -i "s/bootstrap_complete = true//g" $(OPENSHIFT_4_VSPHERE_TERRAFORM_VARS_FILE)

.PHONY: deploy/openshift4/vsphere/destroy
## Destroy openshift on vSphere deployment resources
deploy/openshift4/vsphere/destroy: %destroy:
	@$(SELF) terraform:destroy TERRAFORM_VARS_FILE=$(OPENSHIFT_4_VSPHERE_TERRAFORM_VARS_FILE) TERRAFORM_DIR=$(OPENSHIFT_4_VSPHERE_DEPLOY_DIR)/vsphere-upi TERRAFORM_VER=$(OPENSHIFT_4_VSPHERE_TERRAFORM_VERSION)

.PHONY: deploy/openshift4/vsphere/clean
## Clean up all openshift on vSphere deployment resources
deploy/openshift4/vsphere/clean: %clean: %destroy
ifeq ($(shell test -d $(OPENSHIFT_4_VSPHERE_DEPLOY_DIR) && echo -n yes),yes)
	@rm -rf $(OPENSHIFT_4_VSPHERE_DEPLOY_DIR)
endif
