-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
124 lines (103 loc) · 3.7 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
data "google_project" "user_project" {
}
locals {
project = data.google_project.user_project
region = var.default_region
network = (
var.create_network
? try(module.vpc_nextflow.0.network.network, null)
: try(data.google_compute_network.default.0, null)
)
subnet = (
var.create_network
? try(module.vpc_nextflow.0.subnets["${local.region}/${var.network_name}"], null)
: try(data.google_compute_subnetwork.default.0, null)
)
project_services = var.enable_services ? [
"compute.googleapis.com",
"cloudresourcemanager.googleapis.com",
"serviceusage.googleapis.com",
"servicenetworking.googleapis.com",
"iam.googleapis.com",
"batch.googleapis.com",
"logging.googleapis.com",
"lifesciences.googleapis.com"
] : []
}
resource "random_id" "default" {
byte_length = 2
}
####################
# nextflow Project #
####################
resource "google_project_service" "enabled_services" {
for_each = toset(local.project_services)
project = local.project.project_id
service = each.value
disable_dependent_services = true
disable_on_destroy = true
}
data "google_compute_default_service_account" "default" {
project = local.project.project_id
depends_on = [
google_project_service.enabled_services
]
}
resource "google_project_iam_member" "compute_service_account_roles" {
for_each = toset([
"roles/storage.objectAdmin",
"roles/batch.agentReporter"
])
project = local.project.project_id
role = each.value
member = "serviceAccount:${data.google_compute_default_service_account.default.email}"
}
resource "google_storage_bucket" "nextflow_workflow_bucket" {
name = "${local.project.project_id}-nextflow-wf-exec"
location = var.default_region
force_destroy = true
uniform_bucket_level_access = true
project = local.project.project_id
cors {
origin = ["http://user-scripts"]
method = ["GET", "HEAD", "PUT", "POST", "DELETE"]
response_header = ["*"]
max_age_seconds = 3600
}
}
resource "google_storage_bucket_object" "config" {
name = "provisioning/nextflow.config"
bucket = google_storage_bucket.nextflow_workflow_bucket.name
content = templatefile("scripts/build/nextflow.config", {
NEXTFLOW_PROJECT = local.project.project_id,
NEXTFLOW_WORK_DIR = "${google_storage_bucket.nextflow_workflow_bucket.url}/workdir",
NEXTFLOW_NETWORK = var.network_name
NEXTFLOW_SUBNET = var.subnet_name
NEXTFLOW_SERVICE_ACCOUNT = module.nextflow_service_account.email,
NEXTFLOW_LOCATION = var.nextflow_API_location,
NEXTFLOW_ZONE = var.nextflow_zone,
BUCKET_URL = google_storage_bucket.nextflow_workflow_bucket.url
})
}
resource "google_storage_bucket_object" "bootstrap" {
name = "provisioning/bootstrap.sh"
bucket = google_storage_bucket.nextflow_workflow_bucket.name
content = templatefile("scripts/build/bootstrap.sh", {
BUCKET_URL = google_storage_bucket.nextflow_workflow_bucket.url
})
}