Skip to content

Commit 6aed99d

Browse files
committed
lab4 use terraform
1 parent c477bd6 commit 6aed99d

File tree

14 files changed

+796
-0
lines changed

14 files changed

+796
-0
lines changed

terraform/TF.md

Lines changed: 536 additions & 0 deletions
Large diffs are not rendered by default.

terraform/cloud/main.tf

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
terraform {
2+
required_providers {
3+
yandex = {
4+
source = "yandex-cloud/yandex"
5+
}
6+
}
7+
required_version = ">= 0.13"
8+
}
9+
10+
provider "yandex" {
11+
service_account_key_file = "/Users/m4k4rich/core-course-labs/terraform/cloud/authorized_key.json"
12+
cloud_id = "b1g5ltf518ub13g9v269"
13+
folder_id = "b1g1aqrohbot4fl3e1vb"
14+
zone = var.zone
15+
}
16+
17+
resource "yandex_compute_instance" "vm-1" {
18+
name = "my-vm-1"
19+
20+
resources {
21+
cores = 2
22+
memory = 2
23+
}
24+
25+
boot_disk {
26+
initialize_params {
27+
image_id = "fd82sqrj4uk9j7vlki3q"
28+
}
29+
}
30+
31+
network_interface {
32+
subnet_id = yandex_vpc_subnet.subnet-1.id
33+
nat = true
34+
}
35+
}
36+
37+
resource "yandex_compute_instance" "vm-2" {
38+
name = "my-vm-2"
39+
40+
resources {
41+
cores = 4
42+
memory = 4
43+
}
44+
45+
boot_disk {
46+
initialize_params {
47+
image_id = "fd82sqrj4uk9j7vlki3q"
48+
}
49+
}
50+
51+
network_interface {
52+
subnet_id = yandex_vpc_subnet.subnet-1.id
53+
nat = true
54+
}
55+
}
56+
57+
resource "yandex_vpc_network" "network-1" {
58+
name = "network1"
59+
}
60+
61+
resource "yandex_vpc_subnet" "subnet-1" {
62+
name = "subnet1"
63+
zone = "ru-central1-a"
64+
network_id = yandex_vpc_network.network-1.id
65+
v4_cidr_blocks = ["192.168.10.0/24"]
66+
}
67+
68+
output "internal_ip_address_vm_1" {
69+
value = yandex_compute_instance.vm-1.network_interface.0.ip_address
70+
}
71+
72+
output "internal_ip_address_vm_2" {
73+
value = yandex_compute_instance.vm-2.network_interface.0.ip_address
74+
}
75+
76+
output "external_ip_address_vm_1" {
77+
value = yandex_compute_instance.vm-1.network_interface.0.nat_ip_address
78+
}
79+
80+
output "external_ip_address_vm_2" {
81+
value = yandex_compute_instance.vm-2.network_interface.0.nat_ip_address
82+
}

terraform/cloud/outputs.tf

Whitespace-only changes.

terraform/cloud/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
variable "zone" {
2+
default = "ru-central1-a"
3+
type = string
4+
}

terraform/docker/main.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
terraform {
2+
required_providers {
3+
docker = {
4+
source = "kreuzwerker/docker"
5+
version = "~> 3.0.1"
6+
}
7+
}
8+
}
9+
10+
provider "docker" {}
11+
12+
resource "docker_image" "nginx" {
13+
name = var.image_name
14+
keep_locally = false
15+
}
16+
17+
resource "docker_container" "nginx" {
18+
image = docker_image.nginx.image_id
19+
name = var.container_name
20+
ports {
21+
internal = 80
22+
external = var.container_ports_external
23+
}
24+
}

terraform/docker/outputs.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "image_id" {
2+
description = "My image ID"
3+
value = docker_image.nginx.id
4+
}
5+
6+
output "container_id" {
7+
description = "My Container ID"
8+
value = docker_container.nginx.id
9+
}

terraform/docker/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
variable "image_name" {
2+
type = string
3+
}
4+
5+
variable "container_name" {
6+
type = string
7+
}
8+
9+
variable "container_ports_external" {
10+
type = number
11+
default = 8000
12+
}

terraform/github/main.tf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
terraform {
2+
required_providers {
3+
github = {
4+
source = "integrations/github"
5+
version = "~> 4.0"
6+
}
7+
}
8+
}
9+
10+
provider "github" {
11+
token = var.github_token
12+
}
13+
14+
resource "github_repository" "devops_course_labs" {
15+
name = "my-core-course-labs"
16+
description = "Solutions for the DevOps course"
17+
visibility = "public"
18+
}
19+
20+
# make the default branch main
21+
resource "github_branch_default" "main" {
22+
repository = github_repository.devops_course_labs.name
23+
branch = "master"
24+
}
25+
26+
resource "github_branch_protection" "default" {
27+
repository_id = github_repository.devops_course_labs.id
28+
pattern = github_branch_default.main.branch
29+
require_conversation_resolution = true
30+
enforce_admins = true
31+
32+
required_pull_request_reviews {
33+
required_approving_review_count = 1
34+
}
35+
}

terraform/github/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
variable "github_token" {
2+
type = string
3+
description = "Required to provide `GITHUB_TOKEN`"
4+
sensitive = true
5+
}

terraform/imports.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import {
2+
to = module.github.github_repository.devops_course_labs
3+
id = "my-core-course-labs"
4+
}

0 commit comments

Comments
 (0)