Skip to content

Commit b291e17

Browse files
committed
creating cloud build triggers and adding in terraform fmtter/linter
1 parent 1a45399 commit b291e17

File tree

8 files changed

+80
-172
lines changed

8 files changed

+80
-172
lines changed

.github/workflows/default.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ on:
77
workflow_dispatch:
88

99
jobs:
10-
run-terraform-apply:
11-
uses: ./.github/workflows/terraform-apply.yml
12-
permissions:
13-
contents: read
14-
secrets: inherit
10+
run-terraform-apply:
11+
uses: ./.github/workflows/terraform-apply.yml
12+
permissions:
13+
contents: read
14+
secrets: inherit
15+
run-terraform-linter:
16+
needs: [run-terraform-apply]
17+
uses: ./.github/workflows/terraform-linter.yml
18+
permissions:
19+
contents: read

.github/workflows/terraform-apply.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ jobs:
3939
id: apply
4040
with:
4141
run: ${{ steps.apply-run.outputs.run_id }}
42-
comment: "Apply Run from GitHub Actions CI ${{ github.sha }}"
42+
comment: "Apply Run from GitHub Actions CI ${{ github.sha }}"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Terraform Linting and Formatting
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
lint-and-format:
8+
name: Lint and Format Terraform Files
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v3
14+
15+
- name: Set up Terraform
16+
uses: hashicorp/setup-terraform@v2
17+
with:
18+
terraform_version: latest
19+
20+
- name: Format Terraform files
21+
run: terraform fmt -check

TOOLS.md

Lines changed: 0 additions & 136 deletions
This file was deleted.

main.tf

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,9 @@ resource "google_storage_bucket" "default" {
1111
uniform_bucket_level_access = true
1212
}
1313

14-
/*resource "google_container_cluster" "primary" {
15-
name = "dsb-devsecops-cluster"
16-
location = var.region
17-
18-
# Enable GKE features
19-
remove_default_node_pool = true
20-
deletion_protection = false
21-
22-
cluster_autoscaling {
23-
enabled = false
24-
}
25-
26-
# Specify network and subnetwork
27-
network = "default"
28-
subnetwork = "default"
14+
resource "google_artifact_registry_repository" "default_docker_repo" {
15+
repository_id = "dsb-docker-images"
16+
format = "DOCKER"
17+
location = var.region
18+
description = "Repository for all DSB Docker images"
2919
}
30-
31-
resource "google_container_node_pool" "primary_nodes" {
32-
cluster = google_container_cluster.primary.name
33-
location = google_container_cluster.primary.location
34-
node_count = 1 # Single node in the pool - super cheap :)
35-
max_pods_per_node = 8
36-
37-
node_config {
38-
preemptible = true
39-
machine_type = "e2-standard-8"
40-
oauth_scopes = [
41-
"https://www.googleapis.com/auth/cloud-platform",
42-
]
43-
}
44-
}*/

modules/pipelines/main.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Cloud Build Pipeline for gcp-python-fastapi
2+
# https://github.com/The-DevSec-Blueprint/gcp-python-fastapi/tree/main
3+
resource "google_cloudbuild_trigger" "build_trigger" {
4+
name = var.cloudbuild_trigger_name
5+
description = var.description
6+
filename = var.filename
7+
8+
github {
9+
owner = "The-DevSec-Blueprint"
10+
name = var.github_repo_name
11+
push {
12+
branch = "^main$"
13+
}
14+
}
15+
}

modules/pipelines/variable.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
variable "cloudbuild_trigger_name" {
2+
description = "Name of the Cloud Build trigger"
3+
type = string
4+
}
5+
6+
variable "description" {
7+
description = "Description of the Cloud Build trigger"
8+
type = string
9+
}
10+
11+
variable "filename" {
12+
description = "Path to the Cloud Build configuration file"
13+
type = string
14+
default = "cloudbuild.yaml"
15+
}
16+
17+
variable "github_repo_name" {
18+
description = "Name of the GitHub repository"
19+
type = string
20+
}

pipelines.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module "gcp_python_fastapi_pipeline" {
2+
source = "./modules/pipelines"
3+
cloudbuild_trigger_name = "gcp-python-fastapi"
4+
description = "Cloud Build Trigger for GCP Python FastAPI"
5+
github_repo_name = "gcp-python-fastapi"
6+
7+
depends_on = [google_artifact_registry_repository.default_docker_repo]
8+
}

0 commit comments

Comments
 (0)