Last active
January 29, 2024 12:54
-
-
Save fl64/c87ce2c72c3e46f83abee99324ce47ed to your computer and use it in GitHub Desktop.
dvp terraform examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "kubernetes_manifest" "vmd" { | |
manifest = { | |
"apiVersion" = "virtualization.deckhouse.io/v1alpha2" | |
"kind" = "VirtualMachineDisk" | |
"metadata" = { | |
"name" = var.root_disk_name | |
"namespace" = var.namespace | |
} | |
"spec" = { | |
"dataSource" = { | |
"clusterVirtualMachineImage" = { | |
"name" = "ubuntu" | |
} | |
"type" = "ClusterVirtualMachineImage" | |
} | |
"persistentVolumeClaim" = { | |
"size" = var.root_disk_size | |
} | |
} | |
} | |
wait { | |
fields = { | |
"status.phase" = "Ready" | |
} | |
} | |
timeouts { | |
create = "10m" | |
update = "1m" | |
delete = "1m" | |
} | |
} | |
output "disk_name" { | |
description = "The name of the VirtualMachineDisk" | |
value = kubernetes_manifest.vmd.manifest.metadata.name | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "kubernetes_manifest" "vmip" { | |
manifest = { | |
"apiVersion" = "virtualization.deckhouse.io/v1alpha2" | |
"kind" = "VirtualMachineIPAddressClaim" | |
"metadata" = { | |
"name" = var.ip_address_claim_name | |
"namespace" = var.namespace | |
} | |
"spec" = { | |
"address" = var.ip_address | |
"reclaimPolicy" = "Delete" | |
} | |
} | |
wait { | |
fields = { | |
"status.phase" = "Bound" | |
} | |
} | |
timeouts { | |
create = "10m" | |
update = "1m" | |
delete = "1m" | |
} | |
} | |
output "ip_address_claim_name" { | |
description = "The name of the VirtualMachineIPAddressClaim" | |
value = kubernetes_manifest.vmip.manifest.metadata.name | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terraform { | |
required_version = ">= 1.7.0" | |
required_providers { | |
kubernetes = { | |
source = "hashicorp/kubernetes" | |
#version = ">= v2.25.0" | |
} | |
} | |
} | |
provider "kubernetes" { | |
config_path = "~/.kube/config" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "namespace" { | |
description = "Namespace of the VirtualMachineDisk" | |
default = "default" | |
} | |
variable "root_disk_name" { | |
description = "Name of the VirtualMachineDisk" | |
default = "vmd-root" | |
} | |
variable "root_disk_size" { | |
description = "Size of the PersistentVolumeClaim" | |
default = "5Gi" | |
} | |
variable "ip_address_claim_name" { | |
description = "Name of VirtualMachineIPAddressClaim" | |
default = "vmipac" | |
} | |
variable "ip_address" { | |
description = "Name of VirtualMachineIPAddressClaim" | |
default = "10.66.10.77" | |
} | |
variable "vm_name" { | |
description = "Name of the VirtualMachine" | |
default = "vm-tf-test" | |
} | |
variable "vm_cpu_count" { | |
description = "VM CPU count" | |
default = 1 | |
} | |
variable "vm_cpu_core_fraction" { | |
description = "VM CPU corefraction" | |
default = "10%" | |
} | |
variable "vm_ram_size" { | |
description = "VM RAM size" | |
default = "512Mi" | |
} | |
variable "vm_provisioning_userdata" { | |
description = "User data for the VirtualMachine" | |
default = <<-EOT | |
#cloud-config | |
users: | |
- name: cloud | |
passwd: $6$rounds=4096$vln/.aPHBOI7BMYR$bBMkqQvuGs5Gyd/1H5DP4m9HjQSy.kgrxpaGEHwkX7KEFV8BS.HZWPitAtZ2Vd8ZqIZRqmlykRCagTgPejt1i. | |
shell: /bin/bash | |
sudo: ALL=(ALL) NOPASSWD:ALL | |
chpasswd: { expire: False } | |
lock_passwd: false | |
EOT | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "kubernetes_manifest" "vm" { | |
manifest = { | |
"apiVersion" = "virtualization.deckhouse.io/v1alpha2" | |
"kind" = "VirtualMachine" | |
"metadata" = { | |
"labels" = { | |
"vm" = var.vm_name | |
} | |
"name" = var.vm_name | |
"namespace" = var.namespace | |
} | |
"spec" = { | |
"virtualMachineIPAddressClaimName" = kubernetes_manifest.vmip.manifest.metadata.name | |
"blockDevices" = [ | |
{ | |
"type" = "VirtualMachineDisk" | |
"virtualMachineDisk" = { | |
"name" = kubernetes_manifest.vmd.manifest.metadata.name | |
} | |
}, | |
] | |
"bootloader" = "BIOS" | |
"cpu" = { | |
"coreFraction" = var.vm_cpu_core_fraction | |
"cores" = var.vm_cpu_count | |
} | |
"enableParavirtualization" = true | |
"memory" = { | |
"size" = var.vm_ram_size | |
} | |
"osType" = "Generic" | |
"provisioning" = { | |
"type" = "UserData" | |
"userData" = var.vm_provisioning_userdata | |
} | |
"runPolicy" = "AlwaysOn" | |
} | |
} | |
wait { | |
fields = { | |
"status.phase" = "Running" | |
} | |
} | |
timeouts { | |
create = "10m" | |
update = "1m" | |
delete = "1m" | |
} | |
} | |
output "vm_name" { | |
description = "The name of the VirtualMachine" | |
value = kubernetes_manifest.vm.manifest.metadata.name | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment