{"id":48469,"date":"2023-03-17T21:57:43","date_gmt":"2023-03-09T10:14:42","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bb%8eterraform%e7%9a%84%e5%85%a5%e9%97%a8%e5%88%b0%e7%b2%be%e9%80%9a%ef%bc%88%e6%95%b4%e7%90%86%e5%91%bd%e4%bb%a4%ef%bc%89\/"},"modified":"2024-04-29T19:20:38","modified_gmt":"2024-04-29T11:20:38","slug":"%e4%bb%8eterraform%e7%9a%84%e5%85%a5%e9%97%a8%e5%88%b0%e7%b2%be%e9%80%9a%ef%bc%88%e6%95%b4%e7%90%86%e5%91%bd%e4%bb%a4%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bb%8eterraform%e7%9a%84%e5%85%a5%e9%97%a8%e5%88%b0%e7%b2%be%e9%80%9a%ef%bc%88%e6%95%b4%e7%90%86%e5%91%bd%e4%bb%a4%ef%bc%89\/","title":{"rendered":"\u4eceTerraform\u7684\u5165\u95e8\u5230\u7cbe\u901a\uff08\u6574\u7406\u547d\u4ee4\uff09"},"content":{"rendered":"<h2>\u603b\u7ed3<\/h2>\n<p>\u5728\u8fd9\u91cc\uff0c\u6211\u5c06\u4e3a\u60a8\u4ecb\u7ecd\u7ecf\u5e38\u5728Terraform\u4e2d\u4f7f\u7528\u7684\u547d\u4ee4\u3002<\/p>\n<h2>\u547d\u4ee4\u5217\u8868<\/h2>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">terraform init<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">terraform fmt<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">terraform plan<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">terraform apply<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">terraform state list<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">terraform state show<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">terraform output<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">terraform refresh<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">terraform destroy<\/ul>\n<h2>\u8bf7\u53c2\u8003DOC<\/h2>\n<p>&nbsp;<\/p>\n<h2>\u524d\u63d0\u6761\u4ef6<\/h2>\n<ul class=\"post-ul\">\u30ea\u30bd\u30fc\u30b9\u3092\u4f5c\u6210\u3059\u308b\u305f\u3081\u306eAWS\u306e\u6a29\u9650\u8a2d\u5b9a\u3092\u3082\u3064iam\u30e6\u30fc\u30b6\u30fc\u306e\u30a2\u30af\u30bb\u30b9\u30ad\u30fc(access_key,secret_key)<\/ul>\n<h2>\u89e3\u91ca<\/h2>\n<h3>\u521d\u59cb\u5316Terraform<\/h3>\n<p>\u521d\u59cb\u5316\u5de5\u4f5c\u533a\u7684\u547d\u4ee4\u3002<br \/>\n\u4e3a\u4e86\u6267\u884cTerraform\uff0c\u5fc5\u987b\u9996\u5148\u4f7f\u7528terraform init\u547d\u4ee4\u6765\u521d\u59cb\u5316\u5de5\u4f5c\u533a\u3002\u6267\u884cterraform init\u5c06\u8fd0\u884c\u4e0b\u8f7d\u63d2\u4ef6\uff08\u5982\u5148\u524d\u63d0\u5230\u7684aws provider\uff09\u7b49\u7684\u8fc7\u7a0b\u3002<\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3atest.tf\u7684\u6587\u4ef6\uff0c\u5e76\u5c06\u4ee5\u4e0b\u4ee3\u7801\u8f93\u5165\u5230test.tf\u4e2d\u3002<\/p>\n<pre class=\"post-pre\"><code>terraform {\r\n  required_providers {\r\n    aws = {\r\n      source  = \"hashicorp\/aws\"\r\n      version = \"~&gt; 3.0\"\r\n    }\r\n  }\r\n}\r\n\r\n# Configure the AWS Provider\r\nprovider \"aws\" {\r\n  region = \"ap-northeast-1\"\r\n}\r\n<\/code><\/pre>\n<p>\u8fd0\u884cterraform init\u547d\u4ee4\u3002<\/p>\n<pre class=\"post-pre\"><code> % terraform init\r\n\r\nInitializing the backend...\r\n\r\nInitializing provider plugins...\r\n- Finding hashicorp\/aws versions matching \"~&gt; 3.0\"...\r\n- Installing hashicorp\/aws v3.75.2...\r\n- Installed hashicorp\/aws v3.75.2 (signed by HashiCorp)\r\n\r\nTerraform has created a lock file .terraform.lock.hcl to record the provider\r\nselections it made above. Include this file in your version control repository\r\nso that Terraform can guarantee to make the same selections by default when\r\nyou run \"terraform init\" in the future.\r\n\r\nTerraform has been successfully initialized!\r\n\r\nYou may now begin working with Terraform. Try running \"terraform plan\" to see\r\nany changes that are required for your infrastructure. All Terraform commands\r\nshould now work.\r\n\r\nIf you ever set or change modules or backend configuration for Terraform,\r\nrerun this command to reinitialize your working directory. If you forget, other\r\ncommands will detect it and remind you to do so if necessary.\r\n<\/code><\/pre>\n<p>\u63d2\u4ef6\u6587\u4ef6\u5c06\u4f1a\u4e0b\u8f7d\u5230.terraform\u6587\u4ef6\u5939\u7684\u9876\u7ea7\u76ee\u5f55\u4e0b\u3002<\/p>\n<pre class=\"post-pre\"><code>ls -al\r\ntotal 16\r\ndrwxr-xr-x  5 youyonghua  staff   160  7 11 10:15 .\r\ndrwxr-xr-x  4 youyonghua  staff   128  7 11 10:05 ..\r\ndrwxr-xr-x  3 youyonghua  staff    96  7 11 10:15 .terraform\r\n-rw-r--r--  1 youyonghua  staff  1181  7 11 10:15 .terraform.lock.hcl\r\n-rw-r--r--  1 youyonghua  staff   192  7 11 10:14 test.tf\r\nyouyonghua@youyonghuadeMacBook-Pro project-2 % ls -lR .terraform\r\ntotal 0\r\ndrwxr-xr-x  3 youyonghua  staff  96  7 11 10:15 providers\r\n\r\n.terraform\/providers:\r\ntotal 0\r\ndrwxr-xr-x  3 youyonghua  staff  96  7 11 10:15 registry.terraform.io\r\n\r\n.terraform\/providers\/registry.terraform.io:\r\ntotal 0\r\ndrwxr-xr-x  3 youyonghua  staff  96  7 11 10:15 hashicorp\r\n\r\n.terraform\/providers\/registry.terraform.io\/hashicorp:\r\ntotal 0\r\ndrwxr-xr-x  3 youyonghua  staff  96  7 11 10:15 aws\r\n\r\n.terraform\/providers\/registry.terraform.io\/hashicorp\/aws:\r\ntotal 0\r\ndrwxr-xr-x  3 youyonghua  staff  96  7 11 10:15 3.75.2\r\n\r\n.terraform\/providers\/registry.terraform.io\/hashicorp\/aws\/3.75.2:\r\ntotal 0\r\ndrwxr-xr-x  3 youyonghua  staff  96  7 11 10:15 darwin_arm64\r\n\r\n.terraform\/providers\/registry.terraform.io\/hashicorp\/aws\/3.75.2\/darwin_arm64:\r\ntotal 576360\r\n-rwxr-xr-x  1 youyonghua  staff  295094370  7 11 10:15 terraform-provider-aws_v3.75.2_x5\r\n<\/code><\/pre>\n<h3>\u7528\u4e2d\u6587\u539f\u751f\u5730\u8868\u8fbe\u4ee5\u4e0b\u5185\u5bb9\uff0c\u53ea\u9700\u8981\u4e00\u4e2a\u9009\u9879\uff1a<\/h3>\n<p>\u5c55\u671b Terraform<\/p>\n<p>\u67e5\u8be2\u4f7f\u7528Terraform\u751f\u6210\u7684\u6267\u884c\u8ba1\u5212\u7684\u547d\u4ee4\u3002<br \/>\n\u5c06\u4ee5\u4e0b\u4ee3\u7801\u8f93\u5165\u5230test.tf\u6587\u4ef6\u4e2d\u3002<\/p>\n<pre class=\"post-pre\"><code>terraform {\r\n  required_providers {\r\n    aws = {\r\n      source  = \"hashicorp\/aws\"\r\n      version = \"~&gt; 3.0\"\r\n    }\r\n  }\r\n}\r\n\r\n# Configure the AWS Provider\r\nprovider \"aws\" {\r\n  region = \"ap-northeast-1\"\r\n  access_key = \"xxxxx\"\r\n  secret_key = \"xxxxxx\"\r\n}\r\n\r\nresource \"aws_vpc\" \"test\" {\r\n  cidr_block       = \"10.0.0.0\/16\"\r\n\r\n  tags = {\r\n    Name = \"test\"\r\n  }\r\n}\r\n<\/code><\/pre>\n<p>\u6267\u884c terraform plan \u547d\u4ee4<\/p>\n<pre class=\"post-pre\"><code>% terraform plan\r\n\r\nTerraform used the selected providers to generate the following execution plan. Resource actions are indicated with the\r\nfollowing symbols:\r\n  + create\r\n\r\nTerraform will perform the following actions:\r\n\r\n  # aws_vpc.test will be created\r\n  + resource \"aws_vpc\" \"test\" {\r\n      + arn                                  = (known after apply)\r\n      + cidr_block                           = \"10.0.0.0\/16\"\r\n      + default_network_acl_id               = (known after apply)\r\n      + default_route_table_id               = (known after apply)\r\n      + default_security_group_id            = (known after apply)\r\n      + dhcp_options_id                      = (known after apply)\r\n      + enable_classiclink                   = (known after apply)\r\n      + enable_classiclink_dns_support       = (known after apply)\r\n      + enable_dns_hostnames                 = (known after apply)\r\n      + enable_dns_support                   = true\r\n      + id                                   = (known after apply)\r\n      + instance_tenancy                     = \"default\"\r\n      + ipv6_association_id                  = (known after apply)\r\n      + ipv6_cidr_block                      = (known after apply)\r\n      + ipv6_cidr_block_network_border_group = (known after apply)\r\n      + main_route_table_id                  = (known after apply)\r\n      + owner_id                             = (known after apply)\r\n      + tags                                 = {\r\n          + \"Name\" = \"test\"\r\n        }\r\n      + tags_all                             = {\r\n          + \"Name\" = \"test\"\r\n        }\r\n    }\r\n\r\nPlan: 1 to add, 0 to change, 0 to destroy.\r\n\r\n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\nNote: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you\r\nrun \"terraform apply\" now.\r\n<\/code><\/pre>\n<p>\u6839\u636e\u8fd9\u4e2a\u6848\u4f8b\uff0c\u9700\u8981\u521b\u5efa\u4e00\u4e2aVPC\uff0c\u56e0\u6b64\u8f93\u51fa\u4e3a\u201c+\u521b\u5efa\u201d\u3002<\/p>\n<h3>\u4f7f\u7528terraform\u5e94\u7528<\/h3>\n<p>\u6839\u636e.tf\u6587\u4ef6\u4e2d\u7684\u4fe1\u606f\u521b\u5efa\u8d44\u6e90\u7684\u547d\u4ee4\u3002<\/p>\n<pre class=\"post-pre\"><code>terraform apply\r\n\r\nTerraform used the selected providers to generate the following execution plan. Resource actions are indicated with the\r\nfollowing symbols:\r\n  + create\r\n\r\nTerraform will perform the following actions:\r\n\r\n  # aws_vpc.test will be created\r\n  + resource \"aws_vpc\" \"test\" {\r\n      + arn                                  = (known after apply)\r\n      + cidr_block                           = \"10.0.0.0\/16\"\r\n      + default_network_acl_id               = (known after apply)\r\n      + default_route_table_id               = (known after apply)\r\n      + default_security_group_id            = (known after apply)\r\n      + dhcp_options_id                      = (known after apply)\r\n      + enable_classiclink                   = (known after apply)\r\n      + enable_classiclink_dns_support       = (known after apply)\r\n      + enable_dns_hostnames                 = (known after apply)\r\n      + enable_dns_support                   = true\r\n      + id                                   = (known after apply)\r\n      + instance_tenancy                     = \"default\"\r\n      + ipv6_association_id                  = (known after apply)\r\n      + ipv6_cidr_block                      = (known after apply)\r\n      + ipv6_cidr_block_network_border_group = (known after apply)\r\n      + main_route_table_id                  = (known after apply)\r\n      + owner_id                             = (known after apply)\r\n      + tags                                 = {\r\n          + \"Name\" = \"test\"\r\n        }\r\n      + tags_all                             = {\r\n          + \"Name\" = \"test\"\r\n        }\r\n    }\r\n\r\nPlan: 1 to add, 0 to change, 0 to destroy.\r\n\r\nDo you want to perform these actions?\r\n  Terraform will perform the actions described above.\r\n  Only 'yes' will be accepted to approve.\r\n\r\n  Enter a value: yes\r\n\r\naws_vpc.test: Creating...\r\naws_vpc.test: Creation complete after 2s [id=vpc-00b4d82db2030a8e2]\r\n\r\nApply complete! Resources: 1 added, 0 changed, 0 destroyed.\r\n<\/code><\/pre>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d85a2913a08637a6b9b6f\/26-0.png\" alt=\"\u622a\u5c4f2022-07-11 13.16.03.png\" \/><\/div>\n<p>\u6bcf\u6b21\u6267\u884cterraform apply\u65f6\uff0c\u9700\u8981\u5728\u63a7\u5236\u53f0\u8f93\u5165[yes]\u3002<br \/>\n\u4f7f\u7528&#8211;auto-approve\u5c31\u4e0d\u9700\u8981\u8f93\u5165[yes]\u4e86\u3002<\/p>\n<pre class=\"post-pre\"><code>terraform apply --auto-approve\r\n<\/code><\/pre>\n<h3>\u5217\u51fa Terraform \u72b6\u6001<\/h3>\n<p>\u60a8\u53ef\u4ee5\u67e5\u770b\u5df2\u521b\u5efa\u7684\u8d44\u6e90\u5217\u8868\u3002<\/p>\n<pre class=\"post-pre\"><code>% terraform state list\r\naws_vpc.test\r\n<\/code><\/pre>\n<h3>\u5c55\u793aterraform\u72b6\u6001\u8d44\u6e90<\/h3>\n<p>\u4f60\u53ef\u4ee5\u67e5\u770b\u521b\u5efa\u7684\u8d44\u6e90\u7684\u8be6\u7ec6\u4fe1\u606f\u3002<\/p>\n<pre class=\"post-pre\"><code>terraform state show aws_vpc.test\r\n# aws_vpc.test:\r\nresource \"aws_vpc\" \"test\" {\r\n    arn                              = \"arn:aws:ec2:ap-northeast-1:694047010837:vpc\/vpc-00b4d82db2030a8e2\"\r\n    assign_generated_ipv6_cidr_block = false\r\n    cidr_block                       = \"10.0.0.0\/16\"\r\n    default_network_acl_id           = \"acl-0b7fe43792506fd6f\"\r\n    default_route_table_id           = \"rtb-0b82672bf77e1c269\"\r\n    default_security_group_id        = \"sg-007ac38cba387147b\"\r\n    dhcp_options_id                  = \"dopt-b816fbde\"\r\n    enable_classiclink               = false\r\n    enable_classiclink_dns_support   = false\r\n    enable_dns_hostnames             = false\r\n    enable_dns_support               = true\r\n    id                               = \"vpc-00b4d82db2030a8e2\"\r\n    instance_tenancy                 = \"default\"\r\n    ipv6_netmask_length              = 0\r\n    main_route_table_id              = \"rtb-0b82672bf77e1c269\"\r\n    owner_id                         = \"694047010837\"\r\n    tags                             = {\r\n        \"Name\" = \"test\"\r\n    }\r\n    tags_all                         = {\r\n        \"Name\" = \"test\"\r\n    }\r\n}\r\n<\/code><\/pre>\n<h3>terraform\u5237\u65b0<\/h3>\n<p>\u6267\u884c\u6b64\u547d\u4ee4\u65f6\uff0c\u5c06\u53c2\u8003\u8fdc\u7a0b\u63d0\u4f9b\u5546\u7684\u8d44\u6e90\u4fe1\u606f\u5e76\u66f4\u65b0terraform.tfstate\u6587\u4ef6\u3002<\/p>\n<h3>\u8f93\u51faterraform<\/h3>\n<p>\u5728\u65e5\u5e38\u5de5\u4f5c\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528terraform\u521b\u5efa\u4e86\u8d44\u6e90\u3002\u5f53\u6211\u4eec\u60f3\u8981\u4e86\u89e3\u90e8\u5206\u8d44\u6e90\u7684\u4fe1\u606f\u65f6\uff0c\u901a\u5e38\u4f1a\u5728AWS\u63a7\u5236\u53f0\u4e0a\u67e5\u770b\u8d44\u6e90\u7684\u4fe1\u606f\uff0c\u4f46\u5176\u5b9e\u5728\u4f7f\u7528terraform\u521b\u5efa\u8d44\u6e90\u540e\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u8f93\u51fa\u6240\u9700\u7684\u4fe1\u606f\u3002\u4f8b\u5982\uff0c\u5982\u679c\u6211\u4eec\u60f3\u8981\u83b7\u53d6\u521b\u5efa\u7684VPC\u7684arn\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u4ee5\u4e0b\u4ee3\u7801\u6dfb\u52a0\u5230test.tf\u6587\u4ef6\u4e2d\uff0c\u5e76\u6267\u884cterraform refresh\u548cterraform output\u6765\u83b7\u53d6\u4fe1\u606f\u3002<\/p>\n<pre class=\"post-pre\"><code>output \"vpc_arn\" {\r\n  value = aws_vpc.test.arn\r\n}\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code>terraform output \r\nvpc_arn = \"arn:aws:ec2:ap-northeast-1:694047010837:vpc\/vpc-00b4d82db2030a8e2\"\r\n\r\n<\/code><\/pre>\n<h3>\u6467\u6bc1terraform<\/h3>\n<p>\u6839\u636e.tf\u6587\u4ef6\u4e2d\u5305\u542b\u7684\u4fe1\u606f\u5220\u9664\u8d44\u6e90\u7684\u547d\u4ee4\u3002<\/p>\n<pre class=\"post-pre\"><code>% terraform destroy\r\naws_vpc.test: Refreshing state... [id=vpc-00b4d82db2030a8e2]\r\n\r\nTerraform used the selected providers to generate the following execution plan. Resource actions are indicated with the\r\nfollowing symbols:\r\n  - destroy\r\n\r\nTerraform will perform the following actions:\r\n\r\n  # aws_vpc.test will be destroyed\r\n  - resource \"aws_vpc\" \"test\" {\r\n      - arn                              = \"arn:aws:ec2:ap-northeast-1:694047010837:vpc\/vpc-00b4d82db2030a8e2\" -&gt; null\r\n      - assign_generated_ipv6_cidr_block = false -&gt; null\r\n      - cidr_block                       = \"10.0.0.0\/16\" -&gt; null\r\n      - default_network_acl_id           = \"acl-0b7fe43792506fd6f\" -&gt; null\r\n      - default_route_table_id           = \"rtb-0b82672bf77e1c269\" -&gt; null\r\n      - default_security_group_id        = \"sg-007ac38cba387147b\" -&gt; null\r\n      - dhcp_options_id                  = \"dopt-b816fbde\" -&gt; null\r\n      - enable_classiclink               = false -&gt; null\r\n      - enable_classiclink_dns_support   = false -&gt; null\r\n      - enable_dns_hostnames             = false -&gt; null\r\n      - enable_dns_support               = true -&gt; null\r\n      - id                               = \"vpc-00b4d82db2030a8e2\" -&gt; null\r\n      - instance_tenancy                 = \"default\" -&gt; null\r\n      - ipv6_netmask_length              = 0 -&gt; null\r\n      - main_route_table_id              = \"rtb-0b82672bf77e1c269\" -&gt; null\r\n      - owner_id                         = \"694047010837\" -&gt; null\r\n      - tags                             = {\r\n          - \"Name\" = \"test\"\r\n        } -&gt; null\r\n      - tags_all                         = {\r\n          - \"Name\" = \"test\"\r\n        } -&gt; null\r\n    }\r\n\r\nPlan: 0 to add, 0 to change, 1 to destroy.\r\n\r\nChanges to Outputs:\r\n  - vpc_arn = \"arn:aws:ec2:ap-northeast-1:694047010837:vpc\/vpc-00b4d82db2030a8e2\" -&gt; null\r\n\r\nDo you really want to destroy all resources?\r\n  Terraform will destroy all your managed infrastructure, as shown above.\r\n  There is no undo. Only 'yes' will be accepted to confirm.\r\n\r\n  Enter a value: yes\r\n\r\naws_vpc.test: Destroying... [id=vpc-00b4d82db2030a8e2]\r\naws_vpc.test: Destruction complete after 1s\r\n\r\nDestroy complete! Resources: 1 destroyed\r\n<\/code><\/pre>\n<p>\u5148\u524d\u521b\u5efa\u7684VPC\u5c06\u88ab\u5220\u9664\u3002<\/p>\n<pre class=\"post-pre\"><code>terraform destroy\u3000--auto-approve\r\n<\/code><\/pre>\n<p>\u4e0d\u518d\u9700\u8981\u5728\u63a7\u5236\u53f0\u8f93\u5165[yes]\u4e86<\/p>\n<pre class=\"post-pre\"><code>terraform destroy\u3000-target  \u30ea\u30bd\u30fc\u30b9\u540d\r\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u901a\u8fc7\u5355\u4e2a\u5355\u4f4d\u5220\u9664\u8d44\u6e90\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u603b\u7ed3 \u5728\u8fd9\u91cc\uff0c\u6211\u5c06\u4e3a\u60a8\u4ecb\u7ecd\u7ecf\u5e38\u5728Terraform\u4e2d\u4f7f\u7528\u7684\u547d\u4ee4\u3002 \u547d\u4ee4\u5217\u8868 terraform init &#038;n [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-48469","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4eceTerraform\u7684\u5165\u95e8\u5230\u7cbe\u901a\uff08\u6574\u7406\u547d\u4ee4\uff09 - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4eceterraform\u7684\u5165\u95e8\u5230\u7cbe\u901a\uff08\u6574\u7406\u547d\u4ee4\uff09\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4eceTerraform\u7684\u5165\u95e8\u5230\u7cbe\u901a\uff08\u6574\u7406\u547d\u4ee4\uff09\" \/>\n<meta property=\"og:description\" content=\"\u603b\u7ed3 \u5728\u8fd9\u91cc\uff0c\u6211\u5c06\u4e3a\u60a8\u4ecb\u7ecd\u7ecf\u5e38\u5728Terraform\u4e2d\u4f7f\u7528\u7684\u547d\u4ee4\u3002 \u547d\u4ee4\u5217\u8868 terraform init &amp;n [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4eceterraform\u7684\u5165\u95e8\u5230\u7cbe\u901a\uff08\u6574\u7406\u547d\u4ee4\uff09\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-09T10:14:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-29T11:20:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d85a2913a08637a6b9b6f\/26-0.png\" \/>\n<meta name=\"author\" content=\"\u79d1, \u96c5\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u79d1, \u96c5\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bb%8eterraform%e7%9a%84%e5%85%a5%e9%97%a8%e5%88%b0%e7%b2%be%e9%80%9a%ef%bc%88%e6%95%b4%e7%90%86%e5%91%bd%e4%bb%a4%ef%bc%89\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bb%8eterraform%e7%9a%84%e5%85%a5%e9%97%a8%e5%88%b0%e7%b2%be%e9%80%9a%ef%bc%88%e6%95%b4%e7%90%86%e5%91%bd%e4%bb%a4%ef%bc%89\/\",\"name\":\"\u4eceTerraform\u7684\u5165\u95e8\u5230\u7cbe\u901a\uff08\u6574\u7406\u547d\u4ee4\uff09 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-03-09T10:14:42+00:00\",\"dateModified\":\"2024-04-29T11:20:38+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/41e222757cdd2a3365361328bd79970a\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bb%8eterraform%e7%9a%84%e5%85%a5%e9%97%a8%e5%88%b0%e7%b2%be%e9%80%9a%ef%bc%88%e6%95%b4%e7%90%86%e5%91%bd%e4%bb%a4%ef%bc%89\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bb%8eterraform%e7%9a%84%e5%85%a5%e9%97%a8%e5%88%b0%e7%b2%be%e9%80%9a%ef%bc%88%e6%95%b4%e7%90%86%e5%91%bd%e4%bb%a4%ef%bc%89\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bb%8eterraform%e7%9a%84%e5%85%a5%e9%97%a8%e5%88%b0%e7%b2%be%e9%80%9a%ef%bc%88%e6%95%b4%e7%90%86%e5%91%bd%e4%bb%a4%ef%bc%89\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4eceTerraform\u7684\u5165\u95e8\u5230\u7cbe\u901a\uff08\u6574\u7406\u547d\u4ee4\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/41e222757cdd2a3365361328bd79970a\",\"name\":\"\u79d1, \u96c5\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1b2d3e00a7df03689797ebd4af8c5827ba5af936849a71050ec331f4cf902c5d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1b2d3e00a7df03689797ebd4af8c5827ba5af936849a71050ec331f4cf902c5d?s=96&d=mm&r=g\",\"caption\":\"\u79d1, \u96c5\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/keya\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bb%8eterraform%e7%9a%84%e5%85%a5%e9%97%a8%e5%88%b0%e7%b2%be%e9%80%9a%ef%bc%88%e6%95%b4%e7%90%86%e5%91%bd%e4%bb%a4%ef%bc%89\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u4eceTerraform\u7684\u5165\u95e8\u5230\u7cbe\u901a\uff08\u6574\u7406\u547d\u4ee4\uff09 - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u4eceterraform\u7684\u5165\u95e8\u5230\u7cbe\u901a\uff08\u6574\u7406\u547d\u4ee4\uff09\/","og_locale":"zh_CN","og_type":"article","og_title":"\u4eceTerraform\u7684\u5165\u95e8\u5230\u7cbe\u901a\uff08\u6574\u7406\u547d\u4ee4\uff09","og_description":"\u603b\u7ed3 \u5728\u8fd9\u91cc\uff0c\u6211\u5c06\u4e3a\u60a8\u4ecb\u7ecd\u7ecf\u5e38\u5728Terraform\u4e2d\u4f7f\u7528\u7684\u547d\u4ee4\u3002 \u547d\u4ee4\u5217\u8868 terraform init &n [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u4eceterraform\u7684\u5165\u95e8\u5230\u7cbe\u901a\uff08\u6574\u7406\u547d\u4ee4\uff09\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-03-09T10:14:42+00:00","article_modified_time":"2024-04-29T11:20:38+00:00","og_image":[{"url":"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d85a2913a08637a6b9b6f\/26-0.png"}],"author":"\u79d1, \u96c5","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u79d1, \u96c5","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bb%8eterraform%e7%9a%84%e5%85%a5%e9%97%a8%e5%88%b0%e7%b2%be%e9%80%9a%ef%bc%88%e6%95%b4%e7%90%86%e5%91%bd%e4%bb%a4%ef%bc%89\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bb%8eterraform%e7%9a%84%e5%85%a5%e9%97%a8%e5%88%b0%e7%b2%be%e9%80%9a%ef%bc%88%e6%95%b4%e7%90%86%e5%91%bd%e4%bb%a4%ef%bc%89\/","name":"\u4eceTerraform\u7684\u5165\u95e8\u5230\u7cbe\u901a\uff08\u6574\u7406\u547d\u4ee4\uff09 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-03-09T10:14:42+00:00","dateModified":"2024-04-29T11:20:38+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/41e222757cdd2a3365361328bd79970a"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bb%8eterraform%e7%9a%84%e5%85%a5%e9%97%a8%e5%88%b0%e7%b2%be%e9%80%9a%ef%bc%88%e6%95%b4%e7%90%86%e5%91%bd%e4%bb%a4%ef%bc%89\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e4%bb%8eterraform%e7%9a%84%e5%85%a5%e9%97%a8%e5%88%b0%e7%b2%be%e9%80%9a%ef%bc%88%e6%95%b4%e7%90%86%e5%91%bd%e4%bb%a4%ef%bc%89\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bb%8eterraform%e7%9a%84%e5%85%a5%e9%97%a8%e5%88%b0%e7%b2%be%e9%80%9a%ef%bc%88%e6%95%b4%e7%90%86%e5%91%bd%e4%bb%a4%ef%bc%89\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u4eceTerraform\u7684\u5165\u95e8\u5230\u7cbe\u901a\uff08\u6574\u7406\u547d\u4ee4\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/41e222757cdd2a3365361328bd79970a","name":"\u79d1, \u96c5","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/1b2d3e00a7df03689797ebd4af8c5827ba5af936849a71050ec331f4cf902c5d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1b2d3e00a7df03689797ebd4af8c5827ba5af936849a71050ec331f4cf902c5d?s=96&d=mm&r=g","caption":"\u79d1, \u96c5"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/keya\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bb%8eterraform%e7%9a%84%e5%85%a5%e9%97%a8%e5%88%b0%e7%b2%be%e9%80%9a%ef%bc%88%e6%95%b4%e7%90%86%e5%91%bd%e4%bb%a4%ef%bc%89\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/48469","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=48469"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/48469\/revisions"}],"predecessor-version":[{"id":87154,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/48469\/revisions\/87154"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=48469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=48469"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=48469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}