Skip to content

Commit

Permalink
chore: add terraform to each project (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
potb committed Sep 19, 2023
1 parent 5226a89 commit d95b58d
Show file tree
Hide file tree
Showing 13 changed files with 569 additions and 273 deletions.
18 changes: 13 additions & 5 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ on:
- renovate.json
- '**integration.yaml'

env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
TF_CLOUD_ORGANIZATION: ${{ secrets.TF_CLOUD_ORGANIZATION }}
TF_VAR_cloudflare_api_token: ${{ secrets.TF_VAR_CLOUDFLARE_API_TOKEN }}

jobs:
deployment:
name: Deploy to production
Expand All @@ -20,8 +25,13 @@ jobs:
with:
fetch-depth: 0

- name: Setup Terraform
uses: hashicorp/[email protected]
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}

- name: Setup pnpm
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v2.4.0

- name: Set Nx SHAs
uses: nrwl/nx-set-shas@v3
Expand All @@ -40,10 +50,8 @@ jobs:
- name: Build affected projects
run: pnpm affected:build

- name: Expose secrets as environment variables
uses: oNaiPs/secrets-to-env-action@v1
with:
secrets: ${{ toJSON(secrets) }}
- name: Provision infrastructure
run: terraform init && terraform apply -auto-approve

- name: Deploy affected projects
run: pnpm affected:deploy
11 changes: 1 addition & 10 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
- renovate.json
- '**deployment.yaml'


jobs:
integration:
name: Check branch integration
Expand All @@ -22,7 +21,7 @@ jobs:
fetch-depth: 0

- name: Setup pnpm
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v2.4.0

- name: Set Nx SHAs
uses: nrwl/nx-set-shas@v3
Expand All @@ -43,11 +42,3 @@ jobs:

- name: Build affected projects
run: pnpm affected:build

- name: Expose secrets as environment variables
uses: oNaiPs/secrets-to-env-action@v1
with:
secrets: ${{ toJSON(secrets) }}

- name: Deploy affected projects
run: pnpm affected:deploy
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ dist
tmp

# Svelte-kit
.svelte-kit
.svelte-kit

# Terraform
.terraform
terraform.tfvars
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.4.0
20.6.1
25 changes: 25 additions & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/aahh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"build": "vite build",
"preview": "vite preview",
"typecheck": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"provision": "terraform init && terraform apply -auto-approve",
"deploy": "wrangler pages deploy .svelte-kit/cloudflare --project-name aahh",
"prepare": "svelte-kit sync"
}
Expand Down
1 change: 1 addition & 0 deletions apps/prout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"build": "vite build",
"preview": "vite preview",
"typecheck": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"provision": "terraform init && terraform apply -auto-approve",
"deploy": "wrangler pages deploy .svelte-kit/cloudflare --project-name prout",
"prepare": "svelte-kit sync"
}
Expand Down
1 change: 1 addition & 0 deletions apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"build": "vite build",
"preview": "vite preview",
"typecheck": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"provision": "terraform init && terraform apply -auto-approve",
"deploy": "wrangler pages deploy .svelte-kit/cloudflare --project-name website",
"prepare": "svelte-kit sync"
}
Expand Down
65 changes: 65 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
terraform {
required_version = ">= 1.5.0"
required_providers {
cloudflare = {
source = "cloudflare/cloudflare"
version = "~> 4.0"
}
}

cloud {
organization = "potb"
workspaces {
name = "projects"
}
}
}

variable "cloudflare_api_token" {
description = "Cloudflare API Token"
type = string
}

provider "cloudflare" {
api_token = var.cloudflare_api_token
}

module "website" {
source = "./terraform/modules/project"

cloudflare_api_token = var.cloudflare_api_token
name = "website"
dns_record_name = "@"
}

module "prout" {
source = "./terraform/modules/project"

cloudflare_api_token = var.cloudflare_api_token
name = "prout"
extra_dns_config = {
config = {
zone = "prout.dev"
type = "CNAME"
name = "@"
dns_record_name = "prout.dev"
}

}
}

module "aahh" {
source = "./terraform/modules/project"

cloudflare_api_token = var.cloudflare_api_token
name = "aahh"
extra_dns_config = {
config = {
zone = "aahh.dev"
type = "CNAME"
name = "@"
dns_record_name = "aahh.dev"
}

}
}
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@
"typecheck": "nx typecheck"
},
"devDependencies": {
"@nrwl/nx-cloud": "16.1.0",
"@sveltejs/adapter-cloudflare": "2.3.1",
"@sveltejs/kit": "1.22.3",
"@vite-pwa/sveltekit": "0.2.5",
"nx": "16.5.2",
"@nrwl/nx-cloud": "16.4.0",
"@sveltejs/adapter-cloudflare": "2.3.3",
"@sveltejs/kit": "1.25.0",
"@vite-pwa/sveltekit": "0.2.7",
"nx": "16.8.1",
"prettier": "3.0.3",
"prettier-plugin-svelte": "3.0.3",
"svelte": "4.0.5",
"svelte-check": "3.4.6",
"typescript": "5.1.6",
"vite": "4.4.4",
"vite-imagetools": "5.0.5",
"vite-plugin-pwa": "0.16.4",
"wrangler": "3.2.0"
"svelte": "4.2.0",
"svelte-check": "3.5.1",
"typescript": "5.2.2",
"vite": "4.4.9",
"vite-imagetools": "5.0.8",
"vite-plugin-pwa": "0.16.5",
"wrangler": "3.8.0"
},
"packageManager": "pnpm@8.6.7",
"packageManager": "pnpm@8.7.5",
"engines": {
"node": "20.4.0"
"node": "20.6.1"
}
}
Loading

0 comments on commit d95b58d

Please sign in to comment.