Skip to content

Commit

Permalink
feat: add terraform settings
Browse files Browse the repository at this point in the history
  • Loading branch information
RyushiAok committed Oct 28, 2023
1 parent 470e749 commit 2e9c93e
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 0 deletions.
2 changes: 2 additions & 0 deletions terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
environments/
28 changes: 28 additions & 0 deletions terraform/Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
env_files = [{ path = "./.env", profile = "development" }]

[tasks.docker-build]
command = "docker"
args = ["build", "${SERVER_DOCKERFILE_PATH}", "-t", "${DOCKER_IMAGE_NAME}"]

[tasks.docker-push]
dependencies = ["docker-build"]
command = "docker"
args = ["push", "${DOCKER_IMAGE_NAME}"]

[tasks.terraform-init]
command = "terraform"
args = ["-chdir=./gcp/duckstream/environments/${ENV}", "init"]

[tasks.terraform-plan]
dependencies = ["terraform-init"]
command = "terraform"
args = ["-chdir=./gcp/duckstream/environments/${ENV}", "plan"]

[tasks.terraform-apply]
dependencies = ["terraform-plan"]
command = "terraform"
args = [
"-chdir=./gcp/duckstream/environments/${ENV}",
"apply",
"--auto-approve",
]
40 changes: 40 additions & 0 deletions terraform/gcp/duckstream/modules/api/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
resource "google_cloud_run_service" "duckstream_api" {
name = var.service_name
location = var.default_region

template {
metadata {
annotations = {
"autoscaling.knative.dev/minScale" = "0"
"autoscaling.knative.dev/maxScale" = "1"
}
}
spec {
containers {
image = var.container_image
}
}
}

traffic {
percent = 100
latest_revision = true
}
}

data "google_iam_policy" "noauth" {
binding {
role = "roles/run.invoker"
members = [
"allUsers",
]
}
}

resource "google_cloud_run_service_iam_policy" "noauth" {
location = google_cloud_run_service.duckstream_api.location
project = google_cloud_run_service.duckstream_api.project
service = google_cloud_run_service.duckstream_api.name

policy_data = data.google_iam_policy.noauth.policy_data
}
5 changes: 5 additions & 0 deletions terraform/gcp/duckstream/modules/api/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
provider "google" {
credentials = var.credential_path
project = var.project_id
region = var.default_region
}
25 changes: 25 additions & 0 deletions terraform/gcp/duckstream/modules/api/variable.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
variable "project_id" {
description = "project id"
type = string
}

variable "default_region" {
description = "The default region for resources"
type = string
default = "asia-northeast1"
}

variable "service_name" {
description = "The name of the Cloud Run service"
type = string
}

variable "container_image" {
description = "The container image to run"
type = string
}

variable "credential_path" {
description = "The path to the service account key file"
type = string
}
9 changes: 9 additions & 0 deletions terraform/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_version = "~> 1.6.0"
required_providers {
google = {
source = "hashicorp/google"
version = "~> 5.2.0"
}
}
}

0 comments on commit 2e9c93e

Please sign in to comment.