Create PostgreSQL cluster for 1C
We recommend create resources in order. If you create all the resources that are described in the configuration file The Terraform creates resources regardless of the order in which they are listed in the file.
- Optional: configure your ISPs.
- Create a private network and subnet.
- Create a cluster.
- Create a user.
- Create a database and assign an owner.
Configuration files
Example file for configuring providers
terraform {
required_providers {
selectel = {
source = "selectel/selectel"
version = "6.0.0"
}
openstack = {
source = "terraform-provider-openstack/openstack"
version = "2.1.0"
}
}
}
provider "selectel" {
domain_name = "123456"
username = "user"
password = "password"
}
resource "selectel_vpc_project_v2" "project_1" {
name = "project"
}
resource "selectel_iam_serviceuser_v1" "serviceuser_1" {
name = "username"
password = "password"
role {
role_name = "member"
scope = "project"
project_id = selectel_vpc_project_v2.project_1.id
}
}
provider "openstack" {
auth_url = "https://cloud.api.selcloud.ru/identity/v3"
domain_name = "123456"
tenant_id = selectel_vpc_project_v2.project_1.id
user_name = selectel_iam_serviceuser_v1.serviceuser_1.name
password = selectel_iam_serviceuser_v1.serviceuser_1.password
region = "ru-9"
}
Example file for creating a PostgreSQL cluster for 1C fixed configuration
resource "openstack_networking_network_v2" "network_1" {
name = "private-network"
admin_state_up = "true"
}
resource "openstack_networking_subnet_v2" "subnet_1" {
network_id = openstack_networking_network_v2.network_1.id
cidr = "192.168.199.0/24"
}
data "selectel_dbaas_datastore_type_v1" "datastore_type_1" {
project_id = selectel_vpc_project_v2.project_1.id
region = "ru-9"
filter {
engine = "postgresql"
version = "14-1C"
}
}
data "selectel_dbaas_flavor_v1" "flavor_1" {
project_id = selectel_vpc_project_v2.project_1.id
region = "ru-9"
filter {
datastore_type_id = data.selectel_dbaas_datastore_type_v1.datastore_type_1.datastore_types[0].id
fl_size = "standard"
vcpus = 4
ram = 16384
disk = 128
}
}
resource "selectel_dbaas_postgresql_datastore_v1" "datastore_1" {
name = "datastore-1"
project_id = selectel_vpc_project_v2.project_1.id
region = "ru-9"
type_id = data.selectel_dbaas_datastore_type_v1.datastore_type_1.datastore_types[0].id
subnet_id = selectel_vpc_subnet_v2.subnet.subnet_id
node_count = 3
flavor_id = data.selectel_dbaas_flavor_v1.flavor_1.flavors[0].id
pooler {
mode = "transaction"
size = 50
}
}
resource "selectel_dbaas_user_v1" "user_1" {
project_id = selectel_vpc_project_v2.project_1.id
region = "ru-9"
datastore_id = selectel_dbaas_postgresql_datastore_v1.datastore_1.id
name = "user"
password = "secret"
}
resource "selectel_dbaas_postgresql_database_v1" "database_1" {
project_id = selectel_vpc_project_v2.project_1.id
region = "ru-9"
datastore_id = selectel_dbaas_postgresql_datastore_v1.datastore_1.id
owner_id = selectel_dbaas_user_v1.user_1.id
name = "database_1"
}
Example file for creating a PostgreSQL cluster for 1C of arbitrary configuration
resource "openstack_networking_network_v2" "network_1" {
name = "private-network"
admin_state_up = "true"
}
resource "openstack_networking_subnet_v2" "subnet_1" {
network_id = openstack_networking_network_v2.network_1.id
cidr = "192.168.199.0/24"
}
data "selectel_dbaas_datastore_type_v1" "datastore_type_1" {
project_id = selectel_vpc_project_v2.project_1.id
region = "ru-9"
filter {
engine = "postgresql"
version = "14-1С"
}
}
resource "selectel_dbaas_postgresql_datastore_v1" "datastore_1" {
name = "datastore-1"
project_id = selectel_vpc_project_v2.project_1.id
region = "ru-9"
type_id = data.selectel_dbaas_datastore_type_v1.datastore_type_1.datastore_types[0].id
subnet_id = selectel_vpc_subnet_v2.subnet.subnet_id
node_count = 3
flavor {
vcpus = 1
ram = 4096
disk = 32
}
}
resource "selectel_dbaas_user_v1" "user_1" {
project_id = selectel_vpc_project_v2.project_1.id
region = "ru-9"
datastore_id = selectel_dbaas_postgresql_datastore_v1.datastore_1.id
name = "user"
password = "secret"
}
resource "selectel_dbaas_postgresql_database_v1" "database_1" {
project_id = selectel_vpc_project_v2.project_1.id
region = "ru-9"
datastore_id = selectel_dbaas_postgresql_datastore_v1.datastore_1.id
owner_id = selectel_dbaas_user_v1.user_1.id
name = "database_1"
}
optional: configure providers
If you're set up the ISPs Selectel and OpenStack, skip this step.
-
Make sure that in the control panel you created a service user with the Account Administrator and User Administrator roles.
-
Create a directory to store the configuration files and a separate file with the extension
.tf
to configure the ISPs. -
Add Selectel and OpenStack providers to the file to configure the providers:
terraform {
required_providers {
selectel = {
source = "selectel/selectel"
version = "6.0.0"
}
openstack = {
source = "terraform-provider-openstack/openstack"
version = "2.1.0"
}
}
}Here
version
— версии провайдеров. Актуальную версию можно посмотреть в документации Selectel (в Terraform Registry и GitHub) и OpenStack (в Terraform Registry и GitHub).Подробнее о продуктах, услугах и сервисах, которыми можно управлять с помощью провайдеров, в инструкции Провайдеры Selectel и OpenStack.
-
Инициализируйте провайдер Selectel:
provider "selectel" {
domain_name = "123456"
username = "user"
password = "password"
}Здесь:
domain_name
— номер аккаунта Selectel. Можно посмотреть в панели управления в правом верхнем углу;username
— имя сервисного пользователя с ролями Администратор аккаунта и Администратор пользователей. Можно посмотреть в панели управления: раздел Управление доступом → Управление пользователями → вкладка Сервисные пользователи (раздел доступен только Владельцу аккаунта и Администратору пользователей);password
— пароль сервисного пользователя. Можно посмотреть при создании пользователя или изменить на новый.
-
Создайте проект:
resource "selectel_vpc_project_v2" "project_1" {
name = "project"
}Посмотрите подробное описание ресурса selectel_vpc_project_v2.
-
Создайте сервисного пользователя для доступа к проекту и назначьте ему роль Администратор проекта:
resource "selectel_iam_serviceuser_v1" "serviceuser_1" {
name = "username"
password = "password"
role {
role_name = "member"
scope = "project"
project_id = selectel_vpc_project_v2.project_1.id
}
}Здесь:
username
— имя пользователя;password
— пароль пользователя. Пароль должен быть не короче восьми символов и содержать латинские буквы разных регистров и цифры;project_id
— ID проекта. Можно посмотреть в панели управления: раздел Облачная платформа → откройте меню проектов (название текущего проекта) → в строке нужного проекта нажмите .