Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stale] (Copilot Workspace) Implement Terraform #298

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
10 changes: 6 additions & 4 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Deploy
uses: cloudflare/wrangler-action@v3
- name: Trigger Terraform Workflow
uses: actions/github-script@v6
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
script: |
const { execSync } = require('child_process');
execSync('terraform init', { stdio: 'inherit' });
execSync('terraform apply -auto-approve', { stdio: 'inherit' });

- name: Create Sentry release
uses: getsentry/action-release@v1
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: "Terraform Deployment"

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
terraform:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.0.0

- name: Terraform Init
run: terraform init

- name: Terraform Apply
run: terraform apply -auto-approve

- name: Store Terraform State
run: |
mkdir -p $HOME/.terraform.d/plugin-cache
terraform init -backend-config="path=$HOME/.terraform.d/plugin-cache"
58 changes: 58 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
terraform {
required_providers {
cloudflare = {
source = "cloudflare/cloudflare"
version = "~> 3.0"
}
}
}

provider "cloudflare" {
api_token = var.cloudflare_api_token
}

resource "cloudflare_worker_script" "nceahelpworker" {
name = "nceahelpworker"
content = file("src/server.ts")
type = "javascript"
}

resource "cloudflare_kv_namespace" "token_store" {
title = "TOKEN_STORE"
}

resource "cloudflare_worker_secret" "discord_token" {
script = cloudflare_worker_script.nceahelpworker.name
name = "DISCORD_TOKEN"
value = var.discord_token
}

resource "cloudflare_worker_secret" "discord_public_key" {
script = cloudflare_worker_script.nceahelpworker.name
name = "DISCORD_PUBLIC_KEY"
value = var.discord_public_key
}

resource "cloudflare_worker_secret" "discord_application_id" {
script = cloudflare_worker_script.nceahelpworker.name
name = "DISCORD_APPLICATION_ID"
value = var.discord_application_id
}

resource "cloudflare_worker_secret" "discord_client_secret" {
script = cloudflare_worker_script.nceahelpworker.name
name = "DISCORD_CLIENT_SECRET"
value = var.discord_client_secret
}

resource "cloudflare_worker_secret" "worker_url" {
script = cloudflare_worker_script.nceahelpworker.name
name = "WORKER_URL"
value = var.worker_url
}

resource "cloudflare_worker_secret" "cookie_secret" {
script = cloudflare_worker_script.nceahelpworker.name
name = "COOKIE_SECRET"
value = var.cookie_secret
}
4 changes: 4 additions & 0 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "cloudflare_worker_url" {
description = "The URL of the deployed Cloudflare Worker"
value = cloudflare_worker_script.nceahelpworker.id
}
45 changes: 45 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
variable "cloudflare_account_id" {
description = "The Cloudflare account ID"
type = string
}

variable "cloudflare_api_token" {
description = "The Cloudflare API token"
type = string
sensitive = true
}

variable "discord_token" {
description = "The Discord API token"
type = string
sensitive = true
}

variable "discord_public_key" {
description = "The Discord public key"
type = string
sensitive = true
}

variable "discord_application_id" {
description = "The Discord application ID"
type = string
sensitive = true
}

variable "discord_client_secret" {
description = "The Discord client secret"
type = string
sensitive = true
}

variable "worker_url" {
description = "The URL of the worker"
type = string
}

variable "cookie_secret" {
description = "The secret for signing cookies"
type = string
sensitive = true
}
23 changes: 0 additions & 23 deletions wrangler.toml

This file was deleted.

Loading