@@ -3,6 +3,13 @@ terraform {
33 bucket = " tfstate-httparchive"
44 prefix = " tech-report-apis/dev"
55 }
6+
7+ required_providers {
8+ docker = {
9+ source = " kreuzwerker/docker"
10+ version = " >= 3.6.2"
11+ }
12+ }
613}
714
815provider "google" {
@@ -11,23 +18,30 @@ provider "google" {
1118 request_timeout = " 60m"
1219}
1320
14- resource "google_api_gateway_api" "api" {
15- provider = google- beta
16- api_id = " reports-api-dev"
17- display_name = " Reports API Gateway DEV"
18- project = var. project
21+ provider "google-beta" {
22+ project = var. project
23+ region = var. region
24+ }
25+
26+ # Get current Google Cloud access token
27+ data "google_client_config" "default" {}
28+
29+ # Configure Docker provider with Artifact Registry authentication
30+ provider "docker" {
31+ registry_auth {
32+ address = " ${ var . region } -docker.pkg.dev"
33+ username = " oauth2accesstoken"
34+ password = data. google_client_config . default . access_token
35+ }
1936}
2037
21- resource "google_api_gateway_api_config" "api_config" {
22- provider = google- beta
23- api = google_api_gateway_api. api . api_id
24- api_config_id_prefix = " reports-api-config-dev"
25- project = var. project
26- display_name = " Reports API Config DEV"
27- openapi_documents {
28- document {
29- path = " spec.yaml"
30- contents = base64encode (<<- EOF
38+ module "gateway" {
39+ source = " ./../modules/api-gateway"
40+ project = var. project
41+ environment = var. environment
42+ region = var. region
43+ service_account_email = var. google_service_account_api_gateway
44+ spec_yaml = << EOF
3145swagger: "2.0"
3246info:
3347 title: reports_api_config_dev
@@ -113,48 +127,36 @@ paths:
113127 200:
114128 description: String
115129EOF
116- )
117- }
118- }
119- gateway_config {
120- backend_config {
121- google_service_account = var. google_service_account_api_gateway
122- }
123- }
124- }
125-
126- resource "google_api_gateway_gateway" "gateway" {
127- provider = google- beta
128- project = var. project
129- region = var. region
130- api_config = google_api_gateway_api_config. api_config . id
131- gateway_id = " reports-dev"
132- display_name = " Reports API Gateway DEV"
133- labels = {
134- owner = " tech_report_api"
135- environment = var.environment
136- }
137- depends_on = [google_api_gateway_api_config . api_config ]
138- lifecycle {
139- replace_triggered_by = [
140- google_api_gateway_api_config . api_config
141- ]
142- }
143130}
144131
145132module "endpoints" {
146- source = " ./../modules/run-service"
147- entry_point = " app"
148- project = var. project
149- environment = var. environment
150- source_directory = " ../../src"
151- function_name = " tech-report-api"
152- region = var. region
153- service_account_email = var. google_service_account_cloud_functions
154- service_account_api_gateway = var. google_service_account_api_gateway
155- min_instances = var. min_instances
133+ source = " ./../modules/run-service"
134+ entry_point = " app"
135+ project = var. project
136+ environment = var. environment
137+ source_directory = " ../../src"
138+ function_name = " tech-report-api"
139+ region = var. region
140+ service_account_email = var. google_service_account_cloud_functions
141+ service_account_api_gateway = var. google_service_account_api_gateway
142+ min_instances = var. min_instances
156143 environment_variables = {
157144 " PROJECT" = var.project
158145 " DATABASE" = var.project_database
159146 }
160147}
148+
149+ moved {
150+ from = google_api_gateway_api. api
151+ to = module. gateway . google_api_gateway_api . api
152+ }
153+
154+ moved {
155+ from = google_api_gateway_api_config. api_config
156+ to = module. gateway . google_api_gateway_api_config . api_config
157+ }
158+
159+ moved {
160+ from = google_api_gateway_gateway. gateway
161+ to = module. gateway . google_api_gateway_gateway . gateway
162+ }
0 commit comments