{"id":344330,"date":"2023-01-23T09:01:39","date_gmt":"2023-01-23T09:01:39","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=344330"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=344330","title":{"rendered":"<span>\u0411\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 Terraform \u0432 \u042f\u043d\u0434\u0435\u043a\u0441.\u041e\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<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u0432\u043e\u0437\u043d\u0438\u043a \u043f\u0440\u0438 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0432 \u042f\u043d\u0434\u0435\u043a\u0441.\u041e\u0431\u043b\u0430\u043a\u043e. <a href=\"https:\/\/cloud.yandex.ru\/docs\/tutorials\/infrastructure-management\/terraform-state-storage\" rel=\"noopener noreferrer nofollow\">\u041e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f<\/a>, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0435 \u0434\u0430\u0451\u0442 \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u044d\u0442\u043e\u0442 \u0441\u0447\u0451\u0442, \u043a\u0430\u043a \u0438 \u0433\u0443\u0433\u043b\u0451\u0436. \u041e\u0434\u043d\u0430\u043a\u043e, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043e\u0431\u043b\u0430\u0447\u043d\u043e\u043c \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0435 &#8212; AWS.<\/p>\n<p>\u0414\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0443\u0436\u043d\u0430 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 (state locking): \u043a\u043e\u0433\u0434\u0430 \u0441 \u043e\u0431\u043b\u0430\u043a\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043b\u044e\u0434\u044c\u043c\u0438. \u0418\u043d\u0430\u0447\u0435 \u0435\u0441\u0442\u044c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c, \u0432 \u043b\u0443\u0447\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0432\u0440\u0435\u0434\u0438\u0442\u044c state (\u0430 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043d\u044f\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438), \u0432 \u0445\u0443\u0434\u0448\u0435\u043c \u0436\u0435 &#8212; \u0437\u0430\u043f\u043e\u0440\u043e\u0442\u044c \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0435\u0441\u0442\u044c \u0432 <a href=\"https:\/\/developer.hashicorp.com\/terraform\/language\/state\/locking\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>.<\/p>\n<p>\u0412 AWS <a href=\"https:\/\/developer.hashicorp.com\/terraform\/language\/settings\/backends\/s3\" rel=\"noopener noreferrer nofollow\">\u0432\u043e\u043f\u0440\u043e\u0441 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f<\/a> \u0447\u0435\u0440\u0435\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 DynamoDB. \u0412 \u042f\u043d\u0434\u0435\u043a\u0441.\u041e\u0431\u043b\u0430\u043a\u0435 \u0435\u0441\u0442\u044c  \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 &#8212; Yandex Managed Service for YBD (\u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e YDB).<\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d \u0441\u043e\u0437\u0434\u0430\u043d \u0431\u0430\u043a\u0435\u0442 \u0432 Object Storage, \u0438 \u0435\u0441\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u044b\u0439 \u0430\u043a\u043a\u0430\u0443\u043d\u0442 \u0441 \u043f\u0440\u0430\u0432\u0430\u043c\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u044d\u0442\u043e\u0442 \u0431\u0430\u043a\u0435\u0442.<\/p>\n<p>\u041d\u0430\u0437\u043d\u0430\u0447\u0438\u043c \u044d\u0442\u043e\u043c\u0443 \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u043c\u0443 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0443 \u0440\u043e\u043b\u044c \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 YDB<\/p>\n<pre><code class=\"bash\">yc resource-manager folder add-access-binding &lt;folder-id> \\   --role ydb.editor \\   --subject serviceAccount:&lt;service-account-id><\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"bash\">yc ydb database create terraform-state-lock --serverless<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u043f\u0443\u0442\u0438:<\/p>\n<ol>\n<li>\n<p>\u0447\u0435\u0440\u0435\u0437 \u0432\u044d\u0431-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441: <\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>1. \u0432 \u0434\u0430\u0448\u0431\u043e\u0440\u0434\u0435 Managed Service for YDB<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9b7\/c67\/86a\/9b7c6786aff5f8c604f139ccca3aec77.png\" width=\"1548\" height=\"632\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9b7\/c67\/86a\/9b7c6786aff5f8c604f139ccca3aec77.png\"\/><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>2. \u0431\u0430\u0437\u0430 &#171;terraform-state-lock&#187;<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/097\/e45\/011\/097e450113d8058ebb4e2a057aad223f.png\" width=\"1296\" height=\"432\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/097\/e45\/011\/097e450113d8058ebb4e2a057aad223f.png\"\/><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>3. \u041d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/035\/a84\/a4a\/035a84a4aed528a4d92eea3c00ed9624.png\" width=\"492\" height=\"354\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/035\/a84\/a4a\/035a84a4aed528a4d92eea3c00ed9624.png\"\/><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>4. \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2a3\/8e1\/941\/2a38e19417dbe24dc47e9517057d345b.png\" width=\"776\" height=\"398\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2a3\/8e1\/941\/2a38e19417dbe24dc47e9517057d345b.png\"\/><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>5. \u0422\u0438\u043f: \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043d\u0430\u044f, \u043a\u043e\u043b\u043e\u043d\u043a\u0430 &#171;LockID&#187; \u0442\u0438\u043f\u0430 String \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043a\u043b\u044e\u0447\u0435\u043c \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/185\/26f\/4d6\/18526f4d6fd0c83ee340da0c06d44f86.png\" width=\"1458\" height=\"1476\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/185\/26f\/4d6\/18526f4d6fd0c83ee340da0c06d44f86.png\"\/><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<ol start=\"2\">\n<li>\n<p>c \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/cloud.yandex.ru\/docs\/storage\/tools\/aws-cli\" rel=\"noopener noreferrer nofollow\">AWS CLI<\/a>, \u0443\u043a\u0430\u0437\u0430\u0432 Document API \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 (\u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0431\u0430\u0437\u044b. \u0418\u043c\u0435\u0435\u0442 \u0432\u0438\u0434 <em>https:\/\/docapi.serverless.yandexcloud.net\/ru-central1\/&lt;folder-id>\/&lt;database-id><\/em>)<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">aws dynamodb create-table \\   --table-name terraform-state-lock \\   --attribute-definitions \\     AttributeName=LockID,AttributeType=N \\   --key-schema \\     AttributeName=LockID,KeyType=HASH \\   --endpoint &lt;document-api-endpoint><\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 terraform backend, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<pre><code>dynamodb_endpoint = \"&lt;document-api-endpoint>\" dynamodb_table = \"tettaform-state-lock\"<\/code><\/pre>\n<p>\u0418 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0440\u0435\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e:<\/p>\n<pre><code>terraform init -reconfigure<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043f\u043e\u043a\u0430 \u043a\u0442\u043e-\u0442\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0431\u044d\u043a\u0435\u043d\u0434 (terraform apply\/delete), \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u0432\u0438\u0434\u0430:<\/p>\n<pre><code>terraform apply -target=module.test \u2577 \u2502 Error: Error acquiring the state lock \u2502 \u2502 Error message: ConditionalCheckFailedException: Condition not satisfied \u2502 Lock Info: \u2502   ID:        &lt;...> \u2502   Path:      &lt;...> \u2502   Operation: OperationTypeApply \u2502   Who:       &lt;...> \u2502   Version:   1.3.7 \u2502   Created:   &lt;...> \u2502   Info: \u2502 \u2502 \u2502 Terraform acquires a state lock to protect the state from being written \u2502 by multiple users at the same time. Please resolve the issue above and try \u2502 again. For most commands, you can disable locking with the \"-lock=false\" \u2502 flag, but this is not recommended.<\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0451. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0434\u0430\u043d\u043d\u0443\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e \u043c\u043d\u043e\u0433\u0438\u0435 \u043d\u0430\u0439\u0434\u0443\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439.<\/p>\n<\/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\/post\/711982\/\"> https:\/\/habr.com\/ru\/post\/711982\/<\/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<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u0432\u043e\u0437\u043d\u0438\u043a \u043f\u0440\u0438 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0432 \u042f\u043d\u0434\u0435\u043a\u0441.\u041e\u0431\u043b\u0430\u043a\u043e. <a href=\"https:\/\/cloud.yandex.ru\/docs\/tutorials\/infrastructure-management\/terraform-state-storage\" rel=\"noopener noreferrer nofollow\">\u041e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f<\/a>, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0435 \u0434\u0430\u0451\u0442 \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u044d\u0442\u043e\u0442 \u0441\u0447\u0451\u0442, \u043a\u0430\u043a \u0438 \u0433\u0443\u0433\u043b\u0451\u0436. \u041e\u0434\u043d\u0430\u043a\u043e, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043e\u0431\u043b\u0430\u0447\u043d\u043e\u043c \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0435 &#8212; AWS.<\/p>\n<p>\u0414\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0443\u0436\u043d\u0430 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 (state locking): \u043a\u043e\u0433\u0434\u0430 \u0441 \u043e\u0431\u043b\u0430\u043a\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043b\u044e\u0434\u044c\u043c\u0438. \u0418\u043d\u0430\u0447\u0435 \u0435\u0441\u0442\u044c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c, \u0432 \u043b\u0443\u0447\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0432\u0440\u0435\u0434\u0438\u0442\u044c state (\u0430 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043d\u044f\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438), \u0432 \u0445\u0443\u0434\u0448\u0435\u043c \u0436\u0435 &#8212; \u0437\u0430\u043f\u043e\u0440\u043e\u0442\u044c \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0435\u0441\u0442\u044c \u0432 <a href=\"https:\/\/developer.hashicorp.com\/terraform\/language\/state\/locking\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>.<\/p>\n<p>\u0412 AWS <a href=\"https:\/\/developer.hashicorp.com\/terraform\/language\/settings\/backends\/s3\" rel=\"noopener noreferrer nofollow\">\u0432\u043e\u043f\u0440\u043e\u0441 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f<\/a> \u0447\u0435\u0440\u0435\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 DynamoDB. \u0412 \u042f\u043d\u0434\u0435\u043a\u0441.\u041e\u0431\u043b\u0430\u043a\u0435 \u0435\u0441\u0442\u044c  \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 &#8212; Yandex Managed Service for YBD (\u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e YDB).<\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d \u0441\u043e\u0437\u0434\u0430\u043d \u0431\u0430\u043a\u0435\u0442 \u0432 Object Storage, \u0438 \u0435\u0441\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u044b\u0439 \u0430\u043a\u043a\u0430\u0443\u043d\u0442 \u0441 \u043f\u0440\u0430\u0432\u0430\u043c\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u044d\u0442\u043e\u0442 \u0431\u0430\u043a\u0435\u0442.<\/p>\n<p>\u041d\u0430\u0437\u043d\u0430\u0447\u0438\u043c \u044d\u0442\u043e\u043c\u0443 \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u043c\u0443 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0443 \u0440\u043e\u043b\u044c \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 YDB<\/p>\n<pre><code class=\"bash\">yc resource-manager folder add-access-binding &lt;folder-id> \\   --role ydb.editor \\   --subject serviceAccount:&lt;service-account-id><\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"bash\">yc ydb database create terraform-state-lock --serverless<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u043f\u0443\u0442\u0438:<\/p>\n<ol>\n<li>\n<p>\u0447\u0435\u0440\u0435\u0437 \u0432\u044d\u0431-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441: <\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>1. \u0432 \u0434\u0430\u0448\u0431\u043e\u0440\u0434\u0435 Managed Service for YDB<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>2. \u0431\u0430\u0437\u0430 &#171;terraform-state-lock&#187;<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>3. \u041d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>4. \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>5. \u0422\u0438\u043f: \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043d\u0430\u044f, \u043a\u043e\u043b\u043e\u043d\u043a\u0430 &#171;LockID&#187; \u0442\u0438\u043f\u0430 String \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043a\u043b\u044e\u0447\u0435\u043c \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<ol start=\"2\">\n<li>\n<p>c \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/cloud.yandex.ru\/docs\/storage\/tools\/aws-cli\" rel=\"noopener noreferrer nofollow\">AWS CLI<\/a>, \u0443\u043a\u0430\u0437\u0430\u0432 Document API \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 (\u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0431\u0430\u0437\u044b. \u0418\u043c\u0435\u0435\u0442 \u0432\u0438\u0434 <em>https:\/\/docapi.serverless.yandexcloud.net\/ru-central1\/&lt;folder-id>\/&lt;database-id><\/em>)<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">aws dynamodb create-table \\   --table-name terraform-state-lock \\   --attribute-definitions \\     AttributeName=LockID,AttributeType=N \\   --key-schema \\     AttributeName=LockID,KeyType=HASH \\   --endpoint &lt;document-api-endpoint><\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 terraform backend, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<pre><code>dynamodb_endpoint = \"&lt;document-api-endpoint>\" dynamodb_table = \"tettaform-state-lock\"<\/code><\/pre>\n<p>\u0418 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0440\u0435\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e:<\/p>\n<pre><code>terraform init -reconfigure<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043f\u043e\u043a\u0430 \u043a\u0442\u043e-\u0442\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0431\u044d\u043a\u0435\u043d\u0434 (terraform apply\/delete), \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u0432\u0438\u0434\u0430:<\/p>\n<pre><code>terraform apply -target=module.test \u2577 \u2502 Error: Error acquiring the state lock \u2502 \u2502 Error message: ConditionalCheckFailedException: Condition not satisfied \u2502 Lock Info: \u2502   ID:        &lt;...> \u2502   Path:      &lt;...> \u2502   Operation: OperationTypeApply \u2502   Who:       &lt;...> \u2502   Version:   1.3.7 \u2502   Created:   &lt;...> \u2502   Info: \u2502 \u2502 \u2502 Terraform acquires a state lock to protect the state from being written \u2502 by multiple users at the same time. Please resolve the issue above and try \u2502 again. For most commands, you can disable locking with the \"-lock=false\" \u2502 flag, but this is not recommended.<\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0451. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0434\u0430\u043d\u043d\u0443\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e \u043c\u043d\u043e\u0433\u0438\u0435 \u043d\u0430\u0439\u0434\u0443\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439.<\/p>\n<\/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\/post\/711982\/\"> https:\/\/habr.com\/ru\/post\/711982\/<\/a><br \/><\/br><\/br><\/p>\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-344330","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/344330","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=344330"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/344330\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=344330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=344330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=344330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}