Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ jobs:
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
echo "project_name=${{ vars.PROJECT_NAME }}-pr-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
echo "TF_WORKSPACE=${{ vars.PROJECT_NAME }}-pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
echo "WS_NAME=${{ vars.PROJECT_NAME }}-pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
else
echo "PR_NUMBER=" >> $GITHUB_ENV
echo "project_name=${{ vars.PROJECT_NAME }}" >> $GITHUB_OUTPUT
echo "TF_WORKSPACE=${{ vars.PROJECT_NAME }}" >> $GITHUB_ENV
echo "WS_NAME=${{ vars.PROJECT_NAME }}" >> $GITHUB_ENV
fi

- name: Apply Terraform changes
Expand All @@ -80,6 +80,14 @@ jobs:
TF_VAR_branch_name: ${{ github.head_ref || github.ref_name }}
TF_TOKEN_app_terraform_io: ${{ secrets.TF_API_TOKEN }}
run: |
# Create workspace via API if it doesn't exist
curl --header "Authorization: Bearer ${{ secrets.TF_API_TOKEN }}" \
--header "Content-Type: application/vnd.api+json" \
--request POST \
--data "{\"data\":{\"attributes\":{\"name\":\"${{ env.WS_NAME }}\",\"execution-mode\":\"local\"},\"type\":\"workspaces\"}}" \
https://app.terraform.io/api/v2/organizations/kenf-hcp-org/workspaces || true

sed -i "s/RESUME_HOSTING_WORKSPACE_PLACEHOLDER/${{ env.WS_NAME }}/g" main.tf
terraform init
terraform apply --auto-approve
working-directory: ./terraform
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/destroy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
echo "TF_WORKSPACE=${{ vars.PROJECT_NAME }}-pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
echo "WS_NAME=${{ vars.PROJECT_NAME }}-pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
else
echo "PR_NUMBER=" >> $GITHUB_ENV
echo "TF_WORKSPACE=${{ vars.PROJECT_NAME }}" >> $GITHUB_ENV
echo "WS_NAME=${{ vars.PROJECT_NAME }}" >> $GITHUB_ENV
fi

- name: Destroy Terraform changes
Expand All @@ -37,6 +37,14 @@ jobs:
TF_VAR_pr_number: ${{ env.PR_NUMBER }}
TF_TOKEN_app_terraform_io: ${{ secrets.TF_API_TOKEN }}
run: |
# Create workspace via API if it doesn't exist (safety)
curl --header "Authorization: Bearer ${{ secrets.TF_API_TOKEN }}" \
--header "Content-Type: application/vnd.api+json" \
--request POST \
--data "{\"data\":{\"attributes\":{\"name\":\"${{ env.WS_NAME }}\",\"execution-mode\":\"local\"},\"type\":\"workspaces\"}}" \
https://app.terraform.io/api/v2/organizations/kenf-hcp-org/workspaces || true

sed -i "s/RESUME_HOSTING_WORKSPACE_PLACEHOLDER/${{ env.WS_NAME }}/g" main.tf
terraform init
terraform destroy --auto-approve
working-directory: ./terraform
2 changes: 1 addition & 1 deletion terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
organization = "kenf-hcp-org"

workspaces {
name = "resume-hosting"
name = "RESUME_HOSTING_WORKSPACE_PLACEHOLDER"
}
}

Expand Down