Skip to content

Commit c580234

Browse files
Android Build Filesystem (ABFS) Teamsce-taid
authored andcommitted
Add support for custom Cloud Workstations images via Cloud Build.
Integrate the `cicd_pipelines` module to create Cloud Build triggers for custom images passed to the `cicd_workstations` module to enable custom image builds. PiperOrigin-RevId: 802049672
1 parent 9a0f552 commit c580234

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

examples/simple/variables.tf

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ variable "cws_clusters" {
155155
description = "A map of Cloud Workstation clusters to create. The key of the map is used as the unique ID for the cluster."
156156
default = {}
157157
validation {
158-
condition = !var.create_cloud_workstation_resources || length(var.cws_clusters) > 0
158+
condition = ! var.create_cloud_workstation_resources || length(var.cws_clusters) > 0
159159
error_message = "cws_clusters is required when create_cloud_workstation_resources is enabled."
160160
}
161161
}
@@ -175,15 +175,24 @@ variable "cws_configs" {
175175
persistent_disk_reclaim_policy = string
176176
creators = optional(list(string))
177177
image = optional(string)
178-
instances = optional(list(object({
178+
instances = optional(list(object({
179179
name = string
180180
users = list(string)
181181
})))
182182
}))
183183
description = "A map of Cloud Workstation configurations."
184184
default = {}
185185
validation {
186-
condition = !var.create_cloud_workstation_resources || length(var.cws_configs) > 0
186+
condition = ! var.create_cloud_workstation_resources || length(var.cws_configs) > 0
187187
error_message = "cws_configs is required when create_cloud_workstation_resources is enabled."
188188
}
189189
}
190+
191+
variable "cws_custom_images" {
192+
type = map(object({
193+
scheduler_region = optional(string)
194+
ci_schedule = optional(string)
195+
}))
196+
description = "Map of custom images and their Cloud Build trigger details to be used for Cloud Workstations. The key of the map equals the container image name."
197+
default = {}
198+
}

examples/simple/workstations.tf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
module "cicd_pipelines" {
16+
count = var.create_cloud_workstation_resources ? 1 : 0
17+
18+
source = "github.com/GoogleCloudPlatform/cicd-foundation//infra/modules/cicd_pipelines?ref=v2.1.0"
19+
20+
project_id = data.google_project.project.project_id
21+
apps = {
22+
for k in keys(var.cws_custom_images) : k => {
23+
runtime = "workstations"
24+
}
25+
}
26+
}
27+
1528
module "workstations" {
1629
count = var.create_cloud_workstation_resources ? 1 : 0
1730

@@ -21,4 +34,27 @@ module "workstations" {
2134
cws_scopes = var.cws_scopes
2235
cws_clusters = var.cws_clusters
2336
cws_configs = var.cws_configs
37+
custom_images = {
38+
for k, v in module.cicd_pipelines[0].cloud_build_trigger_trigger_id :
39+
k => merge(
40+
{
41+
ci_trigger = v
42+
},
43+
try({ scheduler_region = var.cws_custom_images[k]["scheduler_region"] }, {}),
44+
try({ ci_schedule = var.cws_custom_images[k]["ci_schedule"] }, {})
45+
)
46+
}
47+
cloud_build_service_account_id = module.cicd_pipelines[0].cloud_build_service_account_id
48+
}
49+
50+
resource "google_artifact_registry_repository_iam_binding" "reader" {
51+
count = var.create_cloud_workstation_resources ? 1 : 0
52+
53+
project = module.cicd_pipelines[0].artifact_registry_repository.project
54+
location = module.cicd_pipelines[0].artifact_registry_repository.location
55+
repository = module.cicd_pipelines[0].artifact_registry_repository.id
56+
role = "roles/artifactregistry.reader"
57+
members = [
58+
"serviceAccount:${module.workstations[0].cws_service_account_email}"
59+
]
2460
}

0 commit comments

Comments
 (0)