UPD "С этим разобрался" Показать
но появилась новая Error: Function calls not allowed
on vm-game.tf line 7, in resource "openstack_compute_instance_v2" "game":
7: user_data = file("cloud-init.yml")
Invalid cloud-config: cloud-init.yml is not a valid YAML file
приложу логи ниже
Показать
mkdir /home/altlinux/Projects/Project_01/terraform
cd /home/altlinux/Projects/
FILE: cloudinit.conf
export OS_AUTH_URL=https://domain
export OS_IDENTITY_API_VERSION=3
export OS_AUTH_TYPE=password
export OS_PROJECT_DOMAIN_NAME=+
export OS_USER_DOMAIN_NAME=+
export OS_PROJECT_NAME=
export OS_USERNAME=
export OS_PASSWORD=
source cloudinit.conf
openstack --insecure server list:
Файл .terraformrc расположен в домашнем каталоге пользователя
provider_installation {
network_mirror {
url = "[url]htps://terraform-mirror.mcs.mail.ru[/url]"
include = ["registry.terraform.io/*/*"]
}
direct {
exclude = ["registry.terraform.io/*/*"]
}
}
cd Project_01/terraform/
файл provider.tf
terraform {
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "2.1.0"
}
}
}
provider "openstack" {
auth_url =
tenant_name = "Project0"
user_name = "User0"
password = "P@ssw0rd"
insecure = true
}
terraform init
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub > cloud-init.yml
файл cloud-init.yml
#cloud-config
chpasswd:
expire: false
users:
- {name: altlinux, password: P@ssw0rd, type: text}
- {name: root, password: toor, type: text}
ssh_pwauth: false
users:
- name: altlinux
sudo: ALL=(ALL) NOPASSWD:ALL
groups: wheel
shell: /bin/bash
ssh_authorized_keys:
- <СОДЕРЖИМОЕ_ПУБЛИЧНОГО_КЛЮЧА_SSH>
файл vm-game.tf
flavor_id openstack --insecure flavor list
uuid openstack --insecure image list
resource "openstack_compute_instance_v2" "game" {
count = "3"
name = "game0${count.index + 1}"
flavor_id = "03bf1b85-2f5f-4ada-a07b-8b994b6dcb57"
user_data = file("cloud-init.yml")
block_device {
uuid = "827e08fa-fd3c-41cd-92ca-845bb5018478"
source_type = "image"
volume_size = "10"
boot_index = 0
destination_type = "volume"
delete_on_termination = true
}
network {
port = openstack_networking_port_v2.port_vm_game[count.index].id
}
}
vm-haproxy01.tf
flavor_id --insecure flavor list
uuid --insecure image list
resource "openstack_compute_instance_v2" "haproxy" {
name = "haproxy01"
flavor_id = "03bf1b85-2f5f-4ada-a07b-8b994b6dcb57"
user_data = file("cloud-init.yml")
block_device {
uuid = "827e08fa-fd3c-41cd-92ca-845bb5018478"
source_type = "image"
volume_size = "10"
boot_index = 0
destination_type = "volume"
delete_on_termination = true
}
network {
port = openstack_networking_port_v2.haproxy.id
}
}
файл network.tf
network_id openstack --insecure network list
subnet_id openstack --insecure subnet list
resource "openstack_networking_port_v2" "port_vm_game" {
count = "3"
name = "port_vm_game0${count.index + 1}"
network_id = "61845892-f9cc-4fde-962c-34b59425a74d"
admin_state_up = true
fixed_ip {
subnet_id = "13592ca4-8782-410b-9bcc-90810ccab6fe"
ip_address = "192.168.1.10${count.index + 1}"
}
}
resource "openstack_networking_port_v2" "haproxy" {
name = "port_vm_haproxy"
network_id = "61845892-f9cc-4fde-962c-34b59425a74d"
admin_state_up = true
fixed_ip {
subnet_id = "13592ca4-8782-410b-9bcc-90810ccab6fe"
ip_address = "192.168.1.100"
}
}
файл floatingip.tf
resource "openstack_networking_floatingip_v2" "floatingip_haproxy" {
pool = "public"
}
resource "openstack_networking_floatingip_associate_v2" "association_haproxy" {
port_id = openstack_networking_port_v2.haproxy.id
floating_ip = openstack_networking_floatingip_v2.floatingip_haproxy.address
}
terraform validate
Показать
chpasswd:
expire: false
users:
- {name: altlinux, password: P@ssw0rd, type: text}
- {name: root, password: toor, type: text}
ssh_pwauth: false