{"id":470837,"date":"2025-08-15T15:00:06","date_gmt":"2025-08-15T15:00:06","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=470837"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=470837","title":{"rendered":"<span>DevOps Tutorials \u2014 Terraform: \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0432 \u043e\u0431\u043b\u0430\u043a\u0435<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ma\/po\/lv\/mapolvqq4uunxfqoaviv3g9km9y.jpeg\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/ma\/po\/lv\/mapolvqq4uunxfqoaviv3g9km9y.jpeg 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/ma\/po\/lv\/mapolvqq4uunxfqoaviv3g9km9y.jpeg 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0434\u0440\u0443\u0437\u044c\u044f!<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u044f \u0434\u0435\u043b\u044e\u0441\u044c \u0441 \u0432\u0430\u043c\u0438 \u0441\u0432\u043e\u0438\u043c \u043e\u043f\u044b\u0442\u043e\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0438\u0437 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e.<\/p>\n<p>\u0414\u0440\u0443\u0433\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0441\u0435\u0440\u0438\u0438:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/companies\/timeweb\/articles\/913426\/\" rel=\"noopener noreferrer nofollow\">DevOps Tutorials \u2014 Ansible: \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435<\/a><\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u044b\u043b\u0430 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u0434\u0435\u043f\u043b\u043e\u044e Angular+Java \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435 Ubuntu Linux \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Ansible. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u0435\u043f\u043b\u043e\u044f \u0441\u0435\u0442\u044c \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0432 \u043e\u0431\u043b\u0430\u043a\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Terraform.<\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e? \u0422\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0448\u0443 \u043f\u043e\u0434 \u043a\u0430\u0442.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430\u0448\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 &#8212; \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u043e\u0431\u043b\u0430\u0447\u043d\u0443\u044e \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043a \u0434\u0435\u043f\u043b\u043e\u044e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e:<\/p>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 Ubuntu Linux \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c <code>ansible<\/code><\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u0438\u0439 IP-\u0430\u0434\u0440\u0435\u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f CLI <code>ansible<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0431\u043b\u0430\u043a\u0430 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Yandex Cloud. <em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435,<\/em> \u0447\u0442\u043e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f Terraform \u0441\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043e\u0431\u043b\u0430\u043a\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043e\u0431\u043b\u0430\u043a\u0435 \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0438\u043d\u0430\u0447\u0435.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/developer.hashicorp.com\/terraform\/tutorials\/aws-get-started\/install-cli\" rel=\"noopener noreferrer nofollow\">\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 terraform<\/a> (\u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0440\u0441\u0438\u044e 1.5.7)<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/yandex.cloud\/ru\/docs\/cli\/operations\/install-cli\" rel=\"noopener noreferrer nofollow\">\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 yc<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/yandex.cloud\/ru\/docs\/iam\/concepts\/authorization\/oauth-token\" rel=\"noopener noreferrer nofollow\">OAuth-\u0442\u043e\u043a\u0435\u043d Yandex Cloud<\/a> (<code>yc config set token &lt;OAuth-\u0442\u043e\u043a\u0435\u043d&gt;<\/code>)<\/p>\n<\/li>\n<\/ul>\n<h3>\u041f\u0430\u0440\u0430 \u0441\u043b\u043e\u0432 \u043e Terraform<\/h3>\n<p><a href=\"https:\/\/developer.hashicorp.com\/terraform\" rel=\"noopener noreferrer nofollow\">Terraform<\/a> \u2014 \u044d\u0442\u043e \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043a\u0430\u043a \u043a\u043e\u0434 (IaC) \u2014 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0435\u0439 HashiCorp, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0432 \u043e\u0431\u043b\u0430\u043a\u0430\u0445 \u0438 \u0434\u0430\u0442\u0430-\u0446\u0435\u043d\u0442\u0440\u0430\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432.<\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 Terraform:<\/p>\n<ul>\n<li>\n<p>\u042f\u0437\u044b\u043a \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438<\/p>\n<\/li>\n<\/ul>\n<p>Terraform \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 HCL (HashiCorp Configuration Language) \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 \u044f\u0437\u044b\u043a, \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u043d\u0430 JSON. \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442 \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u0430\u0448\u0438\u043d\u044b, \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u0435\u0442\u0438 \u0438 \u0442.\u0434.<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u0432<\/p>\n<\/li>\n<\/ul>\n<p>Terraform \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430\u043c\u0438 \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438:<\/p>\n<ul>\n<li>\n<p>AWS<\/p>\n<\/li>\n<li>\n<p>Google Cloud Platform<\/p>\n<\/li>\n<li>\n<p>Microsoft Azure<\/p>\n<\/li>\n<li>\n<p>Yandex Cloud<\/p>\n<\/li>\n<li>\n<p>Kubernetes<\/p>\n<\/li>\n<li>\n<p>\u0438 \u0434\u0440.<\/p>\n<\/li>\n<li>\n<p>\u0423\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u043c \u0446\u0438\u043a\u043b\u043e\u043c \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b<\/p>\n<\/li>\n<\/ul>\n<p>Terraform \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442:<\/p>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 (<code>terraform apply<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e<\/p>\n<\/li>\n<li>\n<p>\u0443\u0434\u0430\u043b\u044f\u0442\u044c \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b (<code>terraform destroy<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u041f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u0430 <code>terraform plan<\/code> \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0432\u043d\u0435\u0441\u0435\u043d\u044b \u0432 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u044b \u2014 \u044d\u0442\u043e \u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u0440\u0438\u0441\u043a \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<ul>\n<li>\n<p>\u0418\u0434\u0435\u043c\u043f\u043e\u0442\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 Terraform \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0442\u0435\u043c \u0436\u0435 \u2014 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.<\/p>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/companies\/otus\/articles\/696694\/\" rel=\"noopener noreferrer nofollow\">\u041e\u0441\u043d\u043e\u0432\u044b Terraform<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/1cloud.ru\/blog\/introduce_in_terraform\" rel=\"noopener noreferrer nofollow\">\u041e\u0441\u043d\u043e\u0432\u044b Terraform: \u0440\u0430\u0431\u043e\u0442\u0430 \u0438 \u0437\u0430\u0434\u0430\u0447\u0438<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/companies\/nixys\/articles\/721404\/\" rel=\"noopener noreferrer nofollow\">Terraform: \u043e\u0442 \u043d\u0435\u0437\u043d\u0430\u043d\u0438\u044f \u043a best practices<\/a> (\u0431\u043b\u0438\u0437\u043a\u043e \u043a \u0442\u043e\u043c\u0443, \u0447\u0435\u043c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435)<\/p>\n<\/li>\n<\/ul>\n<h3>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f Terraform<\/h3>\n<p>\u0412 \u0434\u043e\u043c\u0430\u0448\u043d\u0435\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 (<code>\/home\/&lt;user&gt;<\/code>) \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b <code>.terraformrc<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f:<\/p>\n<pre><code>provider_installation {   network_mirror {     url = \"https:\/\/terraform-mirror.yandexcloud.net\/\"     include = [\"registry.terraform.io\/*\/*\"]   }   direct {     exclude = [\"registry.terraform.io\/*\/*\"]   } } <\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e <code>terraform<\/code> \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439:<\/p>\n<pre><code>- main.tf - provider.tf - user-data.txt - variables.tf - versions.tf <\/code><\/pre>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430 \u0432 \u0444\u0430\u0439\u043b\u0430\u0445 <code>versions.tf<\/code> \u0438 <code>provider.tf<\/code>.<\/p>\n<p><code>versions.tf<\/code>:<\/p>\n<pre><code>terraform {   required_providers {     yandex = {       source  = \"yandex-cloud\/yandex\"       version = \"&gt;= 0.87.0\"     }   }    # \u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f Terraform (terraform.tfstate) \u0432 \u0431\u0430\u043a\u0435\u0442\u0435 (bucket) Yandex Cloud   # backend \"s3\" {   #   endpoint = \"https:\/\/storage.yandexcloud.net\"   #   bucket   = \"terraform-state\"   #   region   = \"ru-central1\"   #   key      = \"terraform.tfstate\"    #   skip_region_validation      = true   #   skip_credentials_validation = true   # } } <\/code><\/pre>\n<p><code>provider.tf<\/code>:<\/p>\n<pre><code>provider \"yandex\" {   cloud_id  = var.cloud_id   folder_id = var.folder_id   zone      = var.zone } <\/code><\/pre>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432 \u0444\u0430\u0439\u043b\u0435 <code>variables.tf<\/code>:<\/p>\n<pre><code>variable \"cloud_id\" {   type = string   # \u0417\u0430\u043c\u0435\u043d\u0438\u0442\u044c   default = \"b1g...\" }  variable \"folder_id\" {   type = string   # \u0417\u0430\u043c\u0435\u043d\u0438\u0442\u044c   default = \"b1g...\" }  variable \"zone\" {   type = string   default = \"ru-central1-a\" } <\/code><\/pre>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u0444\u0430\u0439\u043b\u0435 <code>user-data.txt<\/code> (\u043e\u043d \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u043c \u043f\u043e\u0437\u0434\u043d\u0435\u0435):<\/p>\n<pre><code>#cloud-config users:   - name: ansible     shell: \/bin\/bash     sudo: \"ALL=(ALL) NOPASSWD:ALL\"     ssh_authorized_keys:       # \u0417\u0430\u043c\u0435\u043d\u0438\u0442\u044c       - ssh-rsa AAA... <\/code><\/pre>\n<p><em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435:<\/em><\/p>\n<ul>\n<li>\n<p>\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 <code>#cloud-config<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0432\u0435\u0440\u0441\u0438\u0438 Terraform<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e Terraform \u0432 \u0444\u0430\u0439\u043b\u0435 <code>main.tf<\/code>:<\/p>\n<pre><code>module \"instance\" {   source = \".\/modules\/tf-yc-instance\"   subnet_id = module.network.subnet_ids[var.zone] }  module \"network\" {   source = \".\/modules\/tf-yc-network\" }  output \"external_ip\" {   value = module.instance.external_ip }  output \"internal_ip\" {   value = module.instance.internal_ip }  output \"network_id\" {   value = module.network.network_id }  output \"subnet_ids\" {   value = module.network.subnet_ids } <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 2 \u043c\u043e\u0434\u0443\u043b\u0435\u0439: <code>instance<\/code> \u0434\u043b\u044f \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b \u0438 <code>network<\/code> \u0434\u043b\u044f \u0441\u0435\u0442\u0438. <em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435,<\/em> \u0447\u0442\u043e \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c ID \u043f\u043e\u0434\u0441\u0435\u0442\u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0437\u043e\u043d\u0435 <code>ru-central1-a<\/code> (<code>subnet_id<\/code>), \u0438\u0437 \u043c\u043e\u0434\u0443\u043b\u044f <code>network<\/code> \u0432 \u043c\u043e\u0434\u0443\u043b\u044c <code>instance<\/code>. \u0422\u0430\u043a\u0436\u0435 \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c Terraform \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0438 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 IP-\u0430\u0434\u0440\u0435\u0441\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, ID \u0441\u0435\u0442\u0438 \u0438 \u043f\u043e\u0434\u0441\u0435\u0442\u0435\u0439. \u0418\u0437 \u044d\u0442\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u0439 IP, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0430\u0434\u0438 \u0437\u0430\u0431\u0430\u0432\u044b.<\/p>\n<p>\u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f Terraform \u0432 \u0444\u0430\u0439\u043b <code>.gitignore<\/code>:<\/p>\n<pre><code>*.tfstate *.tfstate.* <\/code><\/pre>\n<h3>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f \u0441\u0435\u0442\u0438<\/h3>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e <code>modules\/tf-yc-network<\/code> \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439:<\/p>\n<pre><code>- main.tf - outputs.tf - README.md - variables.tf - versions.tf <\/code><\/pre>\n<p>\u0424\u0430\u0439\u043b <code>versions.tf<\/code> \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u0435\u043d \u043e\u0434\u043d\u043e\u0438\u043c\u0435\u043d\u043d\u043e\u043c\u0443 \u0444\u0430\u0439\u043b\u0443 \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>terraform<\/code> (\u0431\u0435\u0437 \u0431\u043b\u043e\u043a\u0430 <code>s3<\/code>).<\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u0441\u0435\u0442\u0438 \u0438 \u043f\u043e\u0434\u0441\u0435\u0442\u0438 \u0432 \u0444\u0430\u0439\u043b\u0435 <code>main.tf<\/code>:<\/p>\n<pre><code>data \"yandex_vpc_network\" \"default\" {   name = \"default\" }  data \"yandex_vpc_subnet\" \"default\" {   for_each = var.network_zones   name     = \"default-${each.value}\" } <\/code><\/pre>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0432 \u0444\u0430\u0439\u043b\u0435 <code>variables.tf<\/code>:<\/p>\n<pre><code>variable \"network_zones\" {   description = \"\u0421\u043f\u0438\u0441\u043e\u043a \u0437\u043e\u043d \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u0434\u0441\u0435\u0442\u0435\u0439\"   type        = set(string)   default     = [\"ru-central1-a\", \"ru-central1-b\", \"ru-central1-d\"] } <\/code><\/pre>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0444\u0430\u0439\u043b\u0435 <code>outputs.tf<\/code>:<\/p>\n<pre><code>output \"network_id\" {   description = \"ID \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438\"   value       = data.yandex_vpc_network.default.id }  output \"subnet_ids\" {   description = \"ID \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0434\u0441\u0435\u0442\u0435\u0439\"   value       = { for zone, subnet in data.yandex_vpc_subnet.default : zone =&gt; subnet.id } } <\/code><\/pre>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 <code>yandex_vpc_subnet<\/code> \u0438 \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c <code>subnet_ids<\/code> \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435.<\/p>\n<ul>\n<li>\n<p><code>data \"yandex_vpc_subnet\" \"default\"<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u042d\u0442\u043e\u0442 \u0431\u043b\u043e\u043a \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u043e\u0434\u0441\u0435\u0442\u0438 \u043f\u043e \u0438\u043c\u0435\u043d\u0438 <code>default-&lt;zone&gt;<\/code> \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0437\u043e\u043d\u0430\u0445.<br \/> \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>for_each<\/code> \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0443 \u0437\u043e\u043d, \u0437\u043d\u0430\u0447\u0438\u0442, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u0441\u0435\u0442\u0435\u0439, \u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u043d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u0437\u043e\u043d\u0443 \u0438\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>network_zones<\/code>.<\/p>\n<p>Terraform \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b:<\/p>\n<pre><code>data.yandex_vpc_subnet.default[\"ru-central1-a\"] data.yandex_vpc_subnet.default[\"ru-central1-b\"] data.yandex_vpc_subnet.default[\"ru-central1-d\"] <\/code><\/pre>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043a\u0430\u0442\u044c \u043f\u043e\u0434\u0441\u0435\u0442\u044c \u0441 \u0438\u043c\u0435\u043d\u0435\u043c:<\/p>\n<ul>\n<li>\n<p><code>default-ru-central1-a<\/code><\/p>\n<\/li>\n<li>\n<p><code>default-ru-central1-b<\/code><\/p>\n<\/li>\n<li>\n<p><code>default-ru-central1-d<\/code><\/p>\n<\/li>\n<li>\n<p><code>output \"subnet_ids\"<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u042d\u0442\u043e\u0442 \u0431\u043b\u043e\u043a \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0441\u043b\u043e\u0432\u0430\u0440\u044c (map), \u0433\u0434\u0435:<\/p>\n<ul>\n<li>\n<p>\u043a\u043b\u044e\u0447 \u2014 \u044d\u0442\u043e \u0438\u043c\u044f \u0437\u043e\u043d\u044b (<code>ru-central1-a<\/code> \u0438 \u0442.\u0434.)<\/p>\n<\/li>\n<li>\n<p>\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u2014 \u044d\u0442\u043e <code>subnet.id<\/code> (\u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0439 \u043f\u043e\u0434\u0441\u0435\u0442\u0438)<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434:<\/p>\n<pre><code>subnet_ids = {   \"ru-central1-a\" = \"e2lu123abcde12345678\"   \"ru-central1-b\" = \"e2lu456fghij45678901\"   \"ru-central1-d\" = \"e2lu789klmno78901234\" } <\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0432\u044b\u0432\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u043f\u043e\u0434\u0441\u0435\u0442\u0438 <code>ru-central1-a<\/code> \u0432 \u043c\u043e\u0434\u0443\u043b\u044c <code>instance<\/code>.<\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ul>\n<li>\n<p>\u0432\u0441\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0434\u0441\u0435\u0442\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 Yandex Cloud \u0441 \u0438\u043c\u0435\u043d\u0430\u043c\u0438 <code>default-ru-central1-a<\/code> \u0438 \u0442.\u0434. \u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u043e\u0439 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u2014 Terraform \u0432\u044b\u0434\u0430\u0441\u0442 \u043e\u0448\u0438\u0431\u043a\u0443<\/p>\n<\/li>\n<li>\n<p>\u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 <code>data<\/code>, \u0430 \u043d\u0435 \u0441 <code>resource<\/code>, \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f, \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f<\/p>\n<\/li>\n<\/ul>\n<h3>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/h3>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e <code>modules\/tf-yc-instance<\/code> \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439:<\/p>\n<pre><code>- main.tf - outputs.tf - README.md - variables.tf - versions.tf <\/code><\/pre>\n<p>\u0424\u0430\u0439\u043b <code>versions.tf<\/code> \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u0435\u043d \u043e\u0434\u043d\u043e\u0438\u043c\u0435\u043d\u043d\u043e\u043c\u0443 \u0444\u0430\u0439\u043b\u0443 \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>terraform<\/code> (\u0431\u0435\u0437 \u0431\u043b\u043e\u043a\u0430 <code>s3<\/code>).<\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430 <code>vm-1<\/code> \u0432 \u0444\u0430\u0439\u043b\u0435 <code>main.tf<\/code>:<\/p>\n<pre><code>resource \"yandex_compute_instance\" \"vm-1\" {   name        = var.resource_name   platform_id = var.platform_id    resources {     cores  = var.cpu_cores     memory = var.memory_size   }    boot_disk {     initialize_params {       image_id = var.image_id       size     = var.disk_size     }   }    network_interface {     # \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0437 \u043c\u043e\u0434\u0443\u043b\u044f `network`     subnet_id = var.subnet_id     nat       = var.enable_nat   }    scheduling_policy {     preemptible = var.preemptible   }    metadata = {     # \u0414\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439     user-data = \"${file(var.user_data_file)}\"     # \u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430 - ssh-keys = \"ansible:${file(\"~\/.ssh\/id_rsa.pub\")}\"   } } <\/code><\/pre>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432 \u0444\u0430\u0439\u043b\u0435 <code>variables.tf<\/code>:<\/p>\n<details class=\"spoiler\">\n<summary>variables.tf<\/summary>\n<div class=\"spoiler__content\">\n<pre><code>variable \"resource_name\" {   description = \"\u0418\u043c\u044f \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b\"   type        = string   default     = \"my-vm\" }  variable \"platform_id\" {   description = \"\u041f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b\"   type        = string   default     = \"standard-v3\" }  variable \"cpu_cores\" {   description = \"\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044f\u0434\u0435\u0440 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430\"   type        = number   default     = 2 }  variable \"memory_size\" {   description = \"\u041e\u0431\u044a\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 (\u0432 \u0413\u0411)\"   type        = number   default     = 2 }  variable \"image_id\" {   description = \"ID \u043e\u0431\u0440\u0430\u0437\u0430 \u0434\u0438\u0441\u043a\u0430\"   type        = string   default     = \"fd80qm01ah03dkqb14lc\" }  variable \"disk_size\" {   description = \"\u0420\u0430\u0437\u043c\u0435\u0440 \u0434\u0438\u0441\u043a\u0430 (\u0432 \u0413\u0411)\"   type        = number   default     = 50 }  variable \"enable_nat\" {   description = \"\u0412\u043a\u043b\u044e\u0447\u0438\u0442\u044c NAT \u0434\u043b\u044f \u0412\u041c\"   type        = bool   default     = true }  variable \"preemptible\" {   description = \"\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u0435\u043c\u0443\u044e \u0412\u041c\"   type        = bool   default     = true }  variable \"user_data_file\" {   description = \"\u041f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439\"   type        = string   default     = \".\/user-data.txt\" }  variable \"subnet_id\" {   type = string } <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ul>\n<li>\n<p><code>image_id<\/code> &#8212; \u043e\u0431\u0440\u0430\u0437 \u0434\u0438\u0441\u043a\u0430 Ubuntu 20.04<\/p>\n<\/li>\n<li>\n<p><code>user_data_file<\/code> &#8212; \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 (\u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>terraform<\/code>)<\/p>\n<\/li>\n<li>\n<p><code>subnet_id<\/code> &#8212; \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u0434\u0441\u0435\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u043c\u043e\u0434\u0443\u043b\u044f <code>network<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 <code>outputs.tf<\/code>:<\/p>\n<pre><code>output \"external_ip\" {   description = \"\u0412\u043d\u0435\u0448\u043d\u0438\u0439 IP-\u0430\u0434\u0440\u0435\u0441 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b\"   value       = yandex_compute_instance.vm-1.network_interface.0.nat_ip_address }  output \"internal_ip\" {   description = \"\u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 IP-\u0430\u0434\u0440\u0435\u0441 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b\"   value       = yandex_compute_instance.vm-1.network_interface.0.ip_address } <\/code><\/pre>\n<p><em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435,<\/em> \u0447\u0442\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f <code>outputs<\/code> \u0432 \u043c\u043e\u0434\u0443\u043b\u044f\u0445 \u0438 <code>terraform\/main.tf<\/code> \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c.<\/p>\n<h3>\u0418\u0442\u043e\u0433\u043e<\/h3>\n<p>\u0424\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<pre><code>terraform     | main.tf     | provider.tf     | user-data.txt     | variables.tf     | versions.tf     | modules         | tf-yc-instance             | main.tf             | outputs.tf             | README.md             | variables.tf             | versions.tf         | tf-yc-network             | main.tf             | outputs.tf             | README.md             | variables.tf             | versions.tf <\/code><\/pre>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u044b \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 Terraform:<\/p>\n<pre><code class=\"bash\"># \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 (`terraform`). # \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430 terraform init # \u041e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e, \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 terraform validate # \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u043b\u0430\u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0443\u043a\u0442\u0443\u0440\u044b terraform plan # \u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 terraform apply <\/code><\/pre>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/harryheman\/blog-posts\/tree\/master\/devops-terraform\" rel=\"noopener noreferrer nofollow\">devops-terraform \u043d\u0430 GitHub<\/a><\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 Terraform, \u043d\u043e \u0434\u0443\u043c\u0430\u044e \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043d\u0435\u043f\u043b\u043e\u0445\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0438 \u043a\u0430\u043a \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442. \u041d\u0430\u0440\u044f\u0434\u0443 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u043c\u0438 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0418\u0422-\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 (Ansible, Docker, Kubernetes \u0438 \u0442.\u0434.), Terraform \u043d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0430\u0436\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u0430\u0440\u0441\u0435\u043d\u0430\u043b\u0430 DevOps-\u0438\u043d\u0436\u0435\u043d\u0435\u0440\u0430.<\/p>\n<p>Happy devopsing!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/937376\/\"> https:\/\/habr.com\/ru\/articles\/937376\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"\"><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0434\u0440\u0443\u0437\u044c\u044f!<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u044f \u0434\u0435\u043b\u044e\u0441\u044c \u0441 \u0432\u0430\u043c\u0438 \u0441\u0432\u043e\u0438\u043c \u043e\u043f\u044b\u0442\u043e\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u0438\u0437 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e.<\/p>\n<p>\u0414\u0440\u0443\u0433\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0441\u0435\u0440\u0438\u0438:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/companies\/timeweb\/articles\/913426\/\" rel=\"noopener noreferrer nofollow\">DevOps Tutorials \u2014 Ansible: \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435<\/a><\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u044b\u043b\u0430 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u0434\u0435\u043f\u043b\u043e\u044e Angular+Java \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435 Ubuntu Linux \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Ansible. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u0435\u043f\u043b\u043e\u044f \u0441\u0435\u0442\u044c \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0432 \u043e\u0431\u043b\u0430\u043a\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Terraform.<\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e? \u0422\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0448\u0443 \u043f\u043e\u0434 \u043a\u0430\u0442.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430\u0448\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 &#8212; \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u043e\u0431\u043b\u0430\u0447\u043d\u0443\u044e \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043a \u0434\u0435\u043f\u043b\u043e\u044e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e:<\/p>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 Ubuntu Linux \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c <code>ansible<\/code><\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u0438\u0439 IP-\u0430\u0434\u0440\u0435\u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f CLI <code>ansible<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0431\u043b\u0430\u043a\u0430 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Yandex Cloud. <em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435,<\/em> \u0447\u0442\u043e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f Terraform \u0441\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043e\u0431\u043b\u0430\u043a\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043e\u0431\u043b\u0430\u043a\u0435 \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0438\u043d\u0430\u0447\u0435.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/developer.hashicorp.com\/terraform\/tutorials\/aws-get-started\/install-cli\" rel=\"noopener noreferrer nofollow\">\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 terraform<\/a> (\u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0440\u0441\u0438\u044e 1.5.7)<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/yandex.cloud\/ru\/docs\/cli\/operations\/install-cli\" rel=\"noopener noreferrer nofollow\">\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 yc<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/yandex.cloud\/ru\/docs\/iam\/concepts\/authorization\/oauth-token\" rel=\"noopener noreferrer nofollow\">OAuth-\u0442\u043e\u043a\u0435\u043d Yandex Cloud<\/a> (<code>yc config set token &lt;OAuth-\u0442\u043e\u043a\u0435\u043d&gt;<\/code>)<\/p>\n<\/li>\n<\/ul>\n<h3>\u041f\u0430\u0440\u0430 \u0441\u043b\u043e\u0432 \u043e Terraform<\/h3>\n<p><a href=\"https:\/\/developer.hashicorp.com\/terraform\" rel=\"noopener noreferrer nofollow\">Terraform<\/a> \u2014 \u044d\u0442\u043e \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043a\u0430\u043a \u043a\u043e\u0434 (IaC) \u2014 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0435\u0439 HashiCorp, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0432 \u043e\u0431\u043b\u0430\u043a\u0430\u0445 \u0438 \u0434\u0430\u0442\u0430-\u0446\u0435\u043d\u0442\u0440\u0430\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432.<\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 Terraform:<\/p>\n<ul>\n<li>\n<p>\u042f\u0437\u044b\u043a \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438<\/p>\n<\/li>\n<\/ul>\n<p>Terraform \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 HCL (HashiCorp Configuration Language) \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 \u044f\u0437\u044b\u043a, \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u043d\u0430 JSON. \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442 \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u0430\u0448\u0438\u043d\u044b, \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u0435\u0442\u0438 \u0438 \u0442.\u0434.<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u0432<\/p>\n<\/li>\n<\/ul>\n<p>Terraform \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430\u043c\u0438 \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438:<\/p>\n<ul>\n<li>\n<p>AWS<\/p>\n<\/li>\n<li>\n<p>Google Cloud Platform<\/p>\n<\/li>\n<li>\n<p>Microsoft Azure<\/p>\n<\/li>\n<li>\n<p>Yandex Cloud<\/p>\n<\/li>\n<li>\n<p>Kubernetes<\/p>\n<\/li>\n<li>\n<p>\u0438 \u0434\u0440.<\/p>\n<\/li>\n<li>\n<p>\u0423\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u043c \u0446\u0438\u043a\u043b\u043e\u043c \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b<\/p>\n<\/li>\n<\/ul>\n<p>Terraform \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442:<\/p>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 (<code>terraform apply<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e<\/p>\n<\/li>\n<li>\n<p>\u0443\u0434\u0430\u043b\u044f\u0442\u044c \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b (<code>terraform destroy<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u041f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u0430 <code>terraform plan<\/code> \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0432\u043d\u0435\u0441\u0435\u043d\u044b \u0432 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u044b \u2014 \u044d\u0442\u043e \u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u0440\u0438\u0441\u043a \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<ul>\n<li>\n<p>\u0418\u0434\u0435\u043c\u043f\u043e\u0442\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 Terraform \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0442\u0435\u043c \u0436\u0435 \u2014 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.<\/p>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/companies\/otus\/articles\/696694\/\" rel=\"noopener noreferrer nofollow\">\u041e\u0441\u043d\u043e\u0432\u044b Terraform<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/1cloud.ru\/blog\/introduce_in_terraform\" rel=\"noopener noreferrer nofollow\">\u041e\u0441\u043d\u043e\u0432\u044b Terraform: \u0440\u0430\u0431\u043e\u0442\u0430 \u0438 \u0437\u0430\u0434\u0430\u0447\u0438<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/companies\/nixys\/articles\/721404\/\" rel=\"noopener noreferrer nofollow\">Terraform: \u043e\u0442 \u043d\u0435\u0437\u043d\u0430\u043d\u0438\u044f \u043a best practices<\/a> (\u0431\u043b\u0438\u0437\u043a\u043e \u043a \u0442\u043e\u043c\u0443, \u0447\u0435\u043c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435)<\/p>\n<\/li>\n<\/ul>\n<h3>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f Terraform<\/h3>\n<p>\u0412 \u0434\u043e\u043c\u0430\u0448\u043d\u0435\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 (<code>\/home\/&lt;user&gt;<\/code>) \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b <code>.terraformrc<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f:<\/p>\n<pre><code>provider_installation {   network_mirror {     url = \"https:\/\/terraform-mirror.yandexcloud.net\/\"     include = [\"registry.terraform.io\/*\/*\"]   }   direct {     exclude = [\"registry.terraform.io\/*\/*\"]   } } <\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e <code>terraform<\/code> \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439:<\/p>\n<pre><code>- main.tf - provider.tf - user-data.txt - variables.tf - versions.tf <\/code><\/pre>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430 \u0432 \u0444\u0430\u0439\u043b\u0430\u0445 <code>versions.tf<\/code> \u0438 <code>provider.tf<\/code>.<\/p>\n<p><code>versions.tf<\/code>:<\/p>\n<pre><code>terraform {   required_providers {     yandex = {       source  = \"yandex-cloud\/yandex\"       version = \"&gt;= 0.87.0\"     }   }    # \u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f Terraform (terraform.tfstate) \u0432 \u0431\u0430\u043a\u0435\u0442\u0435 (bucket) Yandex Cloud   # backend \"s3\" {   #   endpoint = \"https:\/\/storage.yandexcloud.net\"   #   bucket   = \"terraform-state\"   #   region   = \"ru-central1\"   #   key      = \"terraform.tfstate\"    #   skip_region_validation      = true   #   skip_credentials_validation = true   # } } <\/code><\/pre>\n<p><code>provider.tf<\/code>:<\/p>\n<pre><code>provider \"yandex\" {   cloud_id  = var.cloud_id   folder_id = var.folder_id   zone      = var.zone } <\/code><\/pre>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432 \u0444\u0430\u0439\u043b\u0435 <code>variables.tf<\/code>:<\/p>\n<pre><code>variable \"cloud_id\" {   type = string   # \u0417\u0430\u043c\u0435\u043d\u0438\u0442\u044c   default = \"b1g...\" }  variable \"folder_id\" {   type = string   # \u0417\u0430\u043c\u0435\u043d\u0438\u0442\u044c   default = \"b1g...\" }  variable \"zone\" {   type = string   default = \"ru-central1-a\" } <\/code><\/pre>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u0444\u0430\u0439\u043b\u0435 <code>user-data.txt<\/code> (\u043e\u043d \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u043c \u043f\u043e\u0437\u0434\u043d\u0435\u0435):<\/p>\n<pre><code>#cloud-config users:   - name: ansible     shell: \/bin\/bash     sudo: \"ALL=(ALL) NOPASSWD:ALL\"     ssh_authorized_keys:       # \u0417\u0430\u043c\u0435\u043d\u0438\u0442\u044c       - ssh-rsa AAA... <\/code><\/pre>\n<p><em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435:<\/em><\/p>\n<ul>\n<li>\n<p>\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 <code>#cloud-config<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0432\u0435\u0440\u0441\u0438\u0438 Terraform<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e Terraform \u0432 \u0444\u0430\u0439\u043b\u0435 <code>main.tf<\/code>:<\/p>\n<pre><code>module \"instance\" {   source = \".\/modules\/tf-yc-instance\"   subnet_id = module.network.subnet_ids[var.zone] }  module \"network\" {   source = \".\/modules\/tf-yc-network\" }  output \"external_ip\" {   value = module.instance.external_ip }  output \"internal_ip\" {   value = module.instance.internal_ip }  output \"network_id\" {   value = module.network.network_id }  output \"subnet_ids\" {   value = module.network.subnet_ids } <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 2 \u043c\u043e\u0434\u0443\u043b\u0435\u0439: <code>instance<\/code> \u0434\u043b\u044f \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b \u0438 <code>network<\/code> \u0434\u043b\u044f \u0441\u0435\u0442\u0438. <em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435,<\/em> \u0447\u0442\u043e \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c ID \u043f\u043e\u0434\u0441\u0435\u0442\u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0437\u043e\u043d\u0435 <code>ru-central1-a<\/code> (<code>subnet_id<\/code>), \u0438\u0437 \u043c\u043e\u0434\u0443\u043b\u044f <code>network<\/code> \u0432 \u043c\u043e\u0434\u0443\u043b\u044c <code>instance<\/code>. \u0422\u0430\u043a\u0436\u0435 \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c Terraform \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0438 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 IP-\u0430\u0434\u0440\u0435\u0441\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, ID \u0441\u0435\u0442\u0438 \u0438 \u043f\u043e\u0434\u0441\u0435\u0442\u0435\u0439. \u0418\u0437 \u044d\u0442\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u0439 IP, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0430\u0434\u0438 \u0437\u0430\u0431\u0430\u0432\u044b.<\/p>\n<p>\u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f Terraform \u0432 \u0444\u0430\u0439\u043b <code>.gitignore<\/code>:<\/p>\n<pre><code>*.tfstate *.tfstate.* <\/code><\/pre>\n<h3>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f \u0441\u0435\u0442\u0438<\/h3>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e <code>modules\/tf-yc-network<\/code> \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439:<\/p>\n<pre><code>- main.tf - outputs.tf - README.md - variables.tf - versions.tf <\/code><\/pre>\n<p>\u0424\u0430\u0439\u043b <code>versions.tf<\/code> \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u0435\u043d \u043e\u0434\u043d\u043e\u0438\u043c\u0435\u043d\u043d\u043e\u043c\u0443 \u0444\u0430\u0439\u043b\u0443 \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>terraform<\/code> (\u0431\u0435\u0437 \u0431\u043b\u043e\u043a\u0430 <code>s3<\/code>).<\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u0441\u0435\u0442\u0438 \u0438 \u043f\u043e\u0434\u0441\u0435\u0442\u0438 \u0432 \u0444\u0430\u0439\u043b\u0435 <code>main.tf<\/code>:<\/p>\n<pre><code>data \"yandex_vpc_network\" \"default\" {   name = \"default\" }  data \"yandex_vpc_subnet\" \"default\" {   for_each = var.network_zones   name     = \"default-${each.value}\" } <\/code><\/pre>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0432 \u0444\u0430\u0439\u043b\u0435 <code>variables.tf<\/code>:<\/p>\n<pre><code>variable \"network_zones\" {   description = \"\u0421\u043f\u0438\u0441\u043e\u043a \u0437\u043e\u043d \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u0434\u0441\u0435\u0442\u0435\u0439\"   type        = set(string)   default     = [\"ru-central1-a\", \"ru-central1-b\", \"ru-central1-d\"] } <\/code><\/pre>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0444\u0430\u0439\u043b\u0435 <code>outputs.tf<\/code>:<\/p>\n<pre><code>output \"network_id\" {   description = \"ID \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438\"   value       = data.yandex_vpc_network.default.id }  output \"subnet_ids\" {   description = \"ID \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0434\u0441\u0435\u0442\u0435\u0439\"   value       = { for zone, subnet in data.yandex_vpc_subnet.default : zone =&gt; subnet.id } } <\/code><\/pre>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 <code>yandex_vpc_subnet<\/code> \u0438 \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c <code>subnet_ids<\/code> \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435.<\/p>\n<ul>\n<li>\n<p><code>data \"yandex_vpc_subnet\" \"default\"<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u042d\u0442\u043e\u0442 \u0431\u043b\u043e\u043a \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u043e\u0434\u0441\u0435\u0442\u0438 \u043f\u043e \u0438\u043c\u0435\u043d\u0438 <code>default-&lt;zone&gt;<\/code> \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0437\u043e\u043d\u0430\u0445.<br \/> \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>for_each<\/code> \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0443 \u0437\u043e\u043d, \u0437\u043d\u0430\u0447\u0438\u0442, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u0441\u0435\u0442\u0435\u0439, \u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u043d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u0437\u043e\u043d\u0443 \u0438\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>network_zones<\/code>.<\/p>\n<p>Terraform \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b:<\/p>\n<pre><code>data.yandex_vpc_subnet.default[\"ru-central1-a\"] data.yandex_vpc_subnet.default[\"ru-central1-b\"] data.yandex_vpc_subnet.default[\"ru-central1-d\"] <\/code><\/pre>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043a\u0430\u0442\u044c \u043f\u043e\u0434\u0441\u0435\u0442\u044c \u0441 \u0438\u043c\u0435\u043d\u0435\u043c:<\/p>\n<ul>\n<li>\n<p><code>default-ru-central1-a<\/code><\/p>\n<\/li>\n<li>\n<p><code>default-ru-central1-b<\/code><\/p>\n<\/li>\n<li>\n<p><code>default-ru-central1-d<\/code><\/p>\n<\/li>\n<li>\n<p><code>output \"subnet_ids\"<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u042d\u0442\u043e\u0442 \u0431\u043b\u043e\u043a \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0441\u043b\u043e\u0432\u0430\u0440\u044c (map), \u0433\u0434\u0435:<\/p>\n<ul>\n<li>\n<p>\u043a\u043b\u044e\u0447 \u2014 \u044d\u0442\u043e \u0438\u043c\u044f \u0437\u043e\u043d\u044b (<code>ru-central1-a<\/code> \u0438 \u0442.\u0434.)<\/p>\n<\/li>\n<li>\n<p>\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u2014 \u044d\u0442\u043e <code>subnet.id<\/code> (\u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0439 \u043f\u043e\u0434\u0441\u0435\u0442\u0438)<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434:<\/p>\n<pre><code>subnet_ids = {   \"ru-central1-a\" = \"e2lu123abcde12345678\"   \"ru-central1-b\" = \"e2lu456fghij45678901\"   \"ru-central1-d\" = \"e2lu789klmno78901234\" } <\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0432\u044b\u0432\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u043f\u043e\u0434\u0441\u0435\u0442\u0438 <code>ru-central1-a<\/code> \u0432 \u043c\u043e\u0434\u0443\u043b\u044c <code>instance<\/code>.<\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ul>\n<li>\n<p>\u0432\u0441\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0434\u0441\u0435\u0442\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 Yandex Cloud \u0441 \u0438\u043c\u0435\u043d\u0430\u043c\u0438 <code>default-ru-central1-a<\/code> \u0438 \u0442.\u0434. \u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u043e\u0439 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u2014 Terraform \u0432\u044b\u0434\u0430\u0441\u0442 \u043e\u0448\u0438\u0431\u043a\u0443<\/p>\n<\/li>\n<li>\n<p>\u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 <code>data<\/code>, \u0430 \u043d\u0435 \u0441 <code>resource<\/code>, \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f, \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f<\/p>\n<\/li>\n<\/ul>\n<h3>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/h3>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e <code>modules\/tf-yc-instance<\/code> \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439:<\/p>\n<pre><code>- main.tf - outputs.tf - README.md - variables.tf - versions.tf <\/code><\/pre>\n<p>\u0424\u0430\u0439\u043b <code>versions.tf<\/code> \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u0435\u043d \u043e\u0434\u043d\u043e\u0438\u043c\u0435\u043d\u043d\u043e\u043c\u0443 \u0444\u0430\u0439\u043b\u0443 \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>terraform<\/code> (\u0431\u0435\u0437 \u0431\u043b\u043e\u043a\u0430 <code>s3<\/code>).<\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430 <code>vm-1<\/code> \u0432 \u0444\u0430\u0439\u043b\u0435 <code>main.tf<\/code>:<\/p>\n<pre><code>resource \"yandex_compute_instance\" \"vm-1\" {   name        = var.resource_name   platform_id = var.platform_id    resources {     cores  = var.cpu_cores     memory = var.memory_size   }    boot_disk {     initialize_params {       image_id = var.image_id       size     = var.disk_size     }   }    network_interface {     # \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0437 \u043c\u043e\u0434\u0443\u043b\u044f `network`     subnet_id = var.subnet_id     nat       = var.enable_nat   }    scheduling_policy {     preemptible = var.preemptible   }    metadata = {     # \u0414\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439     user-data = \"${file(var.user_data_file)}\"     # \u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430 - ssh-keys = \"ansible:${file(\"~\/.ssh\/id_rsa.pub\")}\"   } } <\/code><\/pre>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432 \u0444\u0430\u0439\u043b\u0435 <code>variables.tf<\/code>:<\/p>\n<details class=\"spoiler\">\n<summary>variables.tf<\/summary>\n<div class=\"spoiler__content\">\n<pre><code>variable \"resource_name\" {   description = \"\u0418\u043c\u044f \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b\"   type        = string   default     = \"my-vm\" }  variable \"platform_id\" {   description = \"\u041f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b\"   type        = string   default     = \"standard-v3\" }  variable \"cpu_cores\" {   description = \"\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044f\u0434\u0435\u0440 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430\"   type        = number   default     = 2 }  variable \"memory_size\" {   description = \"\u041e\u0431\u044a\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 (\u0432 \u0413\u0411)\"   type        = number   default     = 2 }  variable \"image_id\" {   description = \"ID \u043e\u0431\u0440\u0430\u0437\u0430 \u0434\u0438\u0441\u043a\u0430\"   type        = string   default     = \"fd80qm01ah03dkqb14lc\" }  variable \"disk_size\" {   description = \"\u0420\u0430\u0437\u043c\u0435\u0440 \u0434\u0438\u0441\u043a\u0430 (\u0432 \u0413\u0411)\"   type        = number   default     = 50 }  variable \"enable_nat\" {   description = \"\u0412\u043a\u043b\u044e\u0447\u0438\u0442\u044c NAT \u0434\u043b\u044f \u0412\u041c\"   type        = bool   default     = true }  variable \"preemptible\" {   description = \"\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u0435\u043c\u0443\u044e \u0412\u041c\"   type        = bool   default     = true }  variable \"user_data_file\" {   description = \"\u041f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439\"   type        = string   default     = \".\/user-data.txt\" }  variable \"subnet_id\" {   type = string } <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ul>\n<li>\n<p><code>image_id<\/code> &#8212; \u043e\u0431\u0440\u0430\u0437 \u0434\u0438\u0441\u043a\u0430 Ubuntu 20.04<\/p>\n<\/li>\n<li>\n<p><code>user_data_file<\/code> &#8212; \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 (\u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>terraform<\/code>)<\/p>\n<\/li>\n<li>\n<p><code>subnet_id<\/code> &#8212; \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u0434\u0441\u0435\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u043c\u043e\u0434\u0443\u043b\u044f <code>network<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 <code>outputs.tf<\/code>:<\/p>\n<pre><code>output \"external_ip\" {   description = \"\u0412\u043d\u0435\u0448\u043d\u0438\u0439 IP-\u0430\u0434\u0440\u0435\u0441 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b\"   value       = yandex_compute_instance.vm-1.network_interface.0.nat_ip_address }  output \"internal_ip\" {   description =<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-470837","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/470837","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=470837"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/470837\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=470837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=470837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=470837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}