Skip to content

Commit

Permalink
Merge pull request #1 from ThreeDotsLabs/init
Browse files Browse the repository at this point in the history
Initial configuration
  • Loading branch information
m110 committed Aug 29, 2024
2 parents b205301 + 90e12d5 commit 38c2bf8
Show file tree
Hide file tree
Showing 6 changed files with 351 additions and 0 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: master
on:
workflow_dispatch:
push:
branches:
- master

jobs:
apply:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.9.5
terraform_wrapper: false

- run: echo -n "$CREDENTIALS" > credentials.json
env:
CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}

- id: fmt
run: terraform fmt -check
continue-on-error: true

- id: init
run: terraform init
env:
GOOGLE_APPLICATION_CREDENTIALS: credentials.json

- id: validate
run: terraform validate -no-color | tee validation

- id: plan
run: terraform plan -out=out.tfplan -no-color -input=false 2> plan_errors
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.TERRAFORM_GITHUB_TOKEN }}
GOOGLE_APPLICATION_CREDENTIALS: credentials.json

- run: |
TMP_OUTPUT=$(terraform show -no-color out.tfplan)
FORMATTED_OUTPUT="${TMP_OUTPUT:0:65536}"
echo "$FORMATTED_OUTPUT" | tee output
- id: output
run: |
{
echo 'PLAN_OUTPUT<<EOF'
echo '```'
sed -n '/─/,$p' output | sed '1d'
echo '```'
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Approve
uses: trstringer/manual-approval@v1.9.1
timeout-minutes: 5
with:
issue-title: "Terraform changes require approval"
secret: ${{ github.TOKEN }}
approvers: m110,roblaszczak
issue-body: ${{ steps.output.outputs.PLAN_OUTPUT }}
minimum-approvals: 1

- name: Apply
run: terraform apply out.tfplan
env:
GITHUB_TOKEN: ${{ secrets.TERRAFORM_GITHUB_TOKEN }}
104 changes: 104 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: pr
on:
pull_request:
jobs:
plan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.9.5
terraform_wrapper: false

- run: echo -n "$CREDENTIALS" > credentials.json
env:
CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}

- id: fmt
run: terraform fmt -check
continue-on-error: true

- id: init
run: terraform init
env:
GOOGLE_APPLICATION_CREDENTIALS: credentials.json

- id: validate
run: terraform validate -no-color | tee validation

- id: plan
run: terraform plan -out=out.tfplan -no-color -input=false 2> plan_errors
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.TERRAFORM_GITHUB_TOKEN }}
GOOGLE_APPLICATION_CREDENTIALS: credentials.json

- run: terraform show -no-color out.tfplan | tee plan

- uses: actions/github-script@v7
env:
FMT_OUTPUT: ${{ steps.fmt.outcome }}
INIT_OUTPUT: ${{ steps.init.outcome }}
VALIDATE_OUTPUT: ${{ steps.validate.outcome }}
PLAN_OUTPUT: ${{ steps.plan.outcome }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require("fs");
const validation = fs.readFileSync("validation", "utf8");
const plan = fs.readFileSync("plan", "utf8");
const plan_errors = fs.readFileSync("plan_errors", "utf8");
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
})
const botComment = comments.find(comment => {
return comment.user.type === 'Bot' && comment.body.includes('Terraform Format and Style')
})
const output = `#### Terraform Format and Style 🖌 \`${process.env.FMT_OUTPUT}\`
#### Terraform Initialization ⚙️ \`${process.env.INIT_OUTPUT}\`
#### Terraform Validation 🤖 \`${process.env.VALIDATE_OUTPUT}\`
<details><summary>Validation Output</summary>
\`\`\`\n
${ validation }
\`\`\`
</details>
#### Terraform Plan 📖 \`${process.env.PLAN_OUTPUT}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${ plan }
${ plan_errors }
\`\`\`
</details>
*Pushed by @${{ github.actor }}*`;
if (botComment) {
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: output
})
} else {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
}
- if: steps.plan.outcome != 'success' || steps.fmt.outcome != 'success'
run: exit 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.

114 changes: 114 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
terraform {
backend "gcs" {
bucket = "watermill-terraform-state"
}
required_providers {
github = {
source = "integrations/github"
version = "~> 6.0"
}
}
}

provider "github" {
owner = "ThreeDotsLabs"
}

module "pubsub_repo_amazonsqs" {
source = "./modules/pubsub_repo"

id = "amazonsqs"
name = "Amazon SQS/SNS"
description = ""
url = ""
}

module "pubsub_repo_amqp" {
source = "./modules/pubsub_repo"

id = "amqp"
name = "AMQP"
description = ""
url = ""
}

module "pubsub_repo_bolt" {
source = "./modules/pubsub_repo"

id = "bolt"
name = "Bolt"
description = ""
url = ""
}

module "pubsub_repo_firestore" {
source = "./modules/pubsub_repo"

id = "firestore"
name = "Firestore"
description = ""
url = ""
}

module "pubsub_repo_googlecloud" {
source = "./modules/pubsub_repo"

id = "googlecloud"
name = "Google Cloud Pub/Sub"
description = ""
url = ""
}

module "pubsub_repo_http" {
source = "./modules/pubsub_repo"

id = "http"
name = "HTTP"
description = ""
url = ""
}

module "pubsub_repo_io" {
source = "./modules/pubsub_repo"

id = "io"
name = "IO"
description = ""
url = ""
}

module "pubsub_repo_kafka" {
source = "./modules/pubsub_repo"

id = "kafka"
name = "Kafka"
description = ""
url = ""
}

module "pubsub_repo_nats" {
source = "./modules/pubsub_repo"

id = "nats"
name = "NATS"
description = ""
url = ""
}

module "pubsub_repo_redisstream" {
source = "./modules/pubsub_repo"

id = "redisstream"
name = "Redis"
description = ""
url = ""
}

module "pubsub_repo_sql" {
source = "./modules/pubsub_repo"

id = "sql"
name = "SQL (Postgres/MySQL)"
description = ""
url = ""
}
35 changes: 35 additions & 0 deletions modules/pubsub_repo/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
terraform {
required_providers {
github = {
source = "integrations/github"
version = "~> 6.0"
}
}
}

provider "github" {
owner = "ThreeDotsLabs"
}

resource "github_repository" "repo" {
name = "watermill-${var.id}"
description = "${var.name} Pub/Sub for the Watermill project."

homepage_url = var.url

has_downloads = true
has_issues = false
has_projects = false
has_wiki = false

allow_squash_merge = true
allow_merge_commit = false
allow_rebase_merge = false

merge_commit_message = "PR_TITLE"
merge_commit_title = "MERGE_MESSAGE"
squash_merge_commit_message = "COMMIT_MESSAGES"
squash_merge_commit_title = "COMMIT_OR_PR_TITLE"

vulnerability_alerts = true
}
4 changes: 4 additions & 0 deletions modules/pubsub_repo/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "id" {}
variable "name" {}
variable "description" {}
variable "url" {}

0 comments on commit 38c2bf8

Please sign in to comment.