Files
hunfabric/fast/project-templates/devops-azure-wif/self-hosted-agents/main.tf
Ludovico Magnocavallo a4eb4d24fd Compute VM module refactor (#3805)
* add ad for compute-vm refactor

* Exclue nic_type from validated fields, add split of main.tf and template.tf

* boot disk

* fix examples and fixtures

* attached disks

* fix further examples and module-level tests

* remove extra file

* fix mig examples

* finish refactoring variables

* align fast and other modules

* refactor(compute-vm): align examples and ADR with the newly implemented interface

This commit addresses the remaining references of the `instance_type` and `confidential_compute` parameters in the testing environment and updates the ADR.

* feat(compute-vm): add network_performance_config to instance and templates

This change implements the usage of the `network_performance_tier` variable we added earlier into the actual Terraform resources.

---------

Co-authored-by: Wiktor Niesiobędzki <wiktorn@google.com>
2026-03-26 11:31:40 +00:00

98 lines
2.7 KiB
HCL

/**
* Copyright 2026 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.
*/
locals {
cloud_config = !local.create_instance ? null : templatefile(
"${path.module}/cloud-config.yaml", merge(var.agent_config, {
image = var.instance_config.docker_image
location = var.location
name = var.name
project_id = var.project_id
})
)
create_instance = (
try(var.instance_config.docker_image, null) == null ? false : true
)
}
module "registry" {
source = "../../../../modules/artifact-registry"
project_id = var.project_id
location = var.location
name = "${var.name}-docker"
format = {
docker = {
standard = {}
}
}
iam = var.instance_config == null ? {} : {
"roles/artifactregistry.reader" = [
"serviceAccount:${var.instance_config.service_account}"
]
}
}
module "secret" {
source = "../../../../modules/secret-manager"
project_id = var.project_id
secrets = {
(var.name) = {
iam = var.instance_config == null ? {} : {
"roles/secretmanager.secretAccessor" = [
"serviceAccount:${var.instance_config.service_account}"
]
}
versions = {
"v-${var.agent_config.token.version}" = {
data = try(file(var.agent_config.token.file), null)
data_config = {
write_only_version = var.agent_config.token.version
}
}
}
}
}
}
module "instance" {
source = "../../../../modules/compute-vm"
count = local.create_instance ? 1 : 0
project_id = var.project_id
zone = "${var.location}-${var.instance_config.zone}"
name = "${var.name}-agent"
machine_type = "e2-micro"
boot_disk = {
auto_delete = false
source = {
image = "projects/cos-cloud/global/images/family/cos-117-lts"
}
initialize_params = {
size = 10
}
}
network_interfaces = [{
network = var.instance_config.vpc_config.network
subnetwork = var.instance_config.vpc_config.subnetwork
}]
metadata = {
user-data = local.cloud_config
}
service_account = {
email = var.instance_config.service_account
}
depends_on = [module.secret]
}