-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
36 lines (30 loc) · 1.33 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Use this data source to get project details. For more information see API.
# https://www.terraform.io/docs/providers/google/d/google_project.html
data "google_project" "project" {}
# Create Git repository
# https://www.terraform.io/docs/providers/google/r/sourcerepo_repository.html
resource "google_sourcerepo_repository" "new_git_repository" {
name = "${var.repository}"
}
# Create CloudBuild Trigger
# https://www.terraform.io/docs/providers/google/r/cloudbuild_trigger.html
resource "google_cloudbuild_trigger" "new_git_build_trigger" {
count = "${length(var.triggers)}"
description = "Trigger Git repository ${var.repository} / ${lookup(var.triggers[count.index], "branch", "master")}"
trigger_template {
project = "${data.google_project.project.project_id}"
branch_name = "${lookup(var.triggers[count.index], "branch", "master")}"
repo_name = "${var.repository}"
}
build {
images = ["gcr.io/$PROJECT_ID/$REPO_NAME:${lookup(var.triggers[count.index], "tag_type", "$BRANCH_NAME")}"]
step {
name = "gcr.io/cloud-builders/docker"
args = "build -t gcr.io/$PROJECT_ID/$REPO_NAME:${lookup(var.triggers[count.index], "tag_type", "$BRANCH_NAME")} -f Dockerfile ."
}
}
# Google Git repository has been created.
depends_on = [
"google_sourcerepo_repository.new_git_repository",
]
}