terraformの必要なファイルを設定
This commit is contained in:
parent
c38992d942
commit
27c1c461e8
11
readme/deploy.md
Normal file
11
readme/deploy.md
Normal file
@ -0,0 +1,11 @@
|
||||
# デプロイの方法について
|
||||
|
||||
## 環境について
|
||||
|
||||
* terraform
|
||||
* google cloud
|
||||
* Cloud Run Job
|
||||
|
||||
|
||||
|
||||
|
||||
5
terraform/af.tf
Normal file
5
terraform/af.tf
Normal file
@ -0,0 +1,5 @@
|
||||
resource "google_artifact_registry_repository" "repo" {
|
||||
location = var.region
|
||||
repository_id = "cicd-repo-${var.env_name}"
|
||||
format = "DOCKER"
|
||||
}
|
||||
10
terraform/platform.tf
Normal file
10
terraform/platform.tf
Normal file
@ -0,0 +1,10 @@
|
||||
# Google CloudのAPIを有効化
|
||||
|
||||
resource "google_project_service" "services" {
|
||||
for_each = toset([
|
||||
"run.googleapis.com",
|
||||
"artifactregistry.googleapis.com",
|
||||
"cloudbuild.googleapis.com",
|
||||
])
|
||||
service = each.key
|
||||
}
|
||||
5
terraform/provider.tf
Normal file
5
terraform/provider.tf
Normal file
@ -0,0 +1,5 @@
|
||||
# Google Providerの設定
|
||||
provider "google" {
|
||||
project = var.project_id
|
||||
region = var.region
|
||||
}
|
||||
30
terraform/run_job.tf
Normal file
30
terraform/run_job.tf
Normal file
@ -0,0 +1,30 @@
|
||||
# Cloud Run Jobのリソース
|
||||
resource "google_cloud_run_job" "job" {
|
||||
name = "${var.job_name}-${var.env_name}-job"
|
||||
location = var.region
|
||||
|
||||
# サービスアカウントを指定
|
||||
service_account = google_service_account.job_sa.email
|
||||
|
||||
template {
|
||||
template {
|
||||
containers {
|
||||
image = var.container_image
|
||||
|
||||
resources {
|
||||
limits = {
|
||||
cpu = var.cpu_limit
|
||||
memory = var.memory_limit
|
||||
}
|
||||
}
|
||||
|
||||
# env {
|
||||
# 必要に応じ環境変数を設定
|
||||
# name = "ENV_VAR_NAME"
|
||||
# }
|
||||
}
|
||||
timeout_seconds = var.timeout_seconds
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
14
terraform/sa.tf
Normal file
14
terraform/sa.tf
Normal file
@ -0,0 +1,14 @@
|
||||
resource "google_service_account" "job_sa" {
|
||||
account_id = "sa-${var.job_name}-${var.env_name}"
|
||||
display_name = "Cloud Run Job Service Account for ${var.job_name} in ${var.env_name} environment"
|
||||
description = "Cloud Run Job Service Account for ${var.job_name} in ${var.env_name} environment"
|
||||
project = var.project_id
|
||||
}
|
||||
|
||||
# IAM role assignment
|
||||
# Cloud Run Job実行に必要な権限を付与
|
||||
resource "google_project_iam_member" "run_job_invoker" {
|
||||
project = var.project_id
|
||||
role = "roles/run.invoker"
|
||||
member = "serviceAccount:${google_service_account.job_sa.email}"
|
||||
}
|
||||
10
terraform/sample.tfvars
Normal file
10
terraform/sample.tfvars
Normal file
@ -0,0 +1,10 @@
|
||||
project_id = "プロジェクトIDを指定してください"
|
||||
region = "asia-northeast1"
|
||||
env_name = "dev"
|
||||
|
||||
job_name = "ジョブ名を指定してください"
|
||||
# コンテナイメージ(CI/CDから渡される想定)
|
||||
|
||||
cpu_limit = "1"
|
||||
memory_limit = "512Mi"
|
||||
timeout_seconds = 900
|
||||
53
terraform/variables.tf
Normal file
53
terraform/variables.tf
Normal file
@ -0,0 +1,53 @@
|
||||
# GCPプロジェクトIDとリージョン、環境名、ジョブ名の変数定義
|
||||
variable "project_id" {
|
||||
description = "The ID of the GCP project to deploy resources into."
|
||||
type = string
|
||||
}
|
||||
variable "region" {
|
||||
description = "The GCP region to deploy resources into."
|
||||
type = string
|
||||
default = "asia-northeast1" # 東京
|
||||
}
|
||||
|
||||
variable "env_name" {
|
||||
description = "The environment name for the deployment."
|
||||
type = string
|
||||
default = "dev"
|
||||
validation {
|
||||
condition = contains(["dev", "staging", "prd"], var.env_name)
|
||||
error_message = "env_name must be one of: dev, staging, prd."
|
||||
}
|
||||
}
|
||||
|
||||
variable "job_name" {
|
||||
description = "The name of the Cloud Run Job."
|
||||
type = string
|
||||
default = "get-news-ai"
|
||||
}
|
||||
|
||||
|
||||
# コンテナイメージの変数定義(CI/CDから渡される想定)
|
||||
variable "container_image" {
|
||||
description = "The container image for the Cloud Run Job."
|
||||
type = string
|
||||
}
|
||||
|
||||
|
||||
# Cloud Run Jobの設定変数
|
||||
variable "cpu_limit" {
|
||||
description = "The CPU limit for the Cloud Run Job container."
|
||||
type = string
|
||||
default = "1"
|
||||
}
|
||||
|
||||
variable "memory_limit" {
|
||||
description = "The memory limit for the Cloud Run Job container."
|
||||
type = string
|
||||
default = "512Mi"
|
||||
}
|
||||
|
||||
variable "timeout_seconds" {
|
||||
description = "The timeout for the Cloud Run Job."
|
||||
type = number
|
||||
default = 300
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user