yc2terraform 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. yc2terraform-0.0.2/PKG-INFO +368 -0
  2. yc2terraform-0.0.2/pyproject.toml +121 -0
  3. yc2terraform-0.0.2/readme.md +351 -0
  4. yc2terraform-0.0.2/setup.cfg +4 -0
  5. yc2terraform-0.0.2/tests/test_discovery.py +131 -0
  6. yc2terraform-0.0.2/tests/test_export.py +37 -0
  7. yc2terraform-0.0.2/tests/test_hcl.py +99 -0
  8. yc2terraform-0.0.2/yc2terraform/__init__.py +6 -0
  9. yc2terraform-0.0.2/yc2terraform/__init__.pyi +3 -0
  10. yc2terraform-0.0.2/yc2terraform/__main__.py +3 -0
  11. yc2terraform-0.0.2/yc2terraform/__main__.pyi +1 -0
  12. yc2terraform-0.0.2/yc2terraform/api.py +112 -0
  13. yc2terraform-0.0.2/yc2terraform/api.pyi +23 -0
  14. yc2terraform-0.0.2/yc2terraform/cli.py +258 -0
  15. yc2terraform-0.0.2/yc2terraform/cli.pyi +31 -0
  16. yc2terraform-0.0.2/yc2terraform/discovery.py +268 -0
  17. yc2terraform-0.0.2/yc2terraform/discovery.pyi +26 -0
  18. yc2terraform-0.0.2/yc2terraform/export.py +180 -0
  19. yc2terraform-0.0.2/yc2terraform/export.pyi +41 -0
  20. yc2terraform-0.0.2/yc2terraform/hcl.py +196 -0
  21. yc2terraform-0.0.2/yc2terraform/hcl.pyi +38 -0
  22. yc2terraform-0.0.2/yc2terraform/registry.py +242 -0
  23. yc2terraform-0.0.2/yc2terraform/registry.pyi +22 -0
  24. yc2terraform-0.0.2/yc2terraform/terraform.py +116 -0
  25. yc2terraform-0.0.2/yc2terraform/terraform.pyi +26 -0
  26. yc2terraform-0.0.2/yc2terraform/yc.py +56 -0
  27. yc2terraform-0.0.2/yc2terraform/yc.pyi +12 -0
  28. yc2terraform-0.0.2/yc2terraform.egg-info/PKG-INFO +368 -0
  29. yc2terraform-0.0.2/yc2terraform.egg-info/SOURCES.txt +31 -0
  30. yc2terraform-0.0.2/yc2terraform.egg-info/dependency_links.txt +1 -0
  31. yc2terraform-0.0.2/yc2terraform.egg-info/entry_points.txt +2 -0
  32. yc2terraform-0.0.2/yc2terraform.egg-info/requires.txt +3 -0
  33. yc2terraform-0.0.2/yc2terraform.egg-info/top_level.txt +1 -0
@@ -0,0 +1,368 @@
1
+ Metadata-Version: 2.4
2
+ Name: yc2terraform
3
+ Version: 0.0.2
4
+ Summary: Generate Terraform manifests (HCL) for existing Yandex Cloud resources
5
+ Author-email: Aleksei Marusich <aleksei.marusich@rocshers.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://projects.rocshers.com/open-source/yc2terraform
8
+ Project-URL: Repository, https://gitlab.com/rocshers/python/yc2terraform
9
+ Keywords: yandex-cloud,terraform,hcl,import,infrastructure-as-code
10
+ Classifier: Environment :: Console
11
+ Classifier: Topic :: System :: Systems Administration
12
+ Requires-Python: >=3.14
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: httpx>=0.28.1
15
+ Requires-Dist: rich>=15.0.0
16
+ Requires-Dist: typer>=0.29.1
17
+
18
+ # yc2terraform
19
+
20
+ [![PyPI](https://img.shields.io/pypi/v/yc2terraform)](https://pypi.org/project/yc2terraform/)
21
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/yc2terraform)](https://pypi.org/project/yc2terraform/)
22
+
23
+ [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=rocshers_yc2terraform&metric=coverage)](https://sonarcloud.io/summary/new_code?id=rocshers_yc2terraform)
24
+ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=rocshers_yc2terraform&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=rocshers_yc2terraform)
25
+
26
+ [![Downloads](https://pypi.rocshers.com/badges/svg/packages/yc2terraform/downloads/total)](https://clickpy.clickhouse.com/dashboard/yc2terraform)
27
+ [![GitLab stars](https://img.shields.io/gitlab/stars/rocshers/python/yc2terraform)](https://gitlab.com/rocshers/python/yc2terraform)
28
+ [![GitLab last commit](https://img.shields.io/gitlab/last-commit/rocshers/python/yc2terraform)](https://gitlab.com/rocshers/python/yc2terraform)
29
+
30
+ Generate Terraform manifests (HCL) for **existing** Yandex Cloud resources: one resource, a resource and everything it is linked to, a whole folder or a whole cloud.
31
+
32
+ It started as a rewrite of [yandex-cloud-examples/yc-terraformer](https://github.com/yandex-cloud-examples/yc-terraformer), a single-file script. The use cases and flags are the same. The changes are listed in [Differences from yc-terraformer](#differences-from-yc-terraformer).
33
+
34
+ ## Why
35
+
36
+ - **Move to Terraform**: bring resources created in the console or with `yc` under Terraform management.
37
+ - **Back up your configuration**: keep manifests of production resources so you can recreate them after an accidental deletion or an outage.
38
+ - **Clone an environment**: deploy the same configuration in another zone, folder or cloud (staging, load tests, migration during a zone outage).
39
+ - **Reproduce problems**: support engineers get the exact configuration of a customer's resource and can stand up a copy to debug it.
40
+ - **Learn Terraform**: change a setting in the console, export the resource, and see which Terraform arguments you need.
41
+ - **Investigate a surprising `terraform plan`**: export the live resource and compare it with your code.
42
+
43
+ ## Features
44
+
45
+ - `import SERVICE TYPE NAME [ID]` uses the `yc` naming, as yc-terraformer did. Any `yandex_*` type is supported. If you leave out the ID, it is looked up by name with `yc`.
46
+ - `--recursive` also exports linked resources: VM disks; DB users and databases; Kafka users, topics and connectors; ALB routers, virtual hosts, backend and target groups; NLB target groups; Data Transfer endpoints; VPC subnets, security groups and route tables; Kubernetes node groups.
47
+ - **Full folder dump in one command.** `yc2terraform folder` runs `yc <service> <type> list` for 55 resource types (IAM, VPC, Compute, Managed Kubernetes, every managed database, ALB/NLB, DNS, KMS, Certificate Manager, Lockbox, Object Storage, Serverless, Logging, Data Transfer, Data Proc, CDN, IoT) and exports everything it finds, with linked resources. `cloud` does the same for every folder of a cloud. Both replace the `yc ... list | jq | xargs` loops.
48
+ - **References instead of IDs.** When the referenced resource is exported too, the ID is written as a reference: `network_id = yandex_vpc_network.main.id`. References that would form a cycle (two security groups that cite each other) stay as IDs.
49
+ - **Variables for everything else.** Other `*_id` / `*_ids` values go to `yc2terraform.auto.tfvars.json`. Sensitive values such as passwords go to a separate `yc2terraform.secrets.auto.tfvars.json`, so the manifests can be committed.
50
+ - **Uses the provider schema.** Computed-only and deprecated attributes are dropped, and nested blocks are told apart from map attributes correctly. A small set of hand-written rules (inherited from yc-terraformer) covers the remaining quirks.
51
+ - **Does not touch your state.** Imports run in a temporary workspace with one state file per resource, in parallel (`--parallel`). Your project's state changes only with `--with-state`.
52
+ - **Safe to run again.** A second run into the same directory reuses the same resource names, overwrites the files it wrote before, merges variables, and references resources exported earlier.
53
+ - Output is passed through `terraform fmt`. Cloud-init and other multi-line values are written as heredocs.
54
+ - Works with Terraform >= 1.5 or OpenTofu (`--terraform tofu`).
55
+
56
+ ## Install
57
+
58
+ ```bash
59
+ uv tool install yc2terraform # or: pipx install yc2terraform
60
+ # one-off: uvx yc2terraform --help
61
+ ```
62
+
63
+ You also need `terraform` in `PATH`. In Russia, set up the Yandex provider mirror in `~/.terraformrc` ([guide](https://yandex.cloud/en/docs/tutorials/infrastructure-management/terraform-quickstart#configure-provider)). The provider is downloaded once and cached in `~/.cache/yc2terraform/plugins`.
64
+
65
+ ## Authentication
66
+
67
+ Read-only access is enough: give a service account (or yourself) the `viewer` role on the cloud or folder.
68
+
69
+ The tool needs a token for two things: the Terraform provider and, for `--recursive` / `folder` / `cloud`, the YC REST API. It looks for one in this order:
70
+
71
+ 1. `$YC_TOKEN`: an IAM token, or an OAuth token (exchanged for an IAM token automatically).
72
+ 2. `yc iam create-token`, if the `yc` CLI is installed and configured.
73
+
74
+ The `yc` CLI is optional but recommended. When it is installed, `folder` and `cloud` list resources through it, which covers every type `yc` knows. Without it, they fall back to the REST API, which covers fewer types (see `yc2terraform types`). `yc` uses your active profile; set `YC_PROFILE` to pick another one. The default folder is `$YC_FOLDER_ID`, then `yc config get folder-id`.
75
+
76
+ ```bash
77
+ export YC_TOKEN=$(yc iam create-token)
78
+ ```
79
+
80
+ A plain `import` without `--recursive` uses only the provider. For that, any [provider auth env var](https://yandex.cloud/en/docs/terraform/quickstart#configure-provider) works too, e.g. `YC_SERVICE_ACCOUNT_KEY_FILE`.
81
+
82
+ ## Quick start
83
+
84
+ ```bash
85
+ mkdir infra && cd infra
86
+
87
+ # One VM with its disks
88
+ yc2terraform import -r compute instance web-1 fhm0123456789abcdefg
89
+
90
+ # A PostgreSQL cluster with its users and databases
91
+ yc2terraform import -r managed-postgresql cluster pg-prod c9q0123456789abcdefg
92
+
93
+ # An ALB with its routers, virtual hosts, backend and target groups
94
+ yc2terraform import -r application-load-balancer load-balancer alb-main ds70123456789abcdefg
95
+
96
+ # A bucket (the import ID is the bucket name)
97
+ yc2terraform import storage bucket my-bucket
98
+
99
+ # Look the ID up by name (needs yc)
100
+ yc2terraform import -r compute instance web-1
101
+
102
+ # Everything in a folder, or only some types
103
+ yc2terraform folder # $YC_FOLDER_ID or the yc profile folder
104
+ yc2terraform folder b1g0123456789abcdefg -o prod/
105
+ yc2terraform folder b1g0123456789abcdefg --only compute.instance --only vpc.network
106
+
107
+ # Every folder in a cloud, one sub-directory each
108
+ yc2terraform cloud b1g9876543210abcdefg -o backup/
109
+
110
+ terraform init && terraform plan # expect: No changes
111
+ ```
112
+
113
+ `SERVICE` and `TYPE` are named as in `yc`: `iam service-account`, `vpc security-group`, `managed-kubernetes node-group`, `managed-kafka topic`, and so on. You can also pass a Terraform type directly: `yc2terraform import yandex_compute_instance - web-1 fhm...` (the second argument is then ignored). `yc2terraform types` lists the types that support recursion and folder export.
114
+
115
+ ## Examples
116
+
117
+ All examples use `uvx`, so nothing needs to be installed except `uv` and `terraform`. `yc` is recommended.
118
+
119
+ ### Full folder dump in one command
120
+
121
+ This replaces a hand-written `while read service resource; do yc $service $resource list ...; done` loop over every resource type. The type list is built in (`yc2terraform types` prints it):
122
+
123
+ ```bash
124
+ export YC_FOLDER_ID=b1g0123456789abcdefg # or: yc config set folder-id ...
125
+
126
+ uvx yc2terraform folder \
127
+ --with-state \
128
+ --import-ids \
129
+ --import-metadata
130
+ ```
131
+
132
+ What happens:
133
+
134
+ 1. `yc <service> <type> list --folder-id $YC_FOLDER_ID --format json` runs for every type, up to 8 at a time. If `yc` fails for a type, the REST API is tried. If both fail (no permission, service not enabled), the type is skipped with a warning.
135
+ 2. Linked resources are added: disks, DB users and databases, Kafka topics, ALB virtual hosts, node groups, and so on.
136
+ 3. Resources that were created automatically are skipped: VMs and disks of instance groups and Kubernetes node groups, and the default security group of each network.
137
+ 4. Everything is imported in parallel, written as one file per resource, then imported into the state of the current directory (`--with-state`).
138
+
139
+ Useful variations:
140
+
141
+ ```bash
142
+ # Into a separate directory, without touching any state
143
+ uvx yc2terraform folder -o "dump-$(date +%F)/"
144
+
145
+ # Only some types, or everything except some
146
+ uvx yc2terraform folder --only vpc.network --only "compute instance" --only managed-postgresql.cluster
147
+ uvx yc2terraform folder --skip storage.bucket --skip "serverless function"
148
+
149
+ # Another folder or yc profile
150
+ YC_PROFILE=prod uvx yc2terraform folder b1g9876543210abcdefg -o prod/
151
+
152
+ # Every folder of a cloud: backup/<folder-name>/
153
+ uvx yc2terraform cloud "$CLOUD_ID" -o backup/ --import-ids
154
+ ```
155
+
156
+ ### Every VM in a folder (the yc-terraformer way)
157
+
158
+ The pipeline from yc-terraformer works as before: `xargs` adds `NAME ID` to the end of each command.
159
+
160
+ ```bash
161
+ yc compute instance list \
162
+ --folder-id "$FOLDER_ID" \
163
+ --format json |
164
+ jq -r '.[] | "\(.name) \(.id)"' |
165
+ xargs -n 2 uvx yc2terraform import \
166
+ --with-state \
167
+ --import-ids \
168
+ --import-metadata \
169
+ --recursive compute instance
170
+ ```
171
+
172
+ The same with the built-in command. It runs once, imports in parallel, writes references between the VMs and their disks, and skips VMs owned by instance groups or Kubernetes node groups. Recursion is on by default here:
173
+
174
+ ```bash
175
+ uvx yc2terraform folder "$FOLDER_ID" \
176
+ --only compute.instance \
177
+ --with-state \
178
+ --import-ids \
179
+ --import-metadata
180
+ ```
181
+
182
+ ### Other resource types with `yc` + `xargs`
183
+
184
+ Any `yc <service> <type> list` works the same way:
185
+
186
+ ```bash
187
+ yc managed-postgresql cluster list --folder-id "$FOLDER_ID" --format json |
188
+ jq -r '.[] | "\(.name) \(.id)"' |
189
+ xargs -n 2 uvx yc2terraform import -r -o pg/ managed-postgresql cluster
190
+
191
+ yc vpc security-group list --folder-id "$FOLDER_ID" --format json |
192
+ jq -r '.[] | "\(.name) \(.id)"' |
193
+ xargs -n 2 uvx yc2terraform import -o vpc/ vpc security-group
194
+ ```
195
+
196
+ ### Every folder of a cloud
197
+
198
+ ```bash
199
+ # Built in: one sub-directory per folder
200
+ uvx yc2terraform cloud "$CLOUD_ID" -o backup/
201
+
202
+ # Or with yc, when you need your own folder filter
203
+ yc resource-manager folder list --cloud-id "$CLOUD_ID" --format json |
204
+ jq -r '.[] | select(.name | startswith("prod-")) | "\(.id) \(.name)"' |
205
+ while read -r id name; do
206
+ uvx yc2terraform folder "$id" -o "backup/$name"
207
+ done
208
+ ```
209
+
210
+ ### Configuration backup (daily, e.g. from cron or CI)
211
+
212
+ The manifests keep only configuration and contain no secrets, so they can be committed. Add `*.secrets.auto.tfvars.json` to `.gitignore`.
213
+
214
+ ```bash
215
+ uvx yc2terraform folder "$FOLDER_ID" -o infra-backup/ --import-ids
216
+ cd infra-backup && git add -A && git commit -m "Snapshot $(date +%F)"
217
+ ```
218
+
219
+ ### Clone an environment into another folder
220
+
221
+ ```bash
222
+ uvx yc2terraform folder "$PROD_FOLDER_ID" -o staging/ --skip storage.bucket
223
+ cd staging
224
+ # edit yc2terraform.auto.tfvars.json: folder_id -> staging folder, zones, subnet IDs, ...
225
+ # rename anything that has to be globally unique (buckets, DNS zones, registries)
226
+ terraform init && terraform plan
227
+ ```
228
+
229
+ Without `--import-ids`, folder and other IDs are written as variables, and links between exported resources become references. Usually changing `folder_id` is enough.
230
+
231
+ ### Adopt existing resources into Terraform
232
+
233
+ Using import blocks: `terraform plan` shows what will be imported, and `apply` writes it to state.
234
+
235
+ ```bash
236
+ uvx yc2terraform import -r --import-blocks managed-kubernetes cluster k8s-prod "$CLUSTER_ID"
237
+ terraform init && terraform plan # expect: N to import, 0 to add, 0 to change, 0 to destroy
238
+ terraform apply
239
+ ```
240
+
241
+ Or import right away with `--with-state`:
242
+
243
+ ```bash
244
+ uvx yc2terraform import -r --with-state application-load-balancer load-balancer alb-main "$ALB_ID"
245
+ terraform plan # expect: No changes
246
+ ```
247
+
248
+ ### Reproduce a customer's resource (support)
249
+
250
+ ```bash
251
+ uvx yc2terraform import -r -o repro/ managed-kafka cluster kafka-1 "$CLUSTER_ID"
252
+ cd repro && terraform init && terraform apply # creates a copy in your folder
253
+ # when done:
254
+ terraform destroy && cd .. && rm -rf repro
255
+ ```
256
+
257
+ ### Learn which Terraform arguments a console setting maps to
258
+
259
+ ```bash
260
+ uvx yc2terraform import -o before/ compute instance web-1 "$VM_ID"
261
+ # change the setting in the console
262
+ uvx yc2terraform import -o after/ compute instance web-1 "$VM_ID"
263
+ diff -ru before/ after/
264
+ ```
265
+
266
+ ### OpenTofu, a pinned version, debugging
267
+
268
+ ```bash
269
+ uvx yc2terraform import --terraform tofu vpc network main "$NETWORK_ID"
270
+ uvx yc2terraform@1.2.3 folder "$FOLDER_ID" # pin any published version
271
+ uvx yc2terraform import --debug -r compute instance web-1 "$VM_ID"
272
+ ```
273
+
274
+ ## Output
275
+
276
+ ```
277
+ infra/
278
+ ├── provider.tf # written only if no provider "yandex" exists yet
279
+ ├── yandex_compute_instance.web-1.tf # one file per resource
280
+ ├── yandex_compute_disk.web-1-boot.tf
281
+ ├── yc2terraform.variables.tf # variable declarations (regenerated)
282
+ ├── yc2terraform.auto.tfvars.json # IDs: folder_id, subnet_id, ...
283
+ └── yc2terraform.secrets.auto.tfvars.json # sensitive values: add this file to .gitignore
284
+ ```
285
+
286
+ ```hcl
287
+ # yc2terraform: yandex_compute_instance fhm0123456789abcdefg
288
+ resource "yandex_compute_instance" "web-1" {
289
+ folder_id = var.folder_id
290
+ name = "web-1"
291
+ platform_id = "standard-v3"
292
+ zone = "ru-central1-a"
293
+ boot_disk {
294
+ disk_id = yandex_compute_disk.web-1-boot.id
295
+ }
296
+ network_interface {
297
+ subnet_id = var.subnet_id
298
+ security_group_ids = var.security_group_ids
299
+ }
300
+ resources {
301
+ cores = 2
302
+ memory = 4
303
+ }
304
+ }
305
+ ```
306
+
307
+ The header comment records the import ID. Later runs use it to keep the same address for the same cloud resource.
308
+
309
+ ## Options
310
+
311
+ | Option | Meaning |
312
+ | --- | --- |
313
+ | `-o, --output DIR` | Where to write files (default: current directory). |
314
+ | `-r, --recursive` | `import`: also export linked resources. On by default for `folder`/`cloud`; turn off with `--no-recursive`. |
315
+ | `--import-ids` | Keep literal IDs in manifests instead of moving them to variables. References to exported resources are still used. |
316
+ | `--import-metadata` | Keep `metadata` on instances and instance group templates. It is dropped by default because it holds cloud-init and SSH keys. |
317
+ | `--with-state` | After writing the files, run `terraform import` into the output directory's state. Resources already in state are skipped. |
318
+ | `--import-blocks` | Add `import { to = ..., id = ... }` blocks (Terraform >= 1.5). `terraform plan` then shows the imports, and `apply` adopts them. |
319
+ | `--only TYPE`, `--skip TYPE` | `folder`/`cloud`: limit the exported types (`compute.instance`, `"compute instance"` or `yandex_compute_instance`). Repeatable. |
320
+ | `--folder-id ID` | `import`: folder for the name lookup when ID is omitted. |
321
+ | `-p, --parallel N` | Number of concurrent `terraform import` processes (default 4). |
322
+ | `--terraform BIN` | Terraform binary, e.g. `tofu`. |
323
+ | `--debug` | Verbose logs, including every API call and terraform command. |
324
+
325
+ The exit code is 0 on success, 1 if any resource failed (the others are still written), and 2 on setup errors (no terraform, no token).
326
+
327
+ ## How it works
328
+
329
+ 1. **Discover.** `folder`/`cloud` list resources with `yc` (falling back to the REST API). With `--recursive` (on by default for `folder`), the REST API is used to find linked resources. Requests run concurrently, and each resource is visited only once.
330
+ 2. **Import.** In a temporary directory with a bare `provider "yandex" {}`, each resource gets an empty stub and is imported with `terraform import -state=<own file>`. Imports run in parallel.
331
+ 3. **Convert.** The state attributes are filtered through the provider schema (`terraform providers schema -json`) and the cleanup rules in `registry.py`. Then IDs become references or variables, and the result is rendered as HCL and run through `terraform fmt`.
332
+ 4. **Verify.** You run `terraform plan`. If it wants changes, fix the manifest, and please [open an issue](https://gitlab.com/rocshers/python/yc2terraform/-/issues) with the resource type and the plan diff.
333
+
334
+ ## Safety
335
+
336
+ - Everything is read-only until you `apply`. Without `--with-state` and `--import-blocks`, your state is never changed.
337
+ - Be careful with `--with-state`, `--import-blocks` and `--import-ids`. Once the manifests are bound to live resources, a careless edit followed by `apply` changes production. If you only needed a copy or a repro, remove the files and run `terraform state rm` afterwards.
338
+ - `*.secrets.auto.tfvars.json` contains plaintext secrets (DB user passwords and other sensitive provider attributes). Keep it out of git.
339
+
340
+ ## Differences from yc-terraformer
341
+
342
+ | yc-terraformer | yc2terraform |
343
+ | --- | --- |
344
+ | `yc-terraformer.py [flags] service type name id` | `yc2terraform import [flags] service type name [id]` |
345
+ | Runs in your Terraform project and writes stubs and state there | Isolated temporary workspace; your state changes only with `--with-state` |
346
+ | Imports run one at a time, with `sleep(1)` | Concurrent API discovery and parallel imports |
347
+ | Hand-written list of fields to delete | Provider schema plus a small set of rules |
348
+ | `*_id` → `var.*`, and you write `variables.tf` / `terraform.tfvars` yourself | References between exported resources; variables and values generated and merged |
349
+ | `yc list \| jq \| xargs` loops for bulk export | `folder` (55 types, via `yc` or REST) and `cloud` commands |
350
+ | ID is required | ID optional: looked up by name with `yc` |
351
+ | Resource name `<name>_<root id>`, can be invalid HCL | Names cleaned up and made unique, stable across runs |
352
+ | ALB routes to backend groups were never followed (camelCase/snake_case mix-up) | Fixed; TLS/SNI handlers are followed too |
353
+
354
+ ## Development
355
+
356
+ ```bash
357
+ make test # pytest; the end-to-end test uses tests/fake_terraform.py, so no cloud or terraform is needed
358
+ make format # ruff + mypy
359
+ ```
360
+
361
+ Layout: `cli.py` (Typer commands), `export.py` (the pipeline), `discovery.py` (recursive and folder discovery), `api.py` (async YC REST client), `yc.py` (`yc` CLI wrapper), `terraform.py` (subprocess wrapper and workspace), `hcl.py` (rendering, variables), `registry.py` (type mapping, API paths, cleanup rules).
362
+
363
+ To add a type to the folder dump, add its `yc` pair to `registry.FOLDER_KINDS`. If its Terraform name doesn't follow `yandex_<service>_<type>`, add it to `registry.TYPE_OVERRIDE`. To support recursion for a type, add its REST collection to `registry.API` and an expander to `discovery.EXPANDERS`.
364
+
365
+ ## Contribute
366
+
367
+ Issue Tracker: <https://gitlab.com/rocshers/python/yc2terraform/-/issues>
368
+ Source Code: <https://gitlab.com/rocshers/python/yc2terraform>
@@ -0,0 +1,121 @@
1
+ [project]
2
+ name = "yc2terraform"
3
+ dynamic = ["version"]
4
+ description = "Generate Terraform manifests (HCL) for existing Yandex Cloud resources"
5
+ readme = "readme.md"
6
+ license = {text = "MIT"}
7
+ authors = [
8
+ {name = "Aleksei Marusich", email = "aleksei.marusich@rocshers.com"}
9
+ ]
10
+ classifiers = [
11
+ "Environment :: Console",
12
+ "Topic :: System :: Systems Administration",
13
+ ]
14
+ keywords = ["yandex-cloud", "terraform", "hcl", "import", "infrastructure-as-code"]
15
+ requires-python = ">=3.14"
16
+ dependencies = [
17
+ "httpx>=0.28.1",
18
+ "rich>=15.0.0",
19
+ "typer>=0.29.1",
20
+ ]
21
+
22
+ [dependency-groups]
23
+ dev = [
24
+ "mypy>=1.13.0",
25
+ "pre-commit>=4.0.1",
26
+ "pre-commit-hooks>=5.0.0",
27
+ "pytest>=8.3.3",
28
+ "pytest-asyncio>=0.24.0",
29
+ "ruff>=0.7.3",
30
+ "pytest-cov>=6.0.0",
31
+ ]
32
+
33
+ [project.scripts]
34
+ yc2terraform = "yc2terraform.cli:main"
35
+
36
+ [project.urls]
37
+ Homepage = "https://projects.rocshers.com/open-source/yc2terraform"
38
+ Repository = "https://gitlab.com/rocshers/python/yc2terraform"
39
+
40
+ [build-system]
41
+ requires = ["setuptools", "wheel", "versioningit"]
42
+ build-backend = "setuptools.build_meta"
43
+
44
+ [tool.uv]
45
+ package = true
46
+
47
+ [tool.versioningit.vcs]
48
+ default-tag = "0.0.0"
49
+
50
+ [tool.setuptools]
51
+ packages = ["yc2terraform"]
52
+ license-files = []
53
+
54
+ [tool.black]
55
+ skip-string-normalization = true
56
+ line-length = 120
57
+
58
+ [tool.isort]
59
+ profile = "black"
60
+ line_length = 120
61
+
62
+ [tool.ruff]
63
+ line-length = 120
64
+ target-version = "py313"
65
+ unsafe-fixes = true
66
+
67
+ [tool.ruff.format]
68
+ preview = true
69
+ quote-style = "single"
70
+
71
+ [tool.ruff.lint]
72
+ preview = true
73
+ select = ["A", "B", "C", "D", "E", "F", "I", "UP"]
74
+ fixable = ["A", "B", "C", "D", "E", "F", "I", "UP"]
75
+ ignore = ["UP004", "D100", "D101", "D102", "D103", "D104", "D107", "D415", "D105", "D106", "D203", "D213", "B008", "E501", "D205", "A002"]
76
+
77
+ [tool.ruff.lint.flake8-quotes]
78
+ inline-quotes = "single"
79
+
80
+ [tool.coverage.run]
81
+ omit = [
82
+ "*/tests/*",
83
+ "*/__main__.py",
84
+ "*/base.py",
85
+ ]
86
+
87
+ [tool.coverage.report]
88
+ exclude_lines = [
89
+ "pragma: no cover",
90
+ "def __repr__",
91
+ "raise AssertionError",
92
+ "raise NotImplementedError",
93
+ "if __name__ == .__main__.:",
94
+ ]
95
+
96
+ [tool.pytest.ini_options]
97
+ addopts = "-vvs --tb=short"
98
+ testpaths = [
99
+ "tests",
100
+ "integration",
101
+ ]
102
+ python_files = [
103
+ "tests/*.py",
104
+ "test_*.py"
105
+ ]
106
+ filterwarnings = [
107
+ "ignore::DeprecationWarning",
108
+ "ignore:Module already imported:pytest.PytestWarning"
109
+ ]
110
+ log_cli=true
111
+ log_level='INFO'
112
+ xfail_strict = true
113
+ asyncio_mode = "auto"
114
+ asyncio_default_fixture_loop_scope = "session"
115
+
116
+ [tool.mypy]
117
+ python_version = "3.14"
118
+ ignore_missing_imports = true
119
+
120
+ [tool.yc2terraform]
121
+ release_type = "dev"