@@ -131,7 +131,7 @@ jobs:
131131 TF_VAR_RESOURCE_PROFILE : ${{ inputs.resource_profile || 'prod' }}
132132
133133 steps :
134- - name : debug inputs
134+ - name : Debug inputs
135135 run : |
136136 echo "cluster: ${{ inputs.cluster }}"
137137 echo "namespace: ${{ inputs.namespace }}"
@@ -143,111 +143,31 @@ jobs:
143143 echo "create_static_ips: ${{ inputs.create_static_ips }}"
144144 echo "run_terraform_destroy: ${{ inputs.run_terraform_destroy }}"
145145
146- - name : Check if directory exists
147- id : check_dir
148- run : |
149- if [ -d ".git" ]; then
150- echo "exists=true" >> $GITHUB_OUTPUT
151- else
152- echo "exists=false" >> $GITHUB_OUTPUT
153- fi
154-
155- # if running with `act`, skip the checkout since the code is mounted in
156- - name : Checkout code
157- if : ${{ steps.check_dir.outputs.exists != 'true' }}
158- uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
146+ - name : Setup K8s and Terraform
147+ uses : ./.github/actions/setup-k8s-terraform
159148 with :
149+ cluster : ${{ inputs.cluster }}
150+ namespace : ${{ inputs.namespace }}
160151 ref : ${{ inputs.ref || github.ref }}
152+ gcp_sa_key : ${{ secrets.GCP_SA_KEY }}
153+ kubeconfig_b64 : ${{ secrets.KUBECONFIG_B64 }}
154+ terraform_dir : ./spartan/terraform/deploy-eth-devnet
155+ tf_state_prefix : deploy-eth-devnet
156+ run_terraform_destroy : ${{ inputs.run_terraform_destroy }}
161157
162- - name : Authenticate to Google Cloud
163- uses : google-github-actions/auth@6fc4af4b145ae7821d527454aa9bd537d1f2dc5f
164- with :
165- credentials_json : ${{ secrets.GCP_SA_KEY }}
166-
167- - name : Set up Cloud SDK
168- uses : google-github-actions/setup-gcloud@6189d56e4096ee891640bb02ac264be376592d6a
169-
170- - name : Install GKE Auth Plugin
171- run : |
172- gcloud components install gke-gcloud-auth-plugin --quiet
173-
174- - name : Configure kubectl with GKE cluster
175- if : ${{ inputs.cluster != 'kind' }}
176- run : |
177- gcloud container clusters get-credentials ${{ inputs.cluster }} --region ${{ env.REGION }}
178-
179- - name : Configure kubectl with kind cluster
180- if : ${{ inputs.cluster == 'kind' }}
181- run : |
182- # fail if kubeconfig is not provided
183- if [ -z "${{ secrets.KUBECONFIG_B64 }}" ]; then
184- echo "KUBECONFIG_B64 is not set"
185- exit 1
186- fi
187- mkdir -p $HOME/.kube
188- echo "${{ secrets.KUBECONFIG_B64 }}" | base64 -d > $HOME/.kube/config
189- kubectl config use-context kind-kind
190-
191- - name : Set up Terraform variables
192- id : setup_vars
158+ - name : Set up CREATE_STATIC_IPS variable
193159 run : |
194160 # Set CREATE_STATIC_IPS based on cluster type
195- # Note: Terraform boolean values must be "true" or "false" (lowercase, unquoted)
196161 if [ "${{ inputs.cluster }}" == "kind" ]; then
197162 CREATE_STATIC_IPS=false
198163 else
199- # Convert string "true"/"false" to boolean for Terraform
200164 if [ "${{ inputs.create_static_ips }}" == "true" ]; then
201165 CREATE_STATIC_IPS=true
202166 else
203167 CREATE_STATIC_IPS=false
204168 fi
205169 fi
206-
207- # Get kubectl context
208- CLUSTER_CONTEXT=$(kubectl config current-context)
209-
210- # Export all as TF_VAR for Terraform
211170 echo "TF_VAR_CREATE_STATIC_IPS=${CREATE_STATIC_IPS}" >> $GITHUB_ENV
212- echo "TF_VAR_K8S_CLUSTER_CONTEXT=${CLUSTER_CONTEXT}" >> $GITHUB_ENV
213-
214- - name : Terraform Init
215- working-directory : ./spartan/terraform/deploy-eth-devnet
216- run : |
217- # Clean up any previous backend overrides
218- rm -f backend_override.tf
219-
220- if [ "${{ inputs.cluster }}" == "kind" ]; then
221- # For kind, use local backend with explicit path
222- cat > backend_override.tf << EOF
223- terraform {
224- backend "local" {
225- path = "state/${{ inputs.cluster }}/${{ inputs.namespace }}/terraform.tfstate"
226- }
227- }
228- EOF
229- else
230- # For GKE, use GCS backend with explicit path
231- cat > backend_override.tf << EOF
232- terraform {
233- backend "gcs" {
234- bucket = "${{ env.TF_STATE_BUCKET }}"
235- prefix = "deploy-eth-devnet/${{ env.REGION }}/${{ inputs.cluster }}/${{ inputs.namespace }}/terraform.tfstate"
236- }
237- }
238- EOF
239- fi
240-
241- terraform init -reconfigure
242-
243- - name : Terraform Destroy
244- working-directory : ./spartan/terraform/deploy-eth-devnet
245- if : ${{ inputs.run_terraform_destroy == 'true' }}
246- # Destroy fails if the resources are already destroyed, so we continue on error
247- continue-on-error : true
248- run : |
249- # All variables are now set as TF_VAR_ environment variables
250- terraform destroy -auto-approve
251171
252172 - name : Terraform Plan
253173 working-directory : ./spartan/terraform/deploy-eth-devnet
0 commit comments