variable "server_count" {
default = 1
}resource "openstack_networking_port_v2" "port_1" {
name = "node-${count.index}-eth0"
count = var.server_count| add-apt-repository \ | |
| "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ | |
| $(lsb_release -cs) \ | |
| stable" | |
| curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - | |
| apt-get update | |
| apt-get -y install \ |
| variables: | |
| IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME | |
| GIT_STRATEGY: FETCH | |
| stages: | |
| - lints | |
| - build | |
| - test_create_infra | |
| - tests | |
| - test_destroy_infra |
| ############################################# | |
| # Initialize OpenStack provider | |
| provider "openstack" { | |
| domain_name = "${var.domain_name}" | |
| tenant_id = "${var.project_id}" | |
| user_name = "${var.user_name}" | |
| password = "${var.user_password}" | |
| auth_url = "https://api.selvpc.ru/identity/v3" | |
| region = "${var.region}" | |
| } |
| ################################### | |
| # Configure the OpenStack Provider | |
| ################################### | |
| provider "openstack" { | |
| domain_name = "${var.domain_name}" | |
| tenant_id = "${var.project_id}" | |
| user_name = "${var.user_name}" | |
| password = "${var.user_password}" | |
| auth_url = "https://api.selvpc.ru/identity/v3" | |
| region = "${var.region}" |
| bash-5.0# openstack image list --public | |
| +--------------------------------------+--------------------------------------------+--------+ | |
| | ID | Name | Status | | |
| +--------------------------------------+--------------------------------------------+--------+ | |
| | 4bf30993-828a-4468-9c8f-5a97ebe09f7d | CentOS 7 64-bit | active | | |
| | dede8b0e-9297-4a65-8f5a-32e82a4e0b27 | CentOS 7 Minimal 64-bit | active | | |
| | ed14e2ad-3fad-40ea-8979-ea4ae8d805be | CentOS 8 64-bit | active | | |
| | 88c8d109-164e-4d6f-a1a4-64fafefeb09f | CoreOS | active | | |
| | 8be6ff81-21e1-464c-a343-c6e2ab4226c9 | Debian 10 (Buster) 64-bit | active | | |
| | 2d548634-9a42-4497-b849-48bfa32e66db | Debian 9 (Stretch) 64-bit | active | |
| resource "openstack_compute_flavor_v2" "flavor-node" { | |
| name = "node.${var.project_id}-${random_string.random_name_1.result}" | |
| ram = var.ram | |
| vcpus = "1" | |
| disk = "0" | |
| is_public = "false" | |
| } | |
| ################################### | |
| # Create port | |
| ################################### | |
| resource "openstack_networking_port_v2" "port_1" { | |
| name = "node-eth0" | |
| network_id = var.network_id | |
| fixed_ip { | |
| subnet_id = var.subnet_id |
variable "server_count" {
default = 1
}resource "openstack_networking_port_v2" "port_1" {
name = "node-${count.index}-eth0"
count = var.server_count| resource "openstack_networking_port_v2" "port" { | |
| count = "${var.server_count}" | |
| name = "node-${count.index}-eth0" | |
| ... | |
| } | |
| resource "openstack_blockstorage_volume_v3" "volume" { | |
| count = "${var.server_count}" | |
| name = "volume-for-node-${count.index}" | |
| ... | |
| } |
| ################################### | |
| # Create port | |
| ################################### | |
| resource "openstack_networking_port_v2" "port_2" { | |
| name = "node-eth0" | |
| network_id = openstack_networking_network_v2.network_1.id | |
| fixed_ip { | |
| subnet_id = openstack_networking_subnet_v2.subnet_1.id |