Skip to content

Commit 1657302

Browse files
committed
adding prod env
1 parent 1b6ac6f commit 1657302

File tree

2 files changed

+202
-6
lines changed

2 files changed

+202
-6
lines changed

.github/workflows/pipeline.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,54 @@ jobs:
7878
-var="project_database=${{ env.PIPELINE_PROJECT_DATABASE_DEV }}" \
7979
-auto-approve
8080
81+
deploy_production:
82+
if: github.ref == 'refs/heads/main'
83+
runs-on: ubuntu-latest
84+
needs: [test]
85+
defaults:
86+
run:
87+
working-directory: ./terraform/prod
88+
steps:
89+
- uses: actions/checkout@v4
90+
- name: Google Cloud Auth
91+
uses: 'google-github-actions/auth@v2'
92+
with:
93+
project_id: ${{ env.PIPELINE_PROJECT_ID }}
94+
credentials_json: ${{ env.PIPELINE_SA_KEY }}
95+
96+
- uses: hashicorp/setup-terraform@v3
97+
98+
- name: Terraform fmt
99+
id: fmt
100+
run: terraform fmt -check
101+
continue-on-error: true
102+
103+
- name: Terraform Init
104+
id: init
105+
run: terraform init
106+
107+
- name: Terraform Validate
108+
id: validate
109+
run: terraform validate -no-color
110+
111+
- name: Terraform Plan
112+
id: plan
113+
run: |
114+
terraform plan -no-color -var="google_service_account_cloud_functions=${{ env.PIPELINE_GOOGLE_SERVICE_ACCOUNT_CLOUD_FUNCTIONS }}" \
115+
-var="google_service_account_api_gateway=${{ env.PIPELINE_GOOGLE_SERVICE_ACCOUNT_API_GATEWAY }}" \
116+
-var="project_database=${{ env.PIPELINE_PROJECT_DATABASE_PROD }}"
117+
continue-on-error: true
118+
119+
- name: Terraform Plan status
120+
if: steps.plan.outcome == 'failure'
121+
run: exit 1
122+
123+
- name: Terraform Apply
124+
id: apply
125+
run: |
126+
terraform apply -var="google_service_account_cloud_functions=${{ env.PIPELINE_GOOGLE_SERVICE_ACCOUNT_CLOUD_FUNCTIONS }}" \
127+
-var="google_service_account_api_gateway=${{ env.PIPELINE_GOOGLE_SERVICE_ACCOUNT_API_GATEWAY }}" \
128+
-var="project_database=${{ env.PIPELINE_PROJECT_DATABASE_PROD }}" \
129+
-auto-approve
130+
131+

terraform/prod/main.tf

Lines changed: 151 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,157 @@ terraform {
1212
}
1313
}
1414

15-
module "backend-api" {
16-
source = "./../modules/api-gateway"
17-
environment = "prod"
18-
project = "httparchive"
19-
region = "us-east1"
20-
service_account_email = var.google_service_account_api_gateway
15+
resource "google_api_gateway_api" "api" {
16+
provider = google-beta
17+
api_id = "api-gw-prod"
18+
display_name = "The prod API Gateway"
19+
project = "httparchive"
20+
}
21+
22+
resource "google_api_gateway_api_config" "api_config" {
23+
provider = google-beta
24+
api = google_api_gateway_api.api.api_id
25+
api_config_id_prefix = "api"
26+
project = "httparchive"
27+
display_name = "The prod Config"
28+
openapi_documents {
29+
document {
30+
path = "spec.yaml"
31+
contents = base64encode(<<-EOF
32+
swagger: "2.0"
33+
info:
34+
title: reports-backend-api
35+
description: API tech report
36+
version: 1.0.0
37+
schemes:
38+
- https
39+
produces:
40+
- application/json
41+
paths:
42+
/v1/categories:
43+
get:
44+
summary: categories
45+
operationId: getCategories
46+
x-google-backend:
47+
address: https://us-east1-httparchive.cloudfunctions.net/categories-prod
48+
deadline: 60
49+
# security:
50+
# - api_key: []
51+
responses:
52+
200:
53+
description: String
54+
/v1/adoption:
55+
get:
56+
summary: adoption
57+
operationId: getadoptionReports
58+
x-google-backend:
59+
address: https://us-east1-httparchive.cloudfunctions.net/adoption-prod
60+
deadline: 60
61+
# security:
62+
# - api_key: []
63+
responses:
64+
200:
65+
description: String
66+
/v1/page-weight:
67+
get:
68+
summary: pageWeight
69+
operationId: getpageWeight
70+
x-google-backend:
71+
address: https://us-east1-httparchive.cloudfunctions.net/page-weight-prod
72+
deadline: 60
73+
# security:
74+
# - api_key: []
75+
responses:
76+
200:
77+
description: String
78+
/v1/lighthouse:
79+
get:
80+
summary: lighthouse
81+
operationId: getLighthouseReports
82+
x-google-backend:
83+
address: https://us-east1-httparchive.cloudfunctions.net/lighthouse-prod
84+
deadline: 60
85+
# security:
86+
# - api_key: []
87+
responses:
88+
200:
89+
description: String
90+
/v1/cwv:
91+
get:
92+
summary: cwv
93+
operationId: getCwv
94+
x-google-backend:
95+
address: https://us-east1-httparchive.cloudfunctions.net/cwvtech-prod
96+
deadline: 60
97+
# security:
98+
# - api_key: []
99+
responses:
100+
200:
101+
description: String
102+
/v1/ranks:
103+
get:
104+
summary: ranks
105+
operationId: getRanks
106+
x-google-backend:
107+
address: https://us-east1-httparchive.cloudfunctions.net/ranks-prod
108+
deadline: 60
109+
# security:
110+
# - api_key: []
111+
responses:
112+
200:
113+
description: String
114+
/v1/geos:
115+
get:
116+
summary: geos
117+
operationId: getGeos
118+
x-google-backend:
119+
address: https://us-east1-httparchive.cloudfunctions.net/geos-prod
120+
deadline: 60
121+
# security:
122+
# - api_key: []
123+
responses:
124+
200:
125+
description: String
126+
/v1/technologies:
127+
get:
128+
summary: geos
129+
operationId: getTechnologies
130+
x-google-backend:
131+
address: https://us-east1-httparchive.cloudfunctions.net/technologies-prod
132+
deadline: 60
133+
# security:
134+
# - api_key: []
135+
responses:
136+
200:
137+
description: String
138+
EOF
139+
)
140+
}
141+
}
142+
gateway_config {
143+
backend_config {
144+
google_service_account = var.google_service_account_api_gateway
145+
}
146+
}
147+
}
148+
149+
resource "google_api_gateway_gateway" "gateway" {
150+
provider = google-beta
151+
project = "httparchive"
152+
region = "us-east1"
153+
api_config = google_api_gateway_api_config.api_config.id
154+
gateway_id = "prod-gw"
155+
display_name = "prod Api Gateway"
156+
labels = {
157+
owner = "tech_report_api"
158+
environment = "prod"
159+
}
160+
depends_on = [google_api_gateway_api_config.api_config]
161+
lifecycle {
162+
replace_triggered_by = [
163+
google_api_gateway_api_config.api_config
164+
]
165+
}
21166
}
22167

23168
module "cwvtech" {

0 commit comments

Comments
 (0)