Skip to content

Commit a79e87f

Browse files
committed
init
1 parent 9ec9f4d commit a79e87f

13 files changed

Lines changed: 533 additions & 0 deletions

File tree

app_python/docs/LAB4.md

Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
# Terraform Infrastructure Report
2+
3+
## 1. Cloud Provider Chosen and Why
4+
5+
**Cloud Provider:** Yandex Cloud
6+
7+
Yandex Cloud was chosen because:
8+
9+
- It provides full Infrastructure as Code (IaC) support through the official Terraform provider.
10+
- It offers simple VPC, compute, and security group configuration suitable for educational projects.
11+
- It supports fine-grained IAM roles and service accounts for secure automation.
12+
- It provides public IP (NAT) configuration directly in the compute instance resource.
13+
14+
Terraform was used as the Infrastructure as Code tool because it allows:
15+
16+
- Declarative infrastructure definition
17+
- Version-controlled infrastructure
18+
- Reproducible environments
19+
- Automated provisioning
20+
21+
---
22+
23+
## 2. Terraform Version Used
24+
25+
Terraform version used:
26+
27+
terraform version
28+
Terraform v1.x.x
29+
30+
31+
Provider version:
32+
33+
yandex-cloud/yandex v0.187.0
34+
35+
36+
---
37+
38+
## 3. Resources Created
39+
40+
The following resources were provisioned:
41+
42+
### Network
43+
- VPC Network: `net`
44+
- Subnet: `subnet`
45+
- CIDR block: `10.0.0.0/24`
46+
- Zone: `ru-central1-a`
47+
48+
### Security Group
49+
Inbound rules:
50+
- SSH (22) — allowed only from personal IP (`<MY_IP>/32`)
51+
- HTTP (80) — allowed from `0.0.0.0/0`
52+
- TCP 5000 — allowed from `0.0.0.0/0`
53+
54+
Outbound:
55+
- All traffic allowed
56+
57+
### Virtual Machine
58+
- Name: `terraform1`
59+
- Platform: `standard-v2`
60+
- CPU: 2 cores
61+
- RAM: 2 GB
62+
- OS: Ubuntu 22.04 LTS
63+
- Public NAT enabled
64+
65+
---
66+
67+
## 4. Public IP Address of Created VM
68+
69+
```text
70+
93.77.177.208
71+
```
72+
73+
(Obtained from Terraform output.)
74+
75+
---
76+
77+
## 5. SSH Connection Command
78+
79+
80+
```shell
81+
ssh ubuntu@93.77.177.208
82+
```
83+
84+
---
85+
86+
## 6. Terminal Output – terraform plan
87+
88+
![terraform plan](screenshots/img_3.png)
89+
90+
---
91+
92+
## 7. Terminal Output – terraform apply
93+
94+
![terraform apply](screenshots/img_4.png)
95+
96+
97+
---
98+
99+
## 8. Proof of SSH Access to VM
100+
101+
After successful SSH login:
102+
103+
![image](screenshots/img_3.png)
104+
105+
106+
# Infrastructure Migration Report: Terraform → Pulumi
107+
108+
## 1. Programming Language Chosen for Pulumi
109+
110+
**Language:** Python
111+
112+
Reasoning:
113+
- Simple syntax and readability
114+
- Good integration with Pulumi SDK
115+
- Fast setup for infrastructure scripting
116+
- Suitable for backend-oriented workflow
117+
118+
Pulumi version used:
119+
120+
pulumi version
121+
v3.x.x
122+
123+
124+
---
125+
126+
## 2. Terraform Destroy Output
127+
128+
![Destroy Output](screenshots/img_5.png)
129+
130+
---
131+
132+
## 3. Pulumi Preview Output
133+
134+
135+
---
136+
137+
## 4. Pulumi Up Output
138+
139+
140+
141+
142+
---
143+
144+
## 5. Public IP of Pulumi-Created VM
145+
146+
51.250.xxx.xxx
147+
148+
149+
SSH access:
150+
151+
```shell
152+
ssh ubuntu@51.250.xxx.xxx
153+
```
154+
155+
156+
![login]()
157+
158+
159+
---
160+
161+
## 6. Comparison: Terraform vs Pulumi Experience
162+
163+
### What Was Easier in Terraform
164+
165+
- Clear declarative structure
166+
- Simple `.tf` syntax
167+
- Strong ecosystem and documentation
168+
- Easier to understand infrastructure layout at a glance
169+
170+
### What Was Harder in Terraform
171+
172+
- Limited logic capabilities
173+
- No native loops or conditions without workarounds
174+
- Separate HCL language (not general-purpose)
175+
176+
---
177+
178+
### What Was Easier in Pulumi
179+
180+
- Full programming language support (Python)
181+
- Ability to use variables, loops, conditions naturally
182+
- Better abstraction and reuse potential
183+
- Dynamic infrastructure definitions
184+
185+
### What Was Harder in Pulumi
186+
187+
- More verbose code
188+
- Requires dependency management (venv, pip)
189+
- Slightly more complex project structure
190+
- Harder to quickly read compared to simple HCL
191+
192+
---
193+
194+
## 7. Code Differences (HCL vs Python)
195+
196+
### Terraform (HCL Example)
197+
198+
```hcl
199+
resource "yandex_compute_instance" "vm" {
200+
name = "terraform1"
201+
202+
resources {
203+
cores = 2
204+
memory = 2
205+
}
206+
207+
network_interface {
208+
subnet_id = yandex_vpc_subnet.subnet.id
209+
nat = true
210+
}
211+
}
212+
Characteristics:
213+
214+
Declarative
215+
216+
Resource-based
217+
218+
Static structure
219+
220+
Limited programmability
221+
222+
Pulumi (Python Example)
223+
import pulumi
224+
import pulumi_yandex as yandex
225+
226+
network = yandex.VpcNetwork("net")
227+
228+
subnet = yandex.VpcSubnet("subnet",
229+
network_id=network.id,
230+
zone="ru-central1-a",
231+
v4_cidr_blocks=["10.0.0.0/24"]
232+
)
233+
234+
vm = yandex.ComputeInstance("vm",
235+
resources=yandex.ComputeInstanceResourcesArgs(
236+
cores=2,
237+
memory=2
238+
),
239+
network_interfaces=[yandex.ComputeInstanceNetworkInterfaceArgs(
240+
subnet_id=subnet.id,
241+
nat=True
242+
)]
243+
)
244+
245+
pulumi.export("public_ip", vm.network_interfaces[0].nat_ip_address)
246+
Characteristics:
247+
248+
Imperative style
249+
250+
Uses full Python language
251+
252+
Allows dynamic logic
253+
254+
Code-first infrastructure
255+
256+
8. Preferred Tool and Why
257+
Preferred tool: Terraform
258+
259+
Reason:
260+
261+
Simpler for small and medium infrastructure
262+
263+
Clear declarative model
264+
265+
Easier for teams without strong programming background
266+
267+
More standardized in DevOps industry
268+
269+
Pulumi is more flexible and powerful for complex, dynamic environments, but for straightforward infrastructure provisioning Terraform is more concise and easier to maintain.
82.6 KB
Loading
90.9 KB
Loading
87.7 KB
Loading

pulumi/Pulumi.dev.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
config:
2+
yc-infra:cloudId: b1glhaar472redp2m3to
3+
yc-infra:folderId: b1g1uj21m7e1md6p212p
4+
yc-infra:zone: ru-central1-a
5+
yc-infra:myIp: 188.130.155.177/32

pulumi/Pulumi.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: yc-infra
2+
runtime:
3+
name: python
4+
description: Yandex Cloud infrastructure via Pulumi

pulumi/main.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import pulumi
2+
import pulumi_yandex as yc
3+
from pulumi import Config
4+
5+
config = Config()
6+
7+
cloud_id = config.require("cloudId")
8+
folder_id = config.require("folderId")
9+
zone = config.require("zone")
10+
my_ip = config.require("myIp")
11+
12+
provider = yc.Provider(
13+
"yc-provider",
14+
cloud_id=cloud_id,
15+
folder_id=folder_id,
16+
zone=zone,
17+
service_account_key_file="authorized_key.json"
18+
)
19+
20+
network = yc.VpcNetwork(
21+
"net",
22+
name="net",
23+
opts=pulumi.ResourceOptions(provider=provider)
24+
)
25+
26+
subnet = yc.VpcSubnet(
27+
"subnet",
28+
name="subnet",
29+
zone=zone,
30+
network_id=network.id,
31+
v4_cidr_blocks=["10.0.0.0/24"],
32+
opts=pulumi.ResourceOptions(provider=provider)
33+
)
34+
35+
# Security Group
36+
security_group = yc.VpcSecurityGroup(
37+
"sg",
38+
network_id=network.id,
39+
ingress=[
40+
yc.VpcSecurityGroupIngressArgs(
41+
protocol="TCP",
42+
description="SSH",
43+
v4_cidr_blocks=[my_ip],
44+
port=22
45+
),
46+
yc.VpcSecurityGroupIngressArgs(
47+
protocol="TCP",
48+
description="HTTP",
49+
v4_cidr_blocks=["0.0.0.0/0"],
50+
port=80
51+
),
52+
yc.VpcSecurityGroupIngressArgs(
53+
protocol="TCP",
54+
description="App 5000",
55+
v4_cidr_blocks=["0.0.0.0/0"],
56+
port=5000
57+
),
58+
],
59+
egress=[
60+
yc.VpcSecurityGroupEgressArgs(
61+
protocol="ANY",
62+
v4_cidr_blocks=["0.0.0.0/0"]
63+
)
64+
],
65+
opts=pulumi.ResourceOptions(provider=provider)
66+
)
67+
68+
# Image
69+
image = yc.get_compute_image(family="ubuntu-2204-lts")
70+
71+
# VM
72+
vm = yc.ComputeInstance(
73+
"vm",
74+
name="pulumi-vm",
75+
platform_id="standard-v2",
76+
zone=zone,
77+
resources=yc.ComputeInstanceResourcesArgs(
78+
cores=2,
79+
memory=2
80+
),
81+
boot_disk=yc.ComputeInstanceBootDiskArgs(
82+
initialize_params=yc.ComputeInstanceBootDiskInitializeParamsArgs(
83+
image_id=image.id
84+
)
85+
),
86+
network_interfaces=[
87+
yc.ComputeInstanceNetworkInterfaceArgs(
88+
subnet_id=subnet.id,
89+
nat=True,
90+
security_group_ids=[security_group.id]
91+
)
92+
],
93+
metadata={
94+
"ssh-keys": f"ubuntu:{open('C:/Users/kve10/.ssh/id_ed25519.pub').read()}"
95+
},
96+
opts=pulumi.ResourceOptions(provider=provider)
97+
)
98+
99+
pulumi.export("public_ip", vm.network_interfaces.apply(lambda ni: ni[0].nat_ip_address))
100+
pulumi.export("internal_ip", vm.network_interfaces.apply(lambda ni: ni[0].ip_address))

pulumi/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pulumi>=3.0.0
2+
pulumi-yandex>=0.187.0

terraform/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.terraform/
2+
*.tfstate
3+
*.tfstate.backup
4+
authorized_key.json
5+
terraform.tfvars

0 commit comments

Comments
 (0)