|
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +resource "google_compute_instance" "abfs_client" { |
| 16 | + count = var.create_client_instance_resource ? 1 : 0 |
| 17 | + |
| 18 | + project = var.project_id |
| 19 | + name = var.abfs_client_config.name |
| 20 | + zone = var.zone |
| 21 | + can_ip_forward = var.abfs_client_config.can_ip_forward |
| 22 | + deletion_protection = var.abfs_client_config.deletion_protection |
| 23 | + enable_display = var.abfs_client_config.enable_display |
| 24 | + machine_type = var.abfs_client_config.machine_type |
| 25 | + boot_disk { |
| 26 | + auto_delete = true |
| 27 | + device_name = var.abfs_client_config.name |
| 28 | + initialize_params { |
| 29 | + image = format( |
| 30 | + "projects/%s/global/images/%s", |
| 31 | + var.abfs_client_config.image_project, |
| 32 | + var.abfs_client_config.image_name |
| 33 | + ) |
| 34 | + size = var.abfs_client_config.size |
| 35 | + type = var.abfs_client_config.type |
| 36 | + } |
| 37 | + mode = "READ_WRITE" |
| 38 | + } |
| 39 | + metadata = var.abfs_client_config.enable_oslogin ? { |
| 40 | + enable-osconfig = "TRUE" |
| 41 | + enable-oslogin = "true" |
| 42 | + } : {} |
| 43 | + network_interface { |
| 44 | + access_config { |
| 45 | + network_tier = "PREMIUM" |
| 46 | + } |
| 47 | + queue_count = 0 |
| 48 | + stack_type = "IPV4_ONLY" |
| 49 | + subnetwork = module.abfs_vpc.subnets["${var.region}/${var.abfs_subnet_name}"].self_link |
| 50 | + } |
| 51 | + scheduling { |
| 52 | + automatic_restart = var.abfs_client_config.automatic_restart |
| 53 | + on_host_maintenance = var.abfs_client_config.preemptible ? "TERMINATE" : "MIGRATE" |
| 54 | + preemptible = var.abfs_client_config.preemptible |
| 55 | + provisioning_model = var.abfs_client_config.preemptible ? "SPOT" : "STANDARD" |
| 56 | + } |
| 57 | + service_account { |
| 58 | + email = local.abfs_service_account_email |
| 59 | + scopes = var.abfs_client_config.scopes |
| 60 | + } |
| 61 | + shielded_instance_config { |
| 62 | + enable_integrity_monitoring = var.abfs_client_config.shielded_instance_config.enable_integrity_monitoring |
| 63 | + enable_secure_boot = var.abfs_client_config.shielded_instance_config.enable_secure_boot |
| 64 | + enable_vtpm = var.abfs_client_config.shielded_instance_config.enable_vtpm |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +module "ops_agent_policy" { |
| 69 | + count = var.create_client_instance_resource ? 1 : 0 |
| 70 | + |
| 71 | + source = "github.com/terraform-google-modules/terraform-google-cloud-operations/modules/ops-agent-policy?ref=v0.6.0" |
| 72 | + |
| 73 | + project = google_compute_instance.abfs_client[0].project |
| 74 | + zone = google_compute_instance.abfs_client[0].zone |
| 75 | + assignment_id = format( |
| 76 | + "goog-ops-agent-%s-%s", |
| 77 | + var.abfs_client_config.goog_ops_agent_policy, |
| 78 | + google_compute_instance.abfs_client[0].zone |
| 79 | + ) |
| 80 | + agents_rule = { |
| 81 | + package_state = "installed" |
| 82 | + version = "latest" |
| 83 | + } |
| 84 | + instance_filter = { |
| 85 | + all = false |
| 86 | + inclusion_labels = [{ |
| 87 | + labels = { |
| 88 | + goog-ops-agent-policy = var.abfs_client_config.goog_ops_agent_policy |
| 89 | + } |
| 90 | + }] |
| 91 | + } |
| 92 | +} |
0 commit comments