From cec1c3d6863b584e6bca35efdde6f5e1b9ff5247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Dost=C3=A1l?= Date: Fri, 19 Jan 2024 09:55:23 +0100 Subject: [PATCH] PC: Lint Terraform --- data/publiccloud/terraform/azure.tf | 172 +++++++++--------- data/publiccloud/terraform/azure_nfstest.tf | 146 ++++++++-------- data/publiccloud/terraform/ec2.tf | 132 +++++++------- data/publiccloud/terraform/gce.tf | 184 ++++++++++---------- data/publiccloud/terraform/openstack.tf | 90 +++++----- 5 files changed, 362 insertions(+), 362 deletions(-) diff --git a/data/publiccloud/terraform/azure.tf b/data/publiccloud/terraform/azure.tf index a2f410efce4e..84a8d8b7dc97 100644 --- a/data/publiccloud/terraform/azure.tf +++ b/data/publiccloud/terraform/azure.tf @@ -2,163 +2,163 @@ terraform { required_providers { azurerm = { version = "= 3.48.0" - source = "hashicorp/azurerm" + source = "hashicorp/azurerm" } random = { version = "= 3.1.0" - source = "hashicorp/random" + source = "hashicorp/random" } } } provider "azurerm" { - features {} + features {} } variable "instance_count" { - default = "1" + default = "1" } variable "name" { - default = "openqa-vm" + default = "openqa-vm" } variable "type" { - default = "Standard_B2s" + default = "Standard_B2s" } variable "region" { - default = "westeurope" + default = "westeurope" } variable "image_id" { - default = "" + default = "" } variable "image_uri" { - default = "" + default = "" } variable "publisher" { - default="SUSE" + default = "SUSE" } variable "offer" { - default="" + default = "" } variable "sku" { - default="gen2" + default = "gen2" } variable "extra-disk-size" { - default = "100" + default = "100" } variable "extra-disk-type" { - default = "Premium_LRS" + default = "Premium_LRS" } variable "create-extra-disk" { - default=false + default = false } variable "storage-account" { - # Note: Don't delete the default value!!! - # Not all of our `terraform destroy` calls pass this variable and neither is it necessary. - # However removing the default value might cause `terraform destroy` to fail in corner cases, - # resulting effectively in leaking resources due to failed cleanups. - default="eisleqaopenqa" + # Note: Don't delete the default value!!! + # Not all of our `terraform destroy` calls pass this variable and neither is it necessary. + # However removing the default value might cause `terraform destroy` to fail in corner cases, + # resulting effectively in leaking resources due to failed cleanups. + default = "eisleqaopenqa" } variable "tags" { - type = map(string) - default = {} + type = map(string) + default = {} } variable "vm_create_timeout" { - default = "20m" + default = "20m" } variable "subnet_id" { - default = "" + default = "" } resource "random_id" "service" { - count = var.instance_count - keepers = { - name = var.name - } - byte_length = 8 + count = var.instance_count + keepers = { + name = var.name + } + byte_length = 8 } resource "azurerm_resource_group" "openqa-group" { - name = "${var.name}-${element(random_id.service.*.hex, 0)}" - location = var.region + name = "${var.name}-${element(random_id.service.*.hex, 0)}" + location = var.region - tags = merge({ - openqa_created_by = var.name - openqa_created_date = timestamp() - openqa_created_id = element(random_id.service.*.hex, 0) - }, var.tags) + tags = merge({ + openqa_created_by = var.name + openqa_created_date = timestamp() + openqa_created_id = element(random_id.service.*.hex, 0) + }, var.tags) } resource "azurerm_public_ip" "openqa-publicip" { - name = "${var.name}-${element(random_id.service.*.hex, count.index)}-public-ip" - location = var.region - resource_group_name = azurerm_resource_group.openqa-group.name - allocation_method = "Dynamic" - count = var.instance_count + name = "${var.name}-${element(random_id.service.*.hex, count.index)}-public-ip" + location = var.region + resource_group_name = azurerm_resource_group.openqa-group.name + allocation_method = "Dynamic" + count = var.instance_count } resource "azurerm_network_interface" "openqa-nic" { - name = "${var.name}-${element(random_id.service.*.hex, count.index)}-nic" - location = var.region - resource_group_name = azurerm_resource_group.openqa-group.name - count = var.instance_count - - ip_configuration { - name = "${element(random_id.service.*.hex, count.index)}-nic-config" - subnet_id = "${var.subnet_id}" - private_ip_address_allocation = "Dynamic" - public_ip_address_id = element(azurerm_public_ip.openqa-publicip.*.id, count.index) - } + name = "${var.name}-${element(random_id.service.*.hex, count.index)}-nic" + location = var.region + resource_group_name = azurerm_resource_group.openqa-group.name + count = var.instance_count + + ip_configuration { + name = "${element(random_id.service.*.hex, count.index)}-nic-config" + subnet_id = var.subnet_id + private_ip_address_allocation = "Dynamic" + public_ip_address_id = element(azurerm_public_ip.openqa-publicip.*.id, count.index) + } } resource "azurerm_image" "image" { - name = "${azurerm_resource_group.openqa-group.name}-disk1" - location = var.region - resource_group_name = azurerm_resource_group.openqa-group.name - hyper_v_generation = var.sku == "gen1" ? "V1" : "V2" - count = var.image_id != "" ? 1 : 0 - - os_disk { - os_type = "Linux" - os_state = "Generalized" - blob_uri = "https://${var.storage-account}.blob.core.windows.net/sle-images/${var.image_id}" - size_gb = 30 - } + name = "${azurerm_resource_group.openqa-group.name}-disk1" + location = var.region + resource_group_name = azurerm_resource_group.openqa-group.name + hyper_v_generation = var.sku == "gen1" ? "V1" : "V2" + count = var.image_id != "" ? 1 : 0 + + os_disk { + os_type = "Linux" + os_state = "Generalized" + blob_uri = "https://${var.storage-account}.blob.core.windows.net/sle-images/${var.image_id}" + size_gb = 30 + } } resource "azurerm_linux_virtual_machine" "openqa-vm" { - name = "${var.name}-${element(random_id.service.*.hex, count.index)}" - resource_group_name = azurerm_resource_group.openqa-group.name - location = var.region - size = var.type - computer_name = "${var.name}-${element(random_id.service.*.hex, count.index)}" - admin_username = "azureuser" + name = "${var.name}-${element(random_id.service.*.hex, count.index)}" + resource_group_name = azurerm_resource_group.openqa-group.name + location = var.region + size = var.type + computer_name = "${var.name}-${element(random_id.service.*.hex, count.index)}" + admin_username = "azureuser" disable_password_authentication = true - count = var.instance_count + count = var.instance_count network_interface_ids = [azurerm_network_interface.openqa-nic[count.index].id] tags = merge({ - openqa_created_by = var.name - openqa_created_date = timestamp() - openqa_created_id = element(random_id.service.*.hex, count.index) - }, var.tags) + openqa_created_by = var.name + openqa_created_date = timestamp() + openqa_created_id = element(random_id.service.*.hex, count.index) + }, var.tags) admin_ssh_key { username = "azureuser" @@ -196,15 +196,15 @@ resource "azurerm_linux_virtual_machine" "openqa-vm" { } resource "azurerm_virtual_machine_data_disk_attachment" "default" { - count = var.create-extra-disk ? var.instance_count: 0 - managed_disk_id = element(azurerm_managed_disk.ssd_disk.*.id, count.index) - virtual_machine_id = element(azurerm_linux_virtual_machine.openqa-vm.*.id, count.index) - lun = "1" - caching = "ReadWrite" + count = var.create-extra-disk ? var.instance_count : 0 + managed_disk_id = element(azurerm_managed_disk.ssd_disk.*.id, count.index) + virtual_machine_id = element(azurerm_linux_virtual_machine.openqa-vm.*.id, count.index) + lun = "1" + caching = "ReadWrite" } resource "azurerm_managed_disk" "ssd_disk" { - count = var.create-extra-disk ? var.instance_count: 0 + count = var.create-extra-disk ? var.instance_count : 0 name = "ssd-disk-${element(random_id.service.*.hex, count.index)}" location = azurerm_resource_group.openqa-group.location resource_group_name = azurerm_resource_group.openqa-group.name @@ -215,15 +215,15 @@ resource "azurerm_managed_disk" "ssd_disk" { output "vm_name" { - value = azurerm_linux_virtual_machine.openqa-vm.*.id + value = azurerm_linux_virtual_machine.openqa-vm.*.id } data "azurerm_public_ip" "openqa-publicip" { - name = azurerm_public_ip.openqa-publicip[count.index].name - resource_group_name = azurerm_linux_virtual_machine.openqa-vm.0.resource_group_name - count = var.instance_count + name = azurerm_public_ip.openqa-publicip[count.index].name + resource_group_name = azurerm_linux_virtual_machine.openqa-vm.0.resource_group_name + count = var.instance_count } output "public_ip" { - value = data.azurerm_public_ip.openqa-publicip.*.ip_address + value = data.azurerm_public_ip.openqa-publicip.*.ip_address } diff --git a/data/publiccloud/terraform/azure_nfstest.tf b/data/publiccloud/terraform/azure_nfstest.tf index 518d8d3ea76d..6d903a26473e 100644 --- a/data/publiccloud/terraform/azure_nfstest.tf +++ b/data/publiccloud/terraform/azure_nfstest.tf @@ -2,17 +2,17 @@ terraform { required_providers { azurerm = { version = ">= 3.2.0" - source = "hashicorp/azurerm" + source = "hashicorp/azurerm" } random = { version = "= 3.1.0" - source = "hashicorp/random" + source = "hashicorp/random" } } } provider "azurerm" { - features {} + features {} } ## ---- variables ----------------------------------------------------------- ## @@ -20,45 +20,45 @@ provider "azurerm" { ## general variables variable "name" { - default = "openqa-vm" + default = "openqa-vm" } variable "tags" { - type = map(string) - default = {} + type = map(string) + default = {} } variable "region" { - default = "westeurope" + default = "westeurope" } ## vm-instance variables variable "instance_count" { - default = "1" + default = "1" } variable "type" { - default = "Standard_B2s" + default = "Standard_B2s" } variable "image_id" { - default = "" + default = "" } variable "offer" { - default="" + default = "" } variable "sku" { - default="gen2" + default = "gen2" } variable "vm_create_timeout" { - default = "20m" + default = "20m" } variable "subnet_id" { - default = "" + default = "" } ## ---- data ---------------------------------------------------------------- ## @@ -71,47 +71,47 @@ data "http" "myip" { ## -------------------------------------------------------------------------- ## resource "random_id" "service" { - keepers = { - name = var.name - } - byte_length = 8 + keepers = { + name = var.name + } + byte_length = 8 } ## resource group resource "azurerm_resource_group" "openqa-group" { - name = "${var.name}-${element(random_id.service.*.hex, 0)}" - location = var.region + name = "${var.name}-${element(random_id.service.*.hex, 0)}" + location = var.region - tags = merge({ - openqa_created_by = var.name - openqa_created_date = timestamp() - openqa_created_id = element(random_id.service.*.hex, 0) - }, var.tags) + tags = merge({ + openqa_created_by = var.name + openqa_created_date = timestamp() + openqa_created_id = element(random_id.service.*.hex, 0) + }, var.tags) } ## virtual network resource "azurerm_public_ip" "openqa-publicip" { - name = "${azurerm_resource_group.openqa-group.name}-public-ip" - location = var.region - resource_group_name = azurerm_resource_group.openqa-group.name - allocation_method = "Dynamic" - count = var.instance_count + name = "${azurerm_resource_group.openqa-group.name}-public-ip" + location = var.region + resource_group_name = azurerm_resource_group.openqa-group.name + allocation_method = "Dynamic" + count = var.instance_count } resource "azurerm_network_interface" "openqa-nic" { - name = "${azurerm_resource_group.openqa-group.name}-nic" - location = var.region - resource_group_name = azurerm_resource_group.openqa-group.name - count = var.instance_count - - ip_configuration { - name = "${element(random_id.service.*.hex, count.index)}-nic-config" - subnet_id = "${var.subnet_id}" - private_ip_address_allocation = "Dynamic" - public_ip_address_id = element(azurerm_public_ip.openqa-publicip.*.id, count.index) - } + name = "${azurerm_resource_group.openqa-group.name}-nic" + location = var.region + resource_group_name = azurerm_resource_group.openqa-group.name + count = var.instance_count + + ip_configuration { + name = "${element(random_id.service.*.hex, count.index)}-nic-config" + subnet_id = var.subnet_id + private_ip_address_allocation = "Dynamic" + public_ip_address_id = element(azurerm_public_ip.openqa-publicip.*.id, count.index) + } } ## storage and NFS share @@ -120,7 +120,7 @@ resource "azurerm_storage_account" "openqa-group" { name = "storage${element(random_id.service.*.hex, 0)}" resource_group_name = azurerm_resource_group.openqa-group.name location = azurerm_resource_group.openqa-group.location - account_tier = "Premium" # Required for NFS share + account_tier = "Premium" # Required for NFS share account_replication_type = "LRS" account_kind = "FileStorage" enable_https_traffic_only = false @@ -134,9 +134,9 @@ resource "azurerm_storage_account_network_rules" "openqa-group" { virtual_network_subnet_ids = [azurerm_subnet.openqa-subnet.id] // AZURE LIMITATION: After setting Deny, we need to allow this host otherwise we cannot do changes or delete the resources ip_rules = [chomp(data.http.myip.response_body)] - + private_link_access { - endpoint_resource_id = azurerm_subnet.openqa-subnet.id + endpoint_resource_id = azurerm_subnet.openqa-subnet.id } } @@ -151,37 +151,37 @@ resource "azurerm_storage_share" "openqa-group" { ## virtual machine resource "azurerm_image" "image" { - name = "${azurerm_resource_group.openqa-group.name}-disk1" - location = var.region - resource_group_name = azurerm_resource_group.openqa-group.name - count = var.image_id != "" ? 1 : 0 - - os_disk { - os_type = "Linux" - os_state = "Generalized" - blob_uri = "https://openqa.blob.core.windows.net/sle-images/${var.image_id}" - size_gb = 30 - } + name = "${azurerm_resource_group.openqa-group.name}-disk1" + location = var.region + resource_group_name = azurerm_resource_group.openqa-group.name + count = var.image_id != "" ? 1 : 0 + + os_disk { + os_type = "Linux" + os_state = "Generalized" + blob_uri = "https://openqa.blob.core.windows.net/sle-images/${var.image_id}" + size_gb = 30 + } } resource "azurerm_linux_virtual_machine" "openqa-vm" { - name = "${var.name}-${element(random_id.service.*.hex, count.index)}" - resource_group_name = azurerm_resource_group.openqa-group.name - location = var.region - size = var.type - computer_name = "${var.name}-${element(random_id.service.*.hex, count.index)}" - admin_username = "azureuser" + name = "${var.name}-${element(random_id.service.*.hex, count.index)}" + resource_group_name = azurerm_resource_group.openqa-group.name + location = var.region + size = var.type + computer_name = "${var.name}-${element(random_id.service.*.hex, count.index)}" + admin_username = "azureuser" disable_password_authentication = true - count = var.instance_count + count = var.instance_count network_interface_ids = [azurerm_network_interface.openqa-nic[count.index].id] tags = merge({ - openqa_created_by = var.name - openqa_created_date = timestamp() - openqa_created_id = element(random_id.service.*.hex, count.index) - }, var.tags) + openqa_created_by = var.name + openqa_created_date = timestamp() + openqa_created_id = element(random_id.service.*.hex, count.index) + }, var.tags) admin_ssh_key { username = "azureuser" @@ -197,7 +197,7 @@ resource "azurerm_linux_virtual_machine" "openqa-vm" { # disk_size_gb = 30 } - source_image_id = var.image_id != "" ? azurerm_image.image.0.id : null + source_image_id = var.image_id != "" ? azurerm_image.image.0.id : null dynamic "source_image_reference" { for_each = range(var.image_id != "" ? 0 : 1) content { @@ -214,19 +214,19 @@ resource "azurerm_linux_virtual_machine" "openqa-vm" { } output "vm_name" { - value = azurerm_linux_virtual_machine.openqa-vm.*.id + value = azurerm_linux_virtual_machine.openqa-vm.*.id } data "azurerm_public_ip" "openqa-publicip" { - name = azurerm_public_ip.openqa-publicip[count.index].name - resource_group_name = azurerm_linux_virtual_machine.openqa-vm.0.resource_group_name - count = var.instance_count + name = azurerm_public_ip.openqa-publicip[count.index].name + resource_group_name = azurerm_linux_virtual_machine.openqa-vm.0.resource_group_name + count = var.instance_count } output "public_ip" { - value = data.azurerm_public_ip.openqa-publicip.*.ip_address + value = data.azurerm_public_ip.openqa-publicip.*.ip_address } output "resource_id" { - value = "${element(random_id.service.*.hex, 0)}" + value = element(random_id.service.*.hex, 0) } diff --git a/data/publiccloud/terraform/ec2.tf b/data/publiccloud/terraform/ec2.tf index bda6e639bdc1..e3ead82997fb 100644 --- a/data/publiccloud/terraform/ec2.tf +++ b/data/publiccloud/terraform/ec2.tf @@ -2,144 +2,144 @@ terraform { required_providers { aws = { version = "= 5.14.0" - source = "hashicorp/aws" + source = "hashicorp/aws" } random = { version = "= 3.1.0" - source = "hashicorp/random" + source = "hashicorp/random" } } } variable "region" { - default = "eu-central-1" + default = "eu-central-1" } provider "aws" { - region = var.region + region = var.region } variable "instance_count" { - default = "1" + default = "1" } variable "name" { - default = "openqa-vm" + default = "openqa-vm" } variable "type" { - default = "t2.large" + default = "t2.large" } variable "image_id" { - default = "" + default = "" } variable "extra-disk-size" { - default = "1000" + default = "1000" } variable "extra-disk-type" { - default = "gp2" + default = "gp2" } variable "create-extra-disk" { - default=false + default = false } variable "tags" { - type = map(string) - default = {} + type = map(string) + default = {} } variable "vm_create_timeout" { - default = "20m" + default = "20m" } variable "enable_confidential_vm" { - default = "disabled" + default = "disabled" } variable "vpc_security_group_ids" { - default = "" + default = "" } variable "subnet_id" { - default = "" + default = "" } variable "ipv6_address_count" { - default = 0 + default = 0 } resource "random_id" "service" { - count = var.instance_count - keepers = { - name = var.name - } - byte_length = 8 + count = var.instance_count + keepers = { + name = var.name + } + byte_length = 8 } resource "aws_key_pair" "openqa-keypair" { - key_name = "openqa-${element(random_id.service.*.hex, 0)}" - public_key = file("/root/.ssh/id_rsa.pub") + key_name = "openqa-${element(random_id.service.*.hex, 0)}" + public_key = file("/root/.ssh/id_rsa.pub") } resource "aws_instance" "openqa" { - count = var.instance_count - ami = var.image_id - instance_type = var.type - key_name = aws_key_pair.openqa-keypair.key_name - vpc_security_group_ids = [var.vpc_security_group_ids] - subnet_id = var.subnet_id - ipv6_address_count = var.ipv6_address_count - - tags = merge({ - openqa_created_by = var.name - openqa_created_date = timestamp() - openqa_created_id = element(random_id.service.*.hex, count.index) - }, var.tags) - - ebs_block_device { - device_name = "/dev/sda1" - volume_size = 20 - } + count = var.instance_count + ami = var.image_id + instance_type = var.type + key_name = aws_key_pair.openqa-keypair.key_name + vpc_security_group_ids = [var.vpc_security_group_ids] + subnet_id = var.subnet_id + ipv6_address_count = var.ipv6_address_count + + tags = merge({ + openqa_created_by = var.name + openqa_created_date = timestamp() + openqa_created_id = element(random_id.service.*.hex, count.index) + }, var.tags) + + ebs_block_device { + device_name = "/dev/sda1" + volume_size = 20 + } - timeouts { - create = var.vm_create_timeout - } + timeouts { + create = var.vm_create_timeout + } - dynamic "cpu_options" { - for_each = var.enable_confidential_vm == "disabled" ? [] : [1] - content { - amd_sev_snp = var.enable_confidential_vm - } + dynamic "cpu_options" { + for_each = var.enable_confidential_vm == "disabled" ? [] : [1] + content { + amd_sev_snp = var.enable_confidential_vm } + } } resource "aws_volume_attachment" "ebs_att" { - count = var.create-extra-disk ? var.instance_count: 0 - device_name = "/dev/sdb" - volume_id = element(aws_ebs_volume.ssd_disk.*.id, count.index) - instance_id = element(aws_instance.openqa.*.id, count.index) + count = var.create-extra-disk ? var.instance_count : 0 + device_name = "/dev/sdb" + volume_id = element(aws_ebs_volume.ssd_disk.*.id, count.index) + instance_id = element(aws_instance.openqa.*.id, count.index) } resource "aws_ebs_volume" "ssd_disk" { - count = var.create-extra-disk ? var.instance_count : 0 - availability_zone = element(aws_instance.openqa.*.availability_zone, count.index) - size = var.extra-disk-size - type = var.extra-disk-type - tags = merge({ - openqa_created_by = var.name - openqa_created_date = timestamp() - openqa_created_id = element(random_id.service.*.hex, count.index) - }, var.tags) + count = var.create-extra-disk ? var.instance_count : 0 + availability_zone = element(aws_instance.openqa.*.availability_zone, count.index) + size = var.extra-disk-size + type = var.extra-disk-type + tags = merge({ + openqa_created_by = var.name + openqa_created_date = timestamp() + openqa_created_id = element(random_id.service.*.hex, count.index) + }, var.tags) } output "public_ip" { - value = aws_instance.openqa.*.public_ip + value = aws_instance.openqa.*.public_ip } output "vm_name" { - value = aws_instance.openqa.*.id + value = aws_instance.openqa.*.id } diff --git a/data/publiccloud/terraform/gce.tf b/data/publiccloud/terraform/gce.tf index a8fc0e881b50..09f3284d4063 100644 --- a/data/publiccloud/terraform/gce.tf +++ b/data/publiccloud/terraform/gce.tf @@ -2,80 +2,80 @@ terraform { required_providers { google = { version = "= 4.57.0" - source = "hashicorp/google" + source = "hashicorp/google" } random = { version = "= 3.1.0" - source = "hashicorp/random" + source = "hashicorp/random" } external = { version = "= 2.1.0" - source = "hashicorp/external" + source = "hashicorp/external" } } } variable "cred_file" { - default = "/root/google_credentials.json" + default = "/root/google_credentials.json" } provider "google" { - credentials = var.cred_file - project = var.project + credentials = var.cred_file + project = var.project } data "external" "gce_cred" { - program = [ "cat", var.cred_file ] - query = { } + program = ["cat", var.cred_file] + query = {} } variable "instance_count" { - default = "1" + default = "1" } variable "name" { - default = "openqa-vm" + default = "openqa-vm" } variable "type" { - default = "n1-standard-2" + default = "n1-standard-2" } variable "region" { - default = "europe-west1-b" + default = "europe-west1-b" } variable "image_id" { - default = "" + default = "" } variable "project" { - default = "suse-sle-qa" + default = "suse-sle-qa" } variable "extra-disk-size" { - default = "1000" + default = "1000" } variable "extra-disk-type" { - default = "pd-ssd" + default = "pd-ssd" } variable "create-extra-disk" { - default=false + default = false } variable "uefi" { - default=false + default = false } variable "tags" { - type = map(string) - default = {} + type = map(string) + default = {} } variable "enable_confidential_vm" { - default=false + default = false } variable "gpu" { @@ -85,104 +85,104 @@ variable "gpu" { } variable "vm_create_timeout" { - default = "20m" + default = "20m" } resource "random_id" "service" { - count = var.instance_count - keepers = { - name = var.name - } - byte_length = 8 + count = var.instance_count + keepers = { + name = var.name + } + byte_length = 8 } resource "google_compute_instance" "openqa" { - count = var.instance_count - name = "${var.name}-${element(random_id.service.*.hex, count.index)}" - machine_type = var.type - zone = var.region - - guest_accelerator { - type = "nvidia-tesla-t4" - count = var.gpu ? 1 : 0 - } + count = var.instance_count + name = "${var.name}-${element(random_id.service.*.hex, count.index)}" + machine_type = var.type + zone = var.region + + guest_accelerator { + type = "nvidia-tesla-t4" + count = var.gpu ? 1 : 0 + } - confidential_instance_config { - enable_confidential_compute = var.enable_confidential_vm ? true : false - } + confidential_instance_config { + enable_confidential_compute = var.enable_confidential_vm ? true : false + } - boot_disk { - device_name = "${var.name}-${element(random_id.service.*.hex, count.index)}" - initialize_params { - image = var.image_id - size = 20 - } - } - - scheduling { - on_host_maintenance = "TERMINATE" + boot_disk { + device_name = "${var.name}-${element(random_id.service.*.hex, count.index)}" + initialize_params { + image = var.image_id + size = 20 } + } - metadata = merge({ - sshKeys = "susetest:${file("/root/.ssh/id_rsa.pub")}" - openqa_created_by = var.name - openqa_created_date = timestamp() - openqa_created_id = element(random_id.service.*.hex, count.index) - }, var.tags) - - network_interface { - network = "tf-network" - subnetwork = "tf-subnetwork" - access_config {} - stack_type = "IPV4_ONLY" - } + scheduling { + on_host_maintenance = "TERMINATE" + } - service_account { - email = data.external.gce_cred.result["client_email"] - scopes = ["cloud-platform"] - } + metadata = merge({ + sshKeys = "susetest:${file("/root/.ssh/id_rsa.pub")}" + openqa_created_by = var.name + openqa_created_date = timestamp() + openqa_created_id = element(random_id.service.*.hex, count.index) + }, var.tags) + + network_interface { + network = "tf-network" + subnetwork = "tf-subnetwork" + access_config {} + stack_type = "IPV4_ONLY" + } - dynamic "shielded_instance_config" { - for_each = var.uefi ? [ "UEFI" ] : [] - content { - enable_secure_boot = "true" - enable_vtpm = "true" - enable_integrity_monitoring = "true" - } - } + service_account { + email = data.external.gce_cred.result["client_email"] + scopes = ["cloud-platform"] + } - timeouts { - create = var.vm_create_timeout + dynamic "shielded_instance_config" { + for_each = var.uefi ? ["UEFI"] : [] + content { + enable_secure_boot = "true" + enable_vtpm = "true" + enable_integrity_monitoring = "true" } + } + + timeouts { + create = var.vm_create_timeout + } } resource "google_compute_attached_disk" "default" { - count = var.create-extra-disk ? var.instance_count: 0 - disk = element(google_compute_disk.default.*.self_link, count.index) - instance = element(google_compute_instance.openqa.*.self_link, count.index) + count = var.create-extra-disk ? var.instance_count : 0 + disk = element(google_compute_disk.default.*.self_link, count.index) + instance = element(google_compute_instance.openqa.*.self_link, count.index) } resource "google_compute_disk" "default" { - name = "ssd-disk-${element(random_id.service.*.hex, count.index)}" - count = var.create-extra-disk ? var.instance_count : 0 - type = var.extra-disk-type - zone = var.region - size = var.extra-disk-size - physical_block_size_bytes = 4096 - labels = { - openqa_created_by = var.name - openqa_created_id = element(random_id.service.*.hex, count.index) - } + name = "ssd-disk-${element(random_id.service.*.hex, count.index)}" + count = var.create-extra-disk ? var.instance_count : 0 + type = var.extra-disk-type + zone = var.region + size = var.extra-disk-size + physical_block_size_bytes = 4096 + labels = { + openqa_created_by = var.name + openqa_created_id = element(random_id.service.*.hex, count.index) + } } output "public_ip" { - value = google_compute_instance.openqa.*.network_interface.0.access_config.0.nat_ip + value = google_compute_instance.openqa.*.network_interface.0.access_config.0.nat_ip } output "vm_name" { - value = google_compute_instance.openqa.*.name + value = google_compute_instance.openqa.*.name } output "confidential_instance_config" { - value = google_compute_instance.openqa.*.confidential_instance_config + value = google_compute_instance.openqa.*.confidential_instance_config } diff --git a/data/publiccloud/terraform/openstack.tf b/data/publiccloud/terraform/openstack.tf index 28279477c1d0..cee25f5fd858 100644 --- a/data/publiccloud/terraform/openstack.tf +++ b/data/publiccloud/terraform/openstack.tf @@ -2,106 +2,106 @@ terraform { required_providers { openstack = { version = ">= 0.14.0" - source = "terraform-provider-openstack/openstack" + source = "terraform-provider-openstack/openstack" } random = { version = "= 3.1.0" - source = "hashicorp/random" + source = "hashicorp/random" } external = { version = "= 2.1.0" - source = "hashicorp/external" + source = "hashicorp/external" } } } provider "openstack" { - cloud = "mycloud" + cloud = "mycloud" } variable "name" { - default = "openqa-vm" + default = "openqa-vm" } variable "keypair" { - description = "Public Key to be injected to the instance" - type = string - default = "" + description = "Public Key to be injected to the instance" + type = string + default = "" } variable "image_id" { - description = "Image ID to boot the instance" - type = string - default = "" + description = "Image ID to boot the instance" + type = string + default = "" } variable "secgroup" { - description = "Security group to be used" - type = string - default = "icmp_ssh" + description = "Security group to be used" + type = string + default = "icmp_ssh" } variable "type" { - description = "Flavor (cpu, ram) to boot the instance" - type = string - default = "m1.small" + description = "Flavor (cpu, ram) to boot the instance" + type = string + default = "m1.small" } variable "instance_count" { - default = "1" + default = "1" } variable "tags" { - type = map(string) - default = {} + type = map(string) + default = {} } variable "region" { - default = "CustomRegion" + default = "CustomRegion" } resource "random_id" "service" { - count = var.instance_count - keepers = { - name = var.name - } - byte_length = 8 + count = var.instance_count + keepers = { + name = var.name + } + byte_length = 8 } data "template_file" "cloudinit_jeos" { - template = file("/root/mn_jeos.cloud-init") + template = file("/root/mn_jeos.cloud-init") } resource "openstack_compute_instance_v2" "openqa_instance" { - count = var.instance_count - name = "${var.name}-${element(random_id.service.*.hex, count.index)}" - image_id = var.image_id - flavor_name = var.type - key_pair = var.keypair - security_groups = [var.secgroup] - region = var.region - user_data = data.template_file.cloudinit_jeos.rendered - network { - name = "fixed" - } + count = var.instance_count + name = "${var.name}-${element(random_id.service.*.hex, count.index)}" + image_id = var.image_id + flavor_name = var.type + key_pair = var.keypair + security_groups = [var.secgroup] + region = var.region + user_data = data.template_file.cloudinit_jeos.rendered + network { + name = "fixed" + } } resource "openstack_networking_floatingip_v2" "floating_ip" { - count = var.instance_count - pool = "floating" + count = var.instance_count + pool = "floating" } resource "openstack_compute_floatingip_associate_v2" "floating_ip" { - count = var.instance_count - floating_ip = openstack_networking_floatingip_v2.floating_ip[count.index].address - instance_id = openstack_compute_instance_v2.openqa_instance[count.index].id + count = var.instance_count + floating_ip = openstack_networking_floatingip_v2.floating_ip[count.index].address + instance_id = openstack_compute_instance_v2.openqa_instance[count.index].id } output "vm_name" { - value = openstack_compute_instance_v2.openqa_instance.*.name + value = openstack_compute_instance_v2.openqa_instance.*.name } output "public_ip" { - value = openstack_networking_floatingip_v2.floating_ip.*.address + value = openstack_networking_floatingip_v2.floating_ip.*.address }