Skip to content

Commit 4313880

Browse files
committed
Initial commit
0 parents  commit 4313880

File tree

14 files changed

+403
-0
lines changed

14 files changed

+403
-0
lines changed

.devcontainer/devcontainer.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"image": "mcr.microsoft.com/devcontainers/base:bookworm",
3+
"forwardPorts": [],
4+
"workspaceMount": "source=${localWorkspaceFolder},target=/var/app,type=bind,consistency=cached",
5+
"workspaceFolder": "/var/app",
6+
"features": {
7+
"ghcr.io/devcontainers-extra/features/opentofu:1": {
8+
"version": "1.10.7"
9+
},
10+
"ghcr.io/devcontainers/features/aws-cli:1": {}
11+
}
12+
}

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root = true
2+
3+
[*.tf]
4+
indent_style = space
5+
indent_size = 2

.github/workflows/tofu.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: OpenTofu
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
defaults:
9+
run:
10+
shell: bash
11+
12+
permissions:
13+
pull-requests: write
14+
15+
concurrency:
16+
group: ci-${{ github.ref }}
17+
cancel-in-progress: true
18+
19+
env:
20+
TF_VAR_fastly_api_key: ${{ secrets.fastly_api_key }}
21+
TF_VAR_porkbun_api_key: ${{ secrets.porkbun_api_key }}
22+
TF_VAR_porkbun_secret_key: ${{ secrets.porkbun_secret_key }}
23+
AWS_ACCESS_KEY_ID: ${{ secrets.aws_access_key_id }}
24+
AWS_SECRET_ACCESS_KEY: ${{ secrets.aws_secret_access_key }}
25+
26+
jobs:
27+
validate:
28+
name: "Validate"
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v5
32+
- uses: opentofu/setup-opentofu@v1
33+
with:
34+
tofu_version_file: .opentofu-version
35+
- name: Tofu Validate
36+
run: tofu validate -no-color
37+
- name: Tofu Format Check
38+
run: tofu fmt -check
39+
40+
plan:
41+
name: "Plan"
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v5
45+
- uses: opentofu/setup-opentofu@v1
46+
with:
47+
tofu_version_file: .opentofu-version
48+
- name: Tofu Init (Staging)
49+
run: tofu init -var-file="env-staging.tfvars" -input=false
50+
- name: Tofu Plan (Staging)
51+
run: |
52+
{ PLAN=$(tofu plan -var-file="env-staging.tfvars" -no-color | tee /dev/fd/5 || true); } 5>&1
53+
echo "<details><summary>OpenTofu Plan (Staging)</summary><code>$PLAN</code></details>" >> $GITHUB_STEP_SUMMARY
54+
continue-on-error: true
55+
- name: Tofu Init (Prod)
56+
run: tofu init -var-file="env-prod.tfvars" -input=false
57+
- name: Tofu Plan (Prod)
58+
run: |
59+
{ PLAN=$(tofu plan -var-file="env-prod.tfvars" -no-color | tee /dev/fd/5 || true); } 5>&1
60+
echo "<details><summary>OpenTofu Plan (Prod)</summary><code>$PLAN</code></details>" >> $GITHUB_STEP_SUMMARY
61+
62+
deploy-staging:
63+
name: "Deploy (Staging)"
64+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
65+
environment: staging
66+
needs: [validate, plan]
67+
runs-on: ubuntu-latest
68+
steps:
69+
- uses: actions/checkout@v5
70+
- uses: opentofu/setup-opentofu@v1
71+
with:
72+
tofu_version_file: .opentofu-version
73+
- name: Tofu Init
74+
run: tofu init -var-file="env-staging.tfvars"
75+
- name: Tofu Apply
76+
run: tofu apply -var-file="env-staging.tfvars" -auto-approve
77+
78+
deploy-prod:
79+
name: "Deploy (Prod)"
80+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
81+
environment: prod
82+
needs: [deploy-staging]
83+
runs-on: ubuntu-latest
84+
steps:
85+
- uses: actions/checkout@v5
86+
- uses: opentofu/setup-opentofu@v1
87+
with:
88+
tofu_version_file: .opentofu-version
89+
- name: Tofu Init
90+
run: tofu init -var-file="env-prod.tfvars"
91+
- name: Tofu Apply
92+
run: tofu apply -var-file="env-prod.tfvars" -auto-approve

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.terraform/
2+
*.tfstate*
3+
local.auto.tfvars
4+
.env
5+
6+
# Editor-specific files
7+
.DS_Store
8+
.idea
9+
.code
10+
.vscode

.opentofu-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.10.7

.terraform.lock.hcl

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
locals {
2+
env_key_map = {
3+
staging = "terraform-staging.tfstate"
4+
prod = "terraform-prod.tfstate"
5+
}
6+
}
7+
8+
terraform {
9+
backend "s3" {
10+
bucket = "tofu-remote-state"
11+
key = local.env_key_map[var.env]
12+
region = "us-east"
13+
profile = "fastly-us-east"
14+
skip_credentials_validation = true
15+
skip_region_validation = true
16+
use_path_style = true
17+
endpoints = {
18+
s3 = "https://us-east.object.fastlystorage.app"
19+
}
20+
}
21+
}

env-prod.tfvars

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
env = "prod"
2+
playful_web_domain = "playfulprogramming.com"
3+
playful_web_host = "playful-web.fly.dev"

env-staging.tfvars

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
env = "staging"
2+
playful_web_domain = "playfulprogramming-staging.xyz"
3+
playful_web_host = "playful-web.fly.dev"

main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
provider "fastly" {
2+
api_key = var.fastly_api_key
3+
}
4+
5+
provider "porkbun" {
6+
api_key = var.porkbun_api_key
7+
secret_api_key = var.porkbun_secret_key
8+
}
9+
10+
module "playful-web" {
11+
source = "./modules/playful-web"
12+
domain = var.playful_web_domain
13+
host = var.playful_web_host
14+
}

0 commit comments

Comments
 (0)