Skip to content

Commit

Permalink
Merge pull request #18486 from pdostal/pc_terraform
Browse files Browse the repository at this point in the history
PC: Lint Terraform
  • Loading branch information
asmorodskyi authored Jan 19, 2024
2 parents 9369377 + cec1c3d commit bb96b5d
Show file tree
Hide file tree
Showing 5 changed files with 362 additions and 362 deletions.
172 changes: 86 additions & 86 deletions data/publiccloud/terraform/azure.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Loading

0 comments on commit bb96b5d

Please sign in to comment.