parent
							
								
									0108fd0e57
								
							
						
					
					
						commit
						ddd98a76ec
					
				
					 5 changed files with 81 additions and 77 deletions
				
			
		
							
								
								
									
										35
									
								
								lb.tf
									
										
									
									
									
								
							
							
						
						
									
										35
									
								
								lb.tf
									
										
									
									
									
								
							| 
						 | 
					@ -1,35 +0,0 @@
 | 
				
			||||||
resource "yandex_lb_target_group" "group1" {
 | 
					 | 
				
			||||||
  name = "group1"
 | 
					 | 
				
			||||||
  target {
 | 
					 | 
				
			||||||
    subnet_id = yandex_vpc_subnet.subnet1.id
 | 
					 | 
				
			||||||
    address = yandex_compute_instance.vm[0].network_interface.0.ip_address
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  target {
 | 
					 | 
				
			||||||
    subnet_id = yandex_vpc_subnet.subnet1.id
 | 
					 | 
				
			||||||
    address = yandex_compute_instance.vm[1].network_interface.0.ip_address
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
resource "yandex_lb_network_load_balancer" "balancer1" {
 | 
					 | 
				
			||||||
  name = "balancer1"
 | 
					 | 
				
			||||||
  deletion_protection = "false"
 | 
					 | 
				
			||||||
  listener {
 | 
					 | 
				
			||||||
    name = "my-lb1"
 | 
					 | 
				
			||||||
    port = 80
 | 
					 | 
				
			||||||
    external_address_spec {
 | 
					 | 
				
			||||||
      ip_version = "ipv4"
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  attached_target_group {
 | 
					 | 
				
			||||||
    target_group_id = yandex_lb_target_group.group1.id
 | 
					 | 
				
			||||||
    healthcheck {
 | 
					 | 
				
			||||||
      name = "http"
 | 
					 | 
				
			||||||
      http_options {
 | 
					 | 
				
			||||||
        port = 80
 | 
					 | 
				
			||||||
        path = "/"
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										81
									
								
								main.tf
									
										
									
									
									
								
							
							
						
						
									
										81
									
								
								main.tf
									
										
									
									
									
								
							| 
						 | 
					@ -9,3 +9,84 @@ terraform {
 | 
				
			||||||
provider "yandex" {
 | 
					provider "yandex" {
 | 
				
			||||||
  zone = "ru-central1-b"
 | 
					  zone = "ru-central1-b"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					resource "yandex_compute_instance" "vm" {
 | 
				
			||||||
 | 
					  count = 2
 | 
				
			||||||
 | 
					  name = "vm${count.index}"
 | 
				
			||||||
 | 
					  platform_id = "standard-v1"
 | 
				
			||||||
 | 
					  boot_disk {
 | 
				
			||||||
 | 
					    initialize_params {
 | 
				
			||||||
 | 
					      image_id = "fd87j6d92jlrbjqbl32q" # ubuntu 22.04
 | 
				
			||||||
 | 
					      size = 8
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  network_interface {
 | 
				
			||||||
 | 
					    subnet_id = yandex_vpc_subnet.subnet1.id
 | 
				
			||||||
 | 
					    nat = true
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  resources {
 | 
				
			||||||
 | 
					    core_fraction = 5
 | 
				
			||||||
 | 
					    cores = 2
 | 
				
			||||||
 | 
					    memory = 2
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  metadata = { user-data = "${file("users.yml")}" }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					resource "yandex_vpc_network" "network1" {
 | 
				
			||||||
 | 
					  name = "network1"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					resource "yandex_vpc_subnet" "subnet1" {
 | 
				
			||||||
 | 
					  name = "subnet1"
 | 
				
			||||||
 | 
					  v4_cidr_blocks = [ "172.24.8.0/24" ]
 | 
				
			||||||
 | 
					  network_id = yandex_vpc_network.network1.id
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					resource "yandex_lb_target_group" "group1" {
 | 
				
			||||||
 | 
					  name = "group1"
 | 
				
			||||||
 | 
					  target {
 | 
				
			||||||
 | 
					    subnet_id = yandex_vpc_subnet.subnet1.id
 | 
				
			||||||
 | 
					    address = yandex_compute_instance.vm[0].network_interface.0.ip_address
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  target {
 | 
				
			||||||
 | 
					    subnet_id = yandex_vpc_subnet.subnet1.id
 | 
				
			||||||
 | 
					    address = yandex_compute_instance.vm[1].network_interface.0.ip_address
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					resource "yandex_lb_network_load_balancer" "balancer1" {
 | 
				
			||||||
 | 
					  name = "balancer1"
 | 
				
			||||||
 | 
					  deletion_protection = "false"
 | 
				
			||||||
 | 
					  listener {
 | 
				
			||||||
 | 
					    name = "my-lb1"
 | 
				
			||||||
 | 
					    port = 80
 | 
				
			||||||
 | 
					    external_address_spec {
 | 
				
			||||||
 | 
					      ip_version = "ipv4"
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  attached_target_group {
 | 
				
			||||||
 | 
					    target_group_id = yandex_lb_target_group.group1.id
 | 
				
			||||||
 | 
					    healthcheck {
 | 
				
			||||||
 | 
					      name = "http"
 | 
				
			||||||
 | 
					      http_options {
 | 
				
			||||||
 | 
					        port = 80
 | 
				
			||||||
 | 
					        path = "/"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					output "lb-ip" {
 | 
				
			||||||
 | 
					  value = yandex_lb_network_load_balancer.balancer1.listener
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					output "vm-ips" {
 | 
				
			||||||
 | 
					  value = tomap({
 | 
				
			||||||
 | 
					    for name, vm in yandex_compute_instance.vm : name => vm.network_interface.0.nat_ip_address
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,9 +0,0 @@
 | 
				
			||||||
output "lb-ip" {
 | 
					 | 
				
			||||||
  value = yandex_lb_network_load_balancer.balancer1.listener
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
output "vm-ips" {
 | 
					 | 
				
			||||||
  value = tomap({
 | 
					 | 
				
			||||||
    for name, vm in yandex_compute_instance.vm : name => vm.network_interface.0.nat_ip_address
 | 
					 | 
				
			||||||
  })
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										24
									
								
								vms.tf
									
										
									
									
									
								
							
							
						
						
									
										24
									
								
								vms.tf
									
										
									
									
									
								
							| 
						 | 
					@ -1,24 +0,0 @@
 | 
				
			||||||
resource "yandex_compute_instance" "vm" {
 | 
					 | 
				
			||||||
  count = 2
 | 
					 | 
				
			||||||
  name = "vm${count.index}"
 | 
					 | 
				
			||||||
  platform_id = "standard-v1"
 | 
					 | 
				
			||||||
  boot_disk {
 | 
					 | 
				
			||||||
    initialize_params {
 | 
					 | 
				
			||||||
      image_id = "fd87j6d92jlrbjqbl32q" # ubuntu 22.04
 | 
					 | 
				
			||||||
      size = 8
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  network_interface {
 | 
					 | 
				
			||||||
    subnet_id = yandex_vpc_subnet.subnet1.id
 | 
					 | 
				
			||||||
    nat = true
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  resources {
 | 
					 | 
				
			||||||
    core_fraction = 5
 | 
					 | 
				
			||||||
    cores = 2
 | 
					 | 
				
			||||||
    memory = 2
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  metadata = { user-data = "${file("users.yml")}" }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										9
									
								
								vpc.tf
									
										
									
									
									
								
							
							
						
						
									
										9
									
								
								vpc.tf
									
										
									
									
									
								
							| 
						 | 
					@ -1,9 +0,0 @@
 | 
				
			||||||
resource "yandex_vpc_network" "network1" {
 | 
					 | 
				
			||||||
  name = "network1"
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
resource "yandex_vpc_subnet" "subnet1" {
 | 
					 | 
				
			||||||
  name = "subnet1"
 | 
					 | 
				
			||||||
  v4_cidr_blocks = [ "172.24.8.0/24" ]
 | 
					 | 
				
			||||||
  network_id = yandex_vpc_network.network1.id
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue