-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Terraform GCP Cloud Run | ||
|
||
This is a Terraform module to provision GCP Cloud Run to serve your container application or service | ||
|
||
## Resources | ||
|
||
This Terraform module will create below resources: | ||
|
||
* Google Container Image | ||
* Google Service Account for Cloud Run | ||
* Google Cloud Run service | ||
|
||
## Dependencies | ||
|
||
* Terraform: ~> 1.0.0 | ||
* Terraform provider: hashicorp/archive v2.2.0 | ||
* Terraform provider: hashicorp/google v3.88.0 | ||
* Terraform provider: kreuzwerker/docker v2.15.0 | ||
* Terraform provider: hashicorp/null v3.1.0 | ||
* Terraform provider: hashicorp/random v3.1.0 | ||
|
||
## Input Variables | ||
| Variable Name | Data Type | Is Required | Default Value | Description | | ||
|-----------------------|--------------|-----------------------------------|---------------|----------------------------------------------------------------------------------------------------------| | ||
| service_name | string | yes | | The name of your service, e.g. `my-web`, `ashari`, `ashweb`, or `andi-web` | | ||
| gcp_project_name | string | yes | | The name of your GCP project | | ||
| gcp_region | string | yes | | The name of GCP region | | ||
| remove_image_when_destroy | bool | no | true | When you destroy the stacks, do you want to remove all of the images as well? | | ||
| docker_source_path | string | yes | | The path of the service/application source code | | ||
| docker_region | string | no | | The default region name, available value `asia`, `us`, `eu` | | ||
| container_concurrency | string | no | 30 | The maximum concurrent per container | | ||
| container_port | string | no | 3000 | The port to access the container | | ||
| container_cpu | string | no | 2000m | The amount of CPU allocated for the container | | ||
| container_memory | string | no | 4096Mi | The amount of memory allocated for the container | | ||
|
||
## Output Variables | ||
|
||
* **docker-image-url**: A generated docker image URL | ||
* **docker-image-tag**: A generated docker image tag | ||
* **service-endpoint**: A generated service URL | ||
|
||
## Sample Usage | ||
|
||
### Simple Implementation | ||
|
||
``` | ||
module "gcp-cloud-run" { | ||
source = "git@github.com:aashari/terraform-gcp-cloud-run.git?ref=v1.0.0" | ||
service_name = "ashxyz" | ||
gcp_project_name = "ashari-tech-main" | ||
gcp_region = "asia-southeast2" | ||
docker_source_path = "src" | ||
docker_region = "asia" | ||
} | ||
``` | ||
|
||
## Contribute | ||
|
||
Feel free to contribute, don't forget to raise an issue first then create a PR with referenced to that issue, thanks! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
testing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module "gcp-cloud-run" { | ||
source = "../../" | ||
|
||
service_name = "ashxyz" | ||
gcp_project_name = "ashari-tech-main" | ||
gcp_region = "asia-southeast2" | ||
docker_source_path = "src" | ||
docker_region = "asia" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## Stage-1: | ||
## Build image ~300MB | ||
FROM node:16 as build | ||
|
||
WORKDIR /app | ||
COPY ./src /app/ | ||
|
||
RUN npm install | ||
|
||
## Stage-2: | ||
## Deployment image ~70MB | ||
FROM node:16-slim | ||
|
||
WORKDIR /app | ||
COPY --from=build /app . | ||
|
||
EXPOSE 3000 | ||
|
||
CMD ["node", "index.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const express = require('express') | ||
const app = express() | ||
const port = 3000 | ||
|
||
app.get('/', (req, res) => { | ||
res.send('Hello World!') | ||
}) | ||
|
||
app.listen(port, () => { | ||
console.log(`Example app listening at http://localhost:${port}`) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
output "docker-image-url" { | ||
value = local.docker_image_url | ||
description = "A generated docker image URL" | ||
} | ||
|
||
output "docker-image-tag" { | ||
value = data.archive_file.init.output_sha | ||
description = "A generated docker image tag" | ||
} | ||
|
||
output "service-endpoint" { | ||
value = google_cloud_run_service.run.status[0].url | ||
description = "A generated service URL" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters