From ec0e2df47fd17c5880d44af90ca76dd747f0a87e Mon Sep 17 00:00:00 2001 From: Bharat Middha <5100938+bmiddha@users.noreply.github.com> Date: Mon, 13 Nov 2023 11:59:23 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20use=20new=20typesense=20deployme?= =?UTF-8?q?nt=20(#846)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Typesense service is now deployed via the k8s stack. https://github.com/acm-uic/IaC/blob/4ad36212235e6ad8ab979e41f249fbb9c8da6b35/kubernetes/argocd/stacks/typesense/typesense.yml This change updates the website to use the new deployment ## Issues closes #766 closes #731 ## Checklist - [x] I've labeled the PR appropriately. - [x] I've have built the website and verified that my changes work. - [x] I've linked the appropriate issues and related PRs. --- .env.example | 2 - .github/dependabot.yml | 14 -- .github/labeler.yml | 2 - .github/labels.yml | 4 - .github/workflows/ci.yml | 171 +----------------- .github/workflows/drift.yml | 42 ----- .gitignore | 3 +- .vscode/extensions.json | 3 +- .vscode/settings.json | 5 +- ...raper-config.json => docsearch.config.json | 0 docusaurus.config.js | 10 +- tf/.gitignore | 40 ---- tf/.terraform.lock.hcl | 44 ----- tf/main.tf | 29 --- tf/outputs.tf | 7 - tf/typesense.tf | 152 ---------------- tf/variables.tf | 16 -- 17 files changed, 14 insertions(+), 530 deletions(-) delete mode 100644 .env.example delete mode 100644 .github/workflows/drift.yml rename .github/workflows/typesense-scraper-config.json => docsearch.config.json (100%) delete mode 100644 tf/.gitignore delete mode 100644 tf/.terraform.lock.hcl delete mode 100644 tf/main.tf delete mode 100644 tf/outputs.tf delete mode 100644 tf/typesense.tf delete mode 100644 tf/variables.tf diff --git a/.env.example b/.env.example deleted file mode 100644 index 7cb99c747..000000000 --- a/.env.example +++ /dev/null @@ -1,2 +0,0 @@ -TYPESENSE_HOST="" -TYPESENSE_SEARCH_ONLY_API_KEY="" diff --git a/.github/dependabot.yml b/.github/dependabot.yml index c30f5884b..38aa935a7 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,19 +1,5 @@ version: 2 updates: - - package-ecosystem: "terraform" - directory: "/tf" - schedule: - interval: "weekly" - day: "saturday" - time: "07:00" - timezone: "America/Chicago" - labels: - - ":package: dependencies" - - ":robot: bot" - - ":building_construction: terraform" - commit-message: - prefix: ":arrow_up:" - - package-ecosystem: "github-actions" directory: "/" schedule: diff --git a/.github/labeler.yml b/.github/labeler.yml index 3d629241e..9b6734a99 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -10,5 +10,3 @@ - ./*.json ":construction: actions": - .github/workflows/**/* -":building_construction: terraform": - - tf/**/* diff --git a/.github/labels.yml b/.github/labels.yml index 3d1d5bfd0..057a6e505 100644 --- a/.github/labels.yml +++ b/.github/labels.yml @@ -1,7 +1,3 @@ -- # terraform - name: ":building_construction: terraform" - color: "7b42bc" - description: "" - # actions name: ":construction: actions" color: "8f4fbc" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b03da973c..5fb36c122 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,6 @@ on: permissions: contents: write pages: write - id-token: write pull-requests: write jobs: @@ -18,7 +17,6 @@ jobs: if: github.event_name == 'pull_request' && github.event.action != 'closed' runs-on: ubuntu-latest name: Build PR and Deploy 🚀 - needs: terraform_plan steps: - name: Checkout repo 🛎️ @@ -37,9 +35,6 @@ jobs: yarn install - name: Build ⚙️ - env: - TYPESENSE_HOST: ${{ needs.terraform_plan.outputs.typesense_container_app_fqdn }} - TYPESENSE_SEARCH_ONLY_API_KEY: ${{ needs.terraform_plan.outputs.typesense_search_only_api_key }} run: | yarn build @@ -75,7 +70,6 @@ jobs: if: github.event_name == 'push' && github.ref == 'refs/heads/main' runs-on: ubuntu-latest name: Build and Push GitHub Pages Site 🚀 - needs: terraform_apply concurrency: group: build_release_gh_pages cancel-in-progress: true @@ -106,9 +100,6 @@ jobs: yarn prettier:ci - name: Build ⚙️ - env: - TYPESENSE_HOST: ${{ needs.terraform_apply.outputs.typesense_container_app_fqdn }} - TYPESENSE_SEARCH_ONLY_API_KEY: ${{ needs.terraform_apply.outputs.typesense_search_only_api_key }} run: | yarn build @@ -124,166 +115,18 @@ jobs: update_search_db: runs-on: ubuntu-latest name: Update search DB 🔍 - needs: [terraform_apply, build_release_gh_pages] - steps: - - name: Checkout repo 🛎️ - uses: actions/checkout@v4 - with: - submodules: recursive - - - name: Run DocSearch Scraper 🔍 - run: | - docker run \ - --env TYPESENSE_API_KEY="${{ secrets.TYPESENSE_API_KEY }}" \ - --env TYPESENSE_HOST="${{ needs.terraform_apply.outputs.typesense_container_app_fqdn }}" \ - --env TYPESENSE_PORT="443" \ - --env TYPESENSE_PROTOCOL="https" \ - --env CONFIG="$(cat ./.github/workflows/typesense-scraper-config.json | jq -r tostring)" \ - typesense/docsearch-scraper:0.7.0 - - terraform_plan: - runs-on: ubuntu-latest - name: Terraform Plan 🤖📖 - if: github.event_name == 'pull_request' && github.event.action != 'closed' - concurrency: - group: terraform - cancel-in-progress: false - outputs: - typesense_search_only_api_key: ${{ steps.tf-outputs.outputs.typesense_search_only_api_key }} - typesense_container_app_fqdn: ${{ steps.tf-outputs.outputs.typesense_container_app_fqdn }} - env: - ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - ARM_TENANT_ID: ${{ secrets.AZURE_AD_TENANT_ID }} - ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - ARM_USE_OIDC: true - TF_WORKSPACE: prod - TF_IN_AUTOMATION: true - TF_INPUT: 0 - - steps: - - name: Checkout repo 🛎️ - uses: actions/checkout@v4 - with: - submodules: recursive - - - name: Azure CLI setup ⚙️ - uses: azure/login@v1 - with: - client-id: ${{ env.ARM_CLIENT_ID }} - tenant-id: ${{ env.ARM_TENANT_ID }} - subscription-id: ${{ env.ARM_SUBSCRIPTION_ID }} - - - name: Terraform Format 💄 - id: fmt - uses: dflook/terraform-fmt-check@v1 - with: - path: tf - workspace: ${{ env.TF_WORKSPACE }} - - - name: Terraform Validate 👀 - id: validate - uses: dflook/terraform-validate@v1 - with: - path: tf - workspace: ${{ env.TF_WORKSPACE }} - - - name: Get Typesense collection name ⚙️ - id: get_typesense_collection_name - run: | - typesense_collection_name=$(jq -r '.index_name' .github/workflows/typesense-scraper-config.json) - echo "typesense_collection_name=$typesense_collection_name" >> "$GITHUB_OUTPUT" - - - name: Terraform Plan 📖 - id: plan - uses: dflook/terraform-plan@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - path: tf - workspace: ${{ env.TF_WORKSPACE }} - variables: | - typesense_api_key="${{ secrets.TYPESENSE_API_KEY }}" - typesense_rg="${{ secrets.TYPESENSE_RESOURCE_GROUP_NAME }}" - typesense_collection_name="${{ steps.get_typesense_collection_name.outputs.typesense_collection_name }}" - - - name: Get outputs ⚙️ - uses: dflook/terraform-output@v1 - id: tf-outputs - with: - path: tf - workspace: ${{ env.TF_WORKSPACE }} - - terraform_apply: - runs-on: ubuntu-latest - name: Terraform Apply 🤖🚀 - environment: azure-container-app - concurrency: - group: terraform - cancel-in-progress: false - env: - ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - ARM_TENANT_ID: ${{ secrets.AZURE_AD_TENANT_ID }} - ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} - ARM_USE_OIDC: true - TF_WORKSPACE: prod - TF_IN_AUTOMATION: true - TF_INPUT: 0 if: github.ref == 'refs/heads/main' && github.event_name == 'push' - outputs: - typesense_search_only_api_key: ${{ steps.tf-outputs.outputs.typesense_search_only_api_key }} - typesense_container_app_fqdn: ${{ steps.tf-outputs.outputs.typesense_container_app_fqdn }} - steps: - name: Checkout repo 🛎️ uses: actions/checkout@v4 with: submodules: recursive - - name: Azure CLI setup ⚙️ - uses: azure/login@v1 - with: - client-id: ${{ env.ARM_CLIENT_ID }} - tenant-id: ${{ env.ARM_TENANT_ID }} - subscription-id: ${{ env.ARM_SUBSCRIPTION_ID }} - - - name: Terraform Format 💄 - id: fmt - uses: dflook/terraform-fmt-check@v1 - with: - path: tf - workspace: ${{ env.TF_WORKSPACE }} - - - name: Terraform Validate 👀 - id: validate - uses: dflook/terraform-validate@v1 - with: - path: tf - workspace: ${{ env.TF_WORKSPACE }} - - - name: Get Typesense collection name ⚙️ - id: get_typesense_collection_name - run: | - typesense_collection_name=$(jq -r '.index_name' .github/workflows/typesense-scraper-config.json) - echo "typesense_collection_name=$typesense_collection_name" >> "$GITHUB_OUTPUT" - - - name: Terraform Apply 🚀 - id: apply - uses: dflook/terraform-apply@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - path: tf - workspace: ${{ env.TF_WORKSPACE }} - variables: | - typesense_api_key="${{ secrets.TYPESENSE_API_KEY }}" - typesense_rg="${{ secrets.TYPESENSE_RESOURCE_GROUP_NAME }}" - typesense_collection_name="${{ steps.get_typesense_collection_name.outputs.typesense_collection_name }}" - - - name: Get outputs ⚙️ - uses: dflook/terraform-output@v1 - id: tf-outputs + - name: Run DocSearch Scraper 🔍 + uses: celsiusnarhwal/typesense-scraper@v2 with: - path: tf - workspace: ${{ env.TF_WORKSPACE }} - + api-key: ${{ secrets.TYPESENSE_API_KEY }} + host: typesense.acmuic.org + port: 443 + protocol: https + config: docsearch.config.json diff --git a/.github/workflows/drift.yml b/.github/workflows/drift.yml deleted file mode 100644 index 8d2cd810b..000000000 --- a/.github/workflows/drift.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: terraform drift - -on: -# schedule: -# - cron: "0 8 * * *" - workflow_dispatch: - -permissions: - contents: read - id-token: write - -jobs: - terraform_drift: - runs-on: ubuntu-latest - name: Terraform Drift 🤖🔁 - env: - ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - ARM_TENANT_ID: ${{ secrets.AZURE_AD_TENANT_ID }} - ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - ARM_USE_OIDC: true - TF_WORKSPACE: prod - TF_IN_AUTOMATION: true - TF_INPUT: 0 - steps: - - name: Checkout repo 🛎️ - uses: actions/checkout@v4 - with: - submodules: recursive - - - name: Azure CLI setup ⚙️ - uses: azure/login@v1 - with: - client-id: ${{ env.ARM_CLIENT_ID }} - tenant-id: ${{ env.ARM_TENANT_ID }} - subscription-id: ${{ env.ARM_SUBSCRIPTION_ID }} - - - name: Check for drift 🤖🔁 - uses: dflook/terraform-check@v1 - with: - path: tf - workspace: ${{ env.TF_WORKSPACE }} diff --git a/.gitignore b/.gitignore index c027df741..c459d16a1 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,5 @@ npm-debug.log* yarn-debug.log* yarn-error.log* -/.tmp \ No newline at end of file +/.tmp +.env \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 10e4d81f7..7917fd299 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -4,7 +4,6 @@ "esbenp.prettier-vscode", "DavidAnson.vscode-markdownlint", "stylelint.vscode-stylelint", - "unifiedjs.vscode-mdx", - "hashicorp.terraform" + "unifiedjs.vscode-mdx" ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index c882e043a..30e165636 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -25,8 +25,5 @@ "svgr", "typecheck", "typesense" - ], - "[terraform]": { - "editor.defaultFormatter": "hashicorp.terraform" - } + ] } diff --git a/.github/workflows/typesense-scraper-config.json b/docsearch.config.json similarity index 100% rename from .github/workflows/typesense-scraper-config.json rename to docsearch.config.json diff --git a/docusaurus.config.js b/docusaurus.config.js index 25e5e26a8..0f4611fde 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -1,22 +1,18 @@ // @ts-check -/* eslint-disable @typescript-eslint/no-var-requires */ -require("dotenv").config(); - /* eslint-disable @typescript-eslint/no-var-requires */ const { config: { discordServerId, discordServerInviteLink, slackWorkspaceSignUpLink, youTubeChannelLink }, } = require("./appConfig"); -const { index_name: typesenseCollectionName } = require("./.github/workflows/typesense-scraper-config.json"); - const gitHubOrg = "acm-uic"; const gitHubRepoName = "acm-uic.github.io"; const gitHubOrgUrl = `https://github.com/${gitHubOrg}`; const gitHubRepoUrl = `${gitHubOrgUrl}/${gitHubRepoName}`; const gitHubRepoDefaultBranch = "main"; const gitHubPagesUrl = `https://${gitHubRepoName}`; -const typesenseHost = process.env.TYPESENSE_HOST ?? "localhost"; -const typesenseKey = process.env.TYPESENSE_SEARCH_ONLY_API_KEY ?? "test_key"; +const typesenseHost = "typesense.acmuic.org"; +const typesenseKey = "QRerr6QNQ96HpqBaof6yPinG7fnq11bs"; // key with search-only permissions +const typesenseCollectionName = "docusaurus-2"; /** * diff --git a/tf/.gitignore b/tf/.gitignore deleted file mode 100644 index f5311ae23..000000000 --- a/tf/.gitignore +++ /dev/null @@ -1,40 +0,0 @@ -# Created by https://www.toptal.com/developers/gitignore/api/terraform -# Edit at https://www.toptal.com/developers/gitignore?templates=terraform - -### Terraform ### -# Local .terraform directories -**/.terraform/* - -# .tfstate files -*.tfstate -*.tfstate.* - -# Crash log files -crash.log -crash.*.log - -# Exclude all .tfvars files, which are likely to contain sensitive data, such as -# password, private keys, and other secrets. These should not be part of version -# control as they are data points which are potentially sensitive and subject -# to change depending on the environment. -*.tfvars -*.tfvars.json - -# Ignore override files as they are usually used to override resources locally and so -# are not checked in -override.tf -override.tf.json -*_override.tf -*_override.tf.json - -# Include override files you do wish to add to version control using negated pattern -# !example_override.tf - -# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan -# example: *tfplan* - -# Ignore CLI configuration files -.terraformrc -terraform.rc - -# End of https://www.toptal.com/developers/gitignore/api/terraform \ No newline at end of file diff --git a/tf/.terraform.lock.hcl b/tf/.terraform.lock.hcl deleted file mode 100644 index c45e96fa6..000000000 --- a/tf/.terraform.lock.hcl +++ /dev/null @@ -1,44 +0,0 @@ -# This file is maintained automatically by "terraform init". -# Manual edits may be lost in future updates. - -provider "registry.terraform.io/hashicorp/azurerm" { - version = "3.64.0" - constraints = "3.64.0" - hashes = [ - "h1:g2p1LQQy+Ih6gWzMQTmlb6v5s9iXP3EusXIwd63APg0=", - "zh:08463ceca4208419715b5816d120fe05f2abda9bea083cfe1818e25517483581", - "zh:130760c5ab791bd114b3edbb79b95138a60cd97f1b72e4096b33a207b367d126", - "zh:26403fc9be70b60fddf09b1510067763b2da57cf3b116d375b5bee048acad8d2", - "zh:352c79bb75c1a0d88a686c4e22fded1114de0249aba081e34265d4b11c878fc7", - "zh:52ee37390b70e89add8b70b43c05bc90037a723a726c63440943f9bf2f064817", - "zh:79ad0c72e2b15b9412f1fdb5461dfcec6ca192ab4512e70fcbcea4585c02d71e", - "zh:7a60226f41064a95db14e64dc0250063a621df254ee41e4b3b25ccc5ce47936d", - "zh:9191136871cf2ffa4f1963a6b79d6868f911f827330234421af869df616bacd0", - "zh:a32cb5eb225ccea6d3d5e70f948dfc4b4ed442cd20ceb80ce014a3df05ab93e8", - "zh:de16cb2726016e0eb9a04599fdb81b503a96263b1805243b75b202c559051a5e", - "zh:ee636ddb5281772071f9952f75b2c7ad7f443f25c84c96e6e78d628a151ec4ac", - "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", - ] -} - -provider "registry.terraform.io/scottwinkler/shell" { - version = "1.7.10" - constraints = "1.7.10" - hashes = [ - "h1:yPUe5wSWvyz0d56XUdyoP+TqVj2xP/ruTzfk0yWXJws=", - "zh:0017ae6dcdcf320df10dd0a24f22dd7f1bd92cc62c2550f5696888d7bb042d81", - "zh:00574d8102685054080ad68db5ee99f1ee02c07709d3f77324be2d134eddf0d4", - "zh:0a9b84dccbfe0e704a81c1e76f75c95efdc4bf03c6a1a210b1b386dfd1593209", - "zh:2426358421619cb9125f2145f567908a904fd2a51e86c0afdf92082ea0532e9d", - "zh:425794426f7bb78921b3329c82f6373d5a5f072f28cc7296fdb21e13c595c0e8", - "zh:64d1a85a356ab75e84f12cbab41c548e069609098279eb5360c295b06a6f2994", - "zh:71612774c04cdeae2520a0ea19f938c17b9f6600eaa0356905f40d35caca1e81", - "zh:8d841d44c929bc4882d05c59ddd1bb1b91174c96139500ba29daacf74cf91406", - "zh:97ed1034b0962be59d2e03221031cb49f2ac9e992392bab3b08cbce9fa15e244", - "zh:9daebe55771a8e5b7b21c59cd53d86af9a1435e903ca60de119ccb3bc73a87b8", - "zh:a2d477ed687592a392439c7f96e378c9aa356151f7b2b44dcebc9aae956018e0", - "zh:c0f7e2656593ac97db96d82da41d8a3bd6584406f6d944b02d14ab132b3043ad", - "zh:cc24f9cd5ba535fbdb1bcabea69c5f150b43004ed180a3d14d740700d0d1a4b7", - "zh:cd7283a1a9fb857eb0c2e436ad9859b557127b594a1c7f818c1cb7a20df1c724", - ] -} diff --git a/tf/main.tf b/tf/main.tf deleted file mode 100644 index 25f23a027..000000000 --- a/tf/main.tf +++ /dev/null @@ -1,29 +0,0 @@ -terraform { - required_version = "1.4.6" - backend "azurerm" { - resource_group_name = "acm-hybridcloud" - storage_account_name = "acmhybridstore" - container_name = "acm-terraform-state" - key = "typesense.tfstate" - snapshot = true - } - required_providers { - shell = { - source = "scottwinkler/shell" - version = "1.7.10" - } - azurerm = { - source = "hashicorp/azurerm" - version = "3.64.0" - } - } -} - -provider "azurerm" { - features {} -} - -provider "shell" { - interpreter = ["/bin/bash", "-c"] - enable_parallelism = false -} diff --git a/tf/outputs.tf b/tf/outputs.tf deleted file mode 100644 index 60e5a6350..000000000 --- a/tf/outputs.tf +++ /dev/null @@ -1,7 +0,0 @@ -output "typesense_container_app_fqdn" { - value = azurerm_container_app.typesense_container_app.ingress[0].fqdn -} - -output "typesense_search_only_api_key" { - value = shell_script.typesense_search_only_api_key.output["value"] -} diff --git a/tf/typesense.tf b/tf/typesense.tf deleted file mode 100644 index 7c6e50194..000000000 --- a/tf/typesense.tf +++ /dev/null @@ -1,152 +0,0 @@ -locals { - gh_repo = "acm-uic/acm-uic.github.io" -} - -data "azurerm_resource_group" "typesense_resource_group" { - name = var.typesense_rg -} - -resource "azurerm_container_app" "typesense_container_app" { - name = "typesense-container-app" - container_app_environment_id = azurerm_container_app_environment.typesense_container_app_env.id - resource_group_name = data.azurerm_resource_group.typesense_resource_group.name - revision_mode = "Single" - ingress { - allow_insecure_connections = false - external_enabled = true - target_port = 8108 - transport = "auto" - traffic_weight { - percentage = 100 - latest_revision = true - } - } - secret { - name = "api-key" - value = var.typesense_api_key - } - template { - max_replicas = 1 - min_replicas = 1 - revision_suffix = "one" - container { - args = [] - command = [] - cpu = 1 - image = "docker.io/typesense/typesense:0.24.0" - memory = "2Gi" - name = "typesense-acm-website" - env { - name = "TYPESENSE_DATA_DIR" - value = "/data" - } - env { - name = "TYPESENSE_API_KEY" - secret_name = "api-key" - } - liveness_probe { - initial_delay = 10 - interval_seconds = 10 - path = "/health" - port = 8108 - transport = "HTTP" - } - readiness_probe { - interval_seconds = 10 - path = "/health" - port = 8108 - transport = "HTTP" - } - volume_mounts { - name = "typesense-volume" - path = "/data" - } - } - volume { - name = "typesense-volume" - storage_name = azurerm_container_app_environment_storage.typesense_container_app_env_storage.name - storage_type = "AzureFile" - } - } -} - -resource "azurerm_container_app_environment" "typesense_container_app_env" { - name = "typesense-container-app-env" - location = data.azurerm_resource_group.typesense_resource_group.location - resource_group_name = data.azurerm_resource_group.typesense_resource_group.name - log_analytics_workspace_id = azurerm_log_analytics_workspace.typesense_log_workspace.id -} - -resource "azurerm_container_app_environment_storage" "typesense_container_app_env_storage" { - name = "typesense-container-app-storage" - access_mode = "ReadWrite" - container_app_environment_id = azurerm_container_app_environment.typesense_container_app_env.id - account_name = azurerm_storage_account.typesense_storage_account.name - share_name = azurerm_storage_share.typesense_storage_share.name - access_key = azurerm_storage_account.typesense_storage_account.primary_access_key -} - -resource "azurerm_storage_account" "typesense_storage_account" { - name = "typesensestorage" - account_kind = "FileStorage" - account_replication_type = "LRS" - account_tier = "Premium" - location = data.azurerm_resource_group.typesense_resource_group.location - resource_group_name = data.azurerm_resource_group.typesense_resource_group.name -} - -resource "azurerm_storage_share" "typesense_storage_share" { - name = "typesense-share" - quota = 100 - storage_account_name = azurerm_storage_account.typesense_storage_account.name -} - -resource "azurerm_log_analytics_workspace" "typesense_log_workspace" { - name = "typesense-logs" - sku = "PerGB2018" - retention_in_days = 30 - location = data.azurerm_resource_group.typesense_resource_group.location - resource_group_name = data.azurerm_resource_group.typesense_resource_group.name -} - -resource "shell_script" "typesense_search_only_api_key" { - triggers = { - when_value_changed = azurerm_container_app.typesense_container_app.latest_revision_fqdn - when_value_changed = azurerm_container_app.typesense_container_app.id - when_value_changed = var.typesense_api_key - } - environment = { - TYPESENSE_HOST = azurerm_container_app.typesense_container_app.latest_revision_fqdn - COLLECTION_NAME = var.typesense_collection_name - } - depends_on = [ - azurerm_container_app.typesense_container_app - ] - sensitive_environment = { - TYPESENSE_API_KEY = var.typesense_api_key - } - lifecycle { - replace_triggered_by = [ - azurerm_container_app.typesense_container_app - ] - } - lifecycle_commands { - create = <<-EOF - until curl --silent "https://$TYPESENSE_HOST/health" | grep -q '"ok":true'; do sleep 5; done; - curl --silent "https://$TYPESENSE_HOST/keys" \ - -X POST \ - -H "X-TYPESENSE-API-KEY: $TYPESENSE_API_KEY" \ - -H 'Content-Type: application/json' \ - -d "{\"description\":\"search-only-api-key-$COLLECTION_NAME\",\"actions\": [\"documents:search\"], \"collections\": [\"$COLLECTION_NAME\"]}" \ - | jq '{id, value}' - EOF - delete = <<-EOF - IN=$(cat) - ID=$(echo $IN | jq -r .id) - until curl --silent "https://$TYPESENSE_HOST/health" | grep -q '"ok":true'; do sleep 5; done; - curl --silent "https://$TYPESENSE_HOST/keys/$ID" \ - -X DELETE \ - -H "X-TYPESENSE-API-KEY: $TYPESENSE_API_KEY" - EOF - } -} diff --git a/tf/variables.tf b/tf/variables.tf deleted file mode 100644 index 3b454b520..000000000 --- a/tf/variables.tf +++ /dev/null @@ -1,16 +0,0 @@ -variable "typesense_api_key" { - description = "Typesense API key" - type = string - sensitive = true -} - -variable "typesense_collection_name" { - description = "Typesense collection name" - type = string - sensitive = true -} - -variable "typesense_rg" { - description = "Azure resource group" - type = string -}