diff --git a/02.-Короче,-Склифософский!.md b/02.-Короче,-Склифософский!.md new file mode 100644 index 0000000..34b6a00 --- /dev/null +++ b/02.-Короче,-Склифософский!.md @@ -0,0 +1,86 @@ +# «Короче, Склифосовский!» +Данный раздел предназначен для тех, кто хорошо знаком с инструментом Terraform, а также имеет представление об основных понятиях и способах авторизации в облачной платформе DECORT. + +Ниже приведён подробно откомментированный пример, показывающий, как создать виртуальный сервер (aka _compute_) в облачной платформе DECORT с помощью соответствующего Terraform провайдера. + +Идентификатор образа операционной системы, на базе которого должен быть создан виртуальный сервер, считывается из облачной платформы с помощью _source data_ функци [decort_image]( link to follow ). + +В данном примере мы с помощью _resource_ функции [decort_resgroup]( link to follow) создаём новую ресурсную группу, в которую будет помещён этот виртуальный сервер. Для получения информации об уже имеющейся ресурсной группе можно использовать _source data_ функцию с таким же названием. + +Виртуальный сервер - в данном примере на базе системы виртуализации KVM x86 - создаётся посредством _resource_ функции [decort_kvmvm]( link to follow). + +Только авторизованные в контроллере облачной платформы пользователи могут управлять облачными ресурсами. Подробнее о способах авторизации см. [Обзор облачной платформы DECORT]( link to follow ). + +``` +# 1. Initialize DECORT plugin and connection to DECORT cloud controller +# NOTE: in this example credentials are expected to come from +# DECORT_APP_ID and DECORT_APP_SECRET environmental variables - set them +# in the shell before calling terraform. +# Alternatively you may define plugin parameters app_id and app_secret in +# the TF file, however, this may be insecure if you plan to share this TF +# file with others. +provider "decort" { + authenticator = "oauth2" + controller_url = "<>" # specify correct DECORT controller URL, e.g. "https://ds1.digitalenergy.online" + oauth2_url = "<>" # specify corresponding DECORT SSO URL, e.g. "https://sso.digitalenergy.online" + # allow_unverified_ssl = true +} + +# 2. Load account to use - new VM will belong to this account +data "decort_account" "my_account" { + name = "<>" # Specify the name of one of your accounts +} + +# 3. Load OS image to use for VM deployment +data "decort_image" "os_image" { + name = "<>" # Specify OS image name, e.g. "Ubuntu 20.04". Image names are case sensitive and may contain spaces. +} + +# 4. Create new Resource Group in the selected account, new VM will be created in this RG +resource "decort_resgroup" "my_rg" { + name = "NewRgByTF" + account_id = data.decort_account.my_account.id + # if you want to set resource quota on this Resource Group, uncomment + # the following code fragment + # quota { + # cpu = 8 # CPU limit + # ram = 8912 # RAM limit in MB + # disk = 96 # disk volume limit in GB + #} +} + +# 5. Create extra disk, which will be attached to the new VM. +# This step is optional - if you do not want extra disks on your VM, skip it +# and comment out extra_disks parameter when creating VM below. +resource "decort_disk" "extra_disk" { + name = "extra-disk-for-vm" + account_id = data.decort_account.my_account.id + size = 5 # disk size in GB + type = "D" # disk type, always use "D" for exgtra disks + sep_id = data.decort_image.os_image.sep_id # use the same SEP ID as the OS image + pool = "<>" # consult your DECORT platform admin for configured storage pool names +} + +# 6. Create virtual machine (a compute of type KVM VM x86 in this example) +# Now that we have all necessary components at hand, we may create a virtual machine. +# This VM will be based on the previsouly obtained OS image, located in the specified +# Resource Group, directly connected to an external network, have a boot disk of +# specified size and one extra disk attached. +resource "decort_kvmvm" "my_new_vm" { + name = "tf-managed-vm" + rg_id = decort_resgroup.my_rg.id + arch = "KVM_X86" # "KVM_PPC" for IBM Power or "KVM_X86" for Intel + cpu = 1 # CPU count + ram = 1024 # RAM size in MB, must be even number, ideally a power of 2 + boot_disk_size = 10 # Boot disk size in GB + image_id = data.decort_image.os_image.id + description = "Test KVM VM Compute managed by Terraform" + extra_disks = [ decort_disk.extra_disk.id ] + + network { + net_type = "EXTNET" + net_id = <> # specify external network ID to use, consult your DECORT platform admin for correct IDs + # ip_address = "<>" # you may optionally request a specific IP address + } +} +``` \ No newline at end of file