{"id":48623,"date":"2023-03-11T00:33:51","date_gmt":"2024-02-18T20:11:26","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%be%9e-terraform-%e5%88%9d%e5%ad%b8%e8%80%85%e5%88%b0%e5%b0%88%e5%ae%b6%ef%bc%88%e5%88%9d%e5%a7%8b%e9%85%8d%e7%bd%ae%ef%bc%89%e7%9a%84%e5%ae%8c%e5%85%a8%e6%8c%87%e5%8d%97%e3%80%82\/"},"modified":"2024-04-29T18:20:37","modified_gmt":"2024-04-29T10:20:37","slug":"%e5%be%9e-terraform-%e5%88%9d%e5%ad%b8%e8%80%85%e5%88%b0%e5%b0%88%e5%ae%b6%ef%bc%88%e5%88%9d%e5%a7%8b%e9%85%8d%e7%bd%ae%ef%bc%89%e7%9a%84%e5%ae%8c%e5%85%a8%e6%8c%87%e5%8d%97%e3%80%82","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%be%9e-terraform-%e5%88%9d%e5%ad%b8%e8%80%85%e5%88%b0%e5%b0%88%e5%ae%b6%ef%bc%88%e5%88%9d%e5%a7%8b%e9%85%8d%e7%bd%ae%ef%bc%89%e7%9a%84%e5%ae%8c%e5%85%a8%e6%8c%87%e5%8d%97%e3%80%82\/","title":{"rendered":"\u5f9e Terraform \u521d\u5b78\u8005\u5230\u5c08\u5bb6\uff08\u521d\u59cb\u914d\u7f6e\uff09\u7684\u5b8c\u5168\u6307\u5357"},"content":{"rendered":"<h2>\u7b80\u4ecb<\/h2>\n<p>\u672c\u6b21\uff0c\u6211\u60f3\u5411\u90a3\u4e9b\u8fd8\u6ca1\u6709\u63a5\u89e6\u8fc7\u7684\u4eba\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e0b\u4f5c\u4e3a\u57fa\u7840\u8bbe\u65bd\u5373\u4ee3\u7801\u7684\u4ee3\u8868\u6027\u5de5\u5177Terraform\u7684\u7279\u70b9\u548c\u4f7f\u7528\u65b9\u6cd5\u3002<br \/>\n\u6211\u4eec\u5c06\u4f7f\u7528Terraform\u6765\u6784\u5efa\u3001\u7f16\u8f91\u3001\u5220\u9664AWS\u8d44\u6e90\u3002<\/p>\n<h2>\u524d\u63d0\u6761\u4ef6 (Qiant\u00ed<\/h2>\n<p>\u30fbMAC : \u82f9\u679c\u7535\u8111<br \/>\n\u30fbVS code : Visual Studio Code<br \/>\n\u30fb\u5177\u5907\u521b\u5efaAWS\u8d44\u6e90\u6240\u9700\u6743\u9650\u8bbe\u7f6e\u7684IAM\u7528\u6237\u8bbf\u95ee\u5bc6\u94a5<\/p>\n<h2>\u672c\u5730\u73af\u5883<\/h2>\n<pre class=\"post-pre\"><code>% sw_vers  \r\nProductName:\tmacOS\r\nProductVersion:\t12.4\r\nBuildVersion:\t21F79\r\n<\/code><\/pre>\n<h2>\u5b89\u88c5Terraform<\/h2>\n<pre class=\"post-pre\"><code>brew tap hashicorp\/tap\r\nbrew install hashicorp\/tap\/terraform\r\n<\/code><\/pre>\n<h2>\u68c0\u67e5Terraform\u7684\u72b6\u6001<\/h2>\n<pre class=\"post-pre\"><code>% terraform -version\r\nTerraform v1.2.4\r\non darwin_arm64\r\n<\/code><\/pre>\n<h2>Terraform\u6587\u6863<\/h2>\n<p>\u8fd9\u6b21\uff0c\u6211\u53c2\u8003\u4e86\u4e0b\u9762\u7684\u94fe\u63a5\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u4e3a\u4e86\u542f\u52a8Ec2\uff0c\u9700\u8981\u51c6\u5907\u4ee3\u7801\uff0c\u4f7f\u7528Terraform\u3002<\/h2>\n<p>\u4f7f\u7528VSCode\u521b\u5efamain.tf\u6587\u4ef6\u3002<br \/>\n\u5728main.tf\u6587\u4ef6\u4e2d\u5199\u5165\u4ee5\u4e0b\u4ee3\u7801\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 = \"xxxxxxxxxxx\"\r\n  secret_key = \"xxxxxxxxxxxxx\"\r\n\r\n}\r\nresource \"aws_instance\" \"my-first-terraform-ec2\" {\r\n  ami           = \"ami-0b7546e839d7ace12\"\r\n  instance_type = \"t2.micro\"\r\n\r\n  tags = {\r\n    Name = \"my-first-terraform-ec2\"\r\n  }\r\n}\r\n<\/code><\/pre>\n<h2>\u8fdb\u884cterraform\u521d\u671f\u5316<\/h2>\n<p>\u4ece\u4e92\u8054\u7f51\u4e0a\u83b7\u53d6\u6267\u884cTerraform\u6240\u9700\u7684\u63d2\u4ef6\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<h2>\u68c0\u67e5\u5b9a\u4e49\u5185\u5bb9<\/h2>\n<p>\u4f7f\u7528terraform plan\u547d\u4ee4\u53ef\u4ee5\u9884\u89c8\u5b9a\u4e49\u5185\u5bb9\u3002<\/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 following symbols:\r\n  + create\r\n\r\nTerraform will perform the following actions:\r\n\r\n  # aws_instance.my-first-terraform-ec2 will be created\r\n  + resource \"aws_instance\" \"my-first-terraform-ec2\" {\r\n      + ami                                  = \"ami-0b7546e839d7ace12\"\r\n      + arn                                  = (known after apply)\r\n      + associate_public_ip_address          = (known after apply)\r\n      + availability_zone                    = (known after apply)\r\n      + cpu_core_count                       = (known after apply)\r\n      + cpu_threads_per_core                 = (known after apply)\r\n      + disable_api_termination              = (known after apply)\r\n      + ebs_optimized                        = (known after apply)\r\n      + get_password_data                    = false\r\n      + host_id                              = (known after apply)\r\n      + id                                   = (known after apply)\r\n      + instance_initiated_shutdown_behavior = (known after apply)\r\n      + instance_state                       = (known after apply)\r\n      + instance_type                        = \"t2.micro\"\r\n      + ipv6_address_count                   = (known after apply)\r\n      + ipv6_addresses                       = (known after apply)\r\n      + key_name                             = (known after apply)\r\n      + monitoring                           = (known after apply)\r\n      + outpost_arn                          = (known after apply)\r\n      + password_data                        = (known after apply)\r\n      + placement_group                      = (known after apply)\r\n      + placement_partition_number           = (known after apply)\r\n      + primary_network_interface_id         = (known after apply)\r\n      + private_dns                          = (known after apply)\r\n      + private_ip                           = (known after apply)\r\n      + public_dns                           = (known after apply)\r\n      + public_ip                            = (known after apply)\r\n      + secondary_private_ips                = (known after apply)\r\n      + security_groups                      = (known after apply)\r\n      + source_dest_check                    = true\r\n      + subnet_id                            = (known after apply)\r\n      + tags                                 = {\r\n          + \"Name\" = \"my-first-terraform-ec2\"\r\n        }\r\n      + tags_all                             = {\r\n          + \"Name\" = \"my-first-terraform-ec2\"\r\n        }\r\n      + tenancy                              = (known after apply)\r\n      + user_data                            = (known after apply)\r\n      + user_data_base64                     = (known after apply)\r\n      + vpc_security_group_ids               = (known after apply)\r\n\r\n      + capacity_reservation_specification {\r\n          + capacity_reservation_preference = (known after apply)\r\n\r\n          + capacity_reservation_target {\r\n              + capacity_reservation_id = (known after apply)\r\n            }\r\n        }\r\n\r\n      + ebs_block_device {\r\n          + delete_on_termination = (known after apply)\r\n          + device_name           = (known after apply)\r\n          + encrypted             = (known after apply)\r\n          + iops                  = (known after apply)\r\n          + kms_key_id            = (known after apply)\r\n          + snapshot_id           = (known after apply)\r\n          + tags                  = (known after apply)\r\n          + throughput            = (known after apply)\r\n          + volume_id             = (known after apply)\r\n          + volume_size           = (known after apply)\r\n          + volume_type           = (known after apply)\r\n        }\r\n\r\n      + enclave_options {\r\n          + enabled = (known after apply)\r\n        }\r\n\r\n      + ephemeral_block_device {\r\n          + device_name  = (known after apply)\r\n          + no_device    = (known after apply)\r\n          + virtual_name = (known after apply)\r\n        }\r\n\r\n      + metadata_options {\r\n          + http_endpoint               = (known after apply)\r\n          + http_put_response_hop_limit = (known after apply)\r\n          + http_tokens                 = (known after apply)\r\n          + instance_metadata_tags      = (known after apply)\r\n        }\r\n\r\n      + network_interface {\r\n          + delete_on_termination = (known after apply)\r\n          + device_index          = (known after apply)\r\n          + network_interface_id  = (known after apply)\r\n        }\r\n\r\n      + root_block_device {\r\n          + delete_on_termination = (known after apply)\r\n          + device_name           = (known after apply)\r\n          + encrypted             = (known after apply)\r\n          + iops                  = (known after apply)\r\n          + kms_key_id            = (known after apply)\r\n          + tags                  = (known after apply)\r\n          + throughput            = (known after apply)\r\n          + volume_id             = (known after apply)\r\n          + volume_size           = (known after apply)\r\n          + volume_type           = (known after apply)\r\n        }\r\n    }\r\n\r\nPlan: 1 to add, 0 to change, 0 to destroy.\r\n\r\n<\/code><\/pre>\n<h2>\u542f\u52a8EC2<\/h2>\n<p>terraform apply\u547d\u4ee4\u5c06\u5e94\u7528\u5b9a\u4e49\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 following symbols:\r\n  + create\r\n\r\nTerraform will perform the following actions:\r\n\r\n  # aws_instance.my-first-terraform-ec2 will be created\r\n  + resource \"aws_instance\" \"my-first-terraform-ec2\" {\r\n      + ami                                  = \"ami-0b7546e839d7ace12\"\r\n      + arn                                  = (known after apply)\r\n      + associate_public_ip_address          = (known after apply)\r\n      + availability_zone                    = (known after apply)\r\n      + cpu_core_count                       = (known after apply)\r\n      + cpu_threads_per_core                 = (known after apply)\r\n      + disable_api_termination              = (known after apply)\r\n      + ebs_optimized                        = (known after apply)\r\n      + get_password_data                    = false\r\n      + host_id                              = (known after apply)\r\n      + id                                   = (known after apply)\r\n      + instance_initiated_shutdown_behavior = (known after apply)\r\n      + instance_state                       = (known after apply)\r\n      + instance_type                        = \"t2.micro\"\r\n      + ipv6_address_count                   = (known after apply)\r\n      + ipv6_addresses                       = (known after apply)\r\n      + key_name                             = (known after apply)\r\n      + monitoring                           = (known after apply)\r\n      + outpost_arn                          = (known after apply)\r\n      + password_data                        = (known after apply)\r\n      + placement_group                      = (known after apply)\r\n      + placement_partition_number           = (known after apply)\r\n      + primary_network_interface_id         = (known after apply)\r\n      + private_dns                          = (known after apply)\r\n      + private_ip                           = (known after apply)\r\n      + public_dns                           = (known after apply)\r\n      + public_ip                            = (known after apply)\r\n      + secondary_private_ips                = (known after apply)\r\n      + security_groups                      = (known after apply)\r\n      + source_dest_check                    = true\r\n      + subnet_id                            = (known after apply)\r\n      + tags                                 = {\r\n          + \"Name\" = \"HelloWorld\"\r\n        }\r\n      + tags_all                             = {\r\n          + \"Name\" = \"HelloWorld\"\r\n        }\r\n      + tenancy                              = (known after apply)\r\n      + user_data                            = (known after apply)\r\n      + user_data_base64                     = (known after apply)\r\n      + vpc_security_group_ids               = (known after apply)\r\n\r\n      + capacity_reservation_specification {\r\n          + capacity_reservation_preference = (known after apply)\r\n\r\n          + capacity_reservation_target {\r\n              + capacity_reservation_id = (known after apply)\r\n            }\r\n        }\r\n\r\n      + ebs_block_device {\r\n          + delete_on_termination = (known after apply)\r\n          + device_name           = (known after apply)\r\n          + encrypted             = (known after apply)\r\n          + iops                  = (known after apply)\r\n          + kms_key_id            = (known after apply)\r\n          + snapshot_id           = (known after apply)\r\n          + tags                  = (known after apply)\r\n          + throughput            = (known after apply)\r\n          + volume_id             = (known after apply)\r\n          + volume_size           = (known after apply)\r\n          + volume_type           = (known after apply)\r\n        }\r\n\r\n      + enclave_options {\r\n          + enabled = (known after apply)\r\n        }\r\n\r\n      + ephemeral_block_device {\r\n          + device_name  = (known after apply)\r\n          + no_device    = (known after apply)\r\n          + virtual_name = (known after apply)\r\n        }\r\n\r\n      + metadata_options {\r\n          + http_endpoint               = (known after apply)\r\n          + http_put_response_hop_limit = (known after apply)\r\n          + http_tokens                 = (known after apply)\r\n          + instance_metadata_tags      = (known after apply)\r\n        }\r\n\r\n      + network_interface {\r\n          + delete_on_termination = (known after apply)\r\n          + device_index          = (known after apply)\r\n          + network_interface_id  = (known after apply)\r\n        }\r\n\r\n      + root_block_device {\r\n          + delete_on_termination = (known after apply)\r\n          + device_name           = (known after apply)\r\n          + encrypted             = (known after apply)\r\n          + iops                  = (known after apply)\r\n          + kms_key_id            = (known after apply)\r\n          + tags                  = (known after apply)\r\n          + throughput            = (known after apply)\r\n          + volume_id             = (known after apply)\r\n          + volume_size           = (known after apply)\r\n          + volume_type           = (known after apply)\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_instance.my-first-terraform-ec2: Creating...\r\naws_instance.my-first-terraform-ec2: Still creating... [10s elapsed]\r\naws_instance.my-first-terraform-ec2: Still creating... [20s elapsed]\r\naws_instance.my-first-terraform-ec2: Still creating... [30s elapsed]\r\naws_instance.my-first-terraform-ec2: Creation complete after 33s [id=i-054b5babd53a5a942]\r\n\r\nApply complete! Resources: 1 added, 0 changed, 0 destroyed.\r\n<\/code><\/pre>\n<h2>\u786e\u8ba4EC2\u5b9e\u4f8b\u7684\u542f\u52a8\u72b6\u6001<\/h2>\n<p>\u767b\u5f55AWS\u63a7\u5236\u53f0\uff0c\u67e5\u770bEC2\u7684\u60c5\u51b5\u3002<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8606913a08637a6baf2b\/27-0.png\" alt=\"\u622a\u5c4f2022-07-06 12.00.26.png\" \/><\/div>\n<p>\u6211\u786e\u8ba4\u4e86 EC2 \u5df2\u7ecf\u542f\u52a8\u3002<\/p>\n<h2>\u4f7f\u7528Terraform\u66f4\u6539\u8d44\u6e90\u3002<\/h2>\n<p>\u521a\u521a\u542f\u52a8\u7684EC2\u6807\u7b7e\u5185\u5bb9\u5c06\u88ab\u66f4\u6539\u3002<br \/>\nmy-first-terraform-ec2<br \/>\n\u2193<br \/>\nmodify-first-terraform-ec2-tags-name<br \/>\n\u5c06\u5728main.tf\u6587\u4ef6\u4e2d\u66f4\u6539EC2\u6807\u7b7e\u7684\u540d\u79f0\u3002<\/p>\n<pre class=\"post-pre\"><code>resource \"aws_instance\" \"my-first-terraform-ec2\" {\r\n  ami           = \"ami-0b7546e839d7ace12\"\r\n  instance_type = \"t2.micro\"\r\n\r\n  tags = {\r\n    Name = \"modify-first-terraform-ec2-tags-name\"\r\n  }\r\n}\r\n<\/code><\/pre>\n<h3>\u786e\u8ba4\u66f4\u6539\u7684\u5185\u5bb9<\/h3>\n<pre class=\"post-pre\"><code>% terraform plan \r\naws_instance.my-first-terraform-ec2: Refreshing state... [id=i-0041e996aac4e5b4b]\r\n\r\nTerraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:\r\n  ~ update in-place\r\n\r\nTerraform will perform the following actions:\r\n\r\n  # aws_instance.my-first-terraform-ec2 will be updated in-place\r\n  ~ resource \"aws_instance\" \"my-first-terraform-ec2\" {\r\n        id                                   = \"i-0041e996aac4e5b4b\"\r\n      ~ tags                                 = {\r\n          ~ \"Name\" = \"my-first-terraform-ec2\" -&gt; \"modify-first-terraform-ec2-tags-name\"\r\n        }\r\n      ~ tags_all                             = {\r\n          ~ \"Name\" = \"my-first-terraform-ec2\" -&gt; \"modify-first-terraform-ec2-tags-name\"\r\n        }\r\n        # (27 unchanged attributes hidden)\r\n\r\n\r\n\r\n\r\n\r\n        # (5 unchanged blocks hidden)\r\n    }\r\n\r\nPlan: 0 to add, 1 to change, 0 to destroy.\r\n<\/code><\/pre>\n<p>\u6267\u884c\u66f4\u6539\u5185\u5bb9<\/p>\n<pre class=\"post-pre\"><code>% terraform apply\r\naws_instance.my-first-terraform-ec2: Refreshing state... [id=i-0041e996aac4e5b4b]\r\n\r\nTerraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:\r\n  ~ update in-place\r\n\r\nTerraform will perform the following actions:\r\n\r\n  # aws_instance.my-first-terraform-ec2 will be updated in-place\r\n  ~ resource \"aws_instance\" \"my-first-terraform-ec2\" {\r\n        id                                   = \"i-0041e996aac4e5b4b\"\r\n      ~ tags                                 = {\r\n          ~ \"Name\" = \"my-first-terraform-ec2\" -&gt; \"modify-first-terraform-ec2-tags-name\"\r\n        }\r\n      ~ tags_all                             = {\r\n          ~ \"Name\" = \"my-first-terraform-ec2\" -&gt; \"modify-first-terraform-ec2-tags-name\"\r\n        }\r\n        # (27 unchanged attributes hidden)\r\n\r\n\r\n\r\n\r\n\r\n        # (5 unchanged blocks hidden)\r\n    }\r\n\r\nPlan: 0 to add, 1 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_instance.my-first-terraform-ec2: Modifying... [id=i-0041e996aac4e5b4b]\r\naws_instance.my-first-terraform-ec2: Modifications complete after 1s [id=i-0041e996aac4e5b4b]\r\n\r\nApply complete! Resources: 0 added, 1 changed, 0 destroyed.\r\n<\/code><\/pre>\n<h2>\u786e\u8ba4\u53d8\u66f4\u7ed3\u679c<\/h2>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8606913a08637a6baf2b\/37-0.png\" alt=\"\u622a\u5c4f2022-07-06 12.09.11.png\" \/><\/div>\n<p>EC2\u7684\u6807\u7b7e\u540d\u79f0\u5df2\u66f4\u6539\u4e3amodify-first-terraform-ec2-tags-name\u3002<\/p>\n<h2>\u4f7f\u7528Terraform\u5220\u9664\u8d44\u6e90\u3002<\/h2>\n<p>\u4f7f\u7528terraform destroy\u547d\u4ee4\u5c06\u5220\u9664\u5728main.tf\u6587\u4ef6\u4e2d\u542f\u52a8\u7684EC2\u5b9e\u4f8b\u3002<\/p>\n<pre class=\"post-pre\"><code>% terraform destroy\r\naws_instance.my-first-terraform-ec2: Refreshing state... [id=i-0041e996aac4e5b4b]\r\n\r\nTerraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:\r\n  - destroy\r\n\r\nTerraform will perform the following actions:\r\n\r\n  # aws_instance.my-first-terraform-ec2 will be destroyed\r\n  - resource \"aws_instance\" \"my-first-terraform-ec2\" {\r\n      - ami                                  = \"ami-0b7546e839d7ace12\" -&gt; null\r\n      - arn                                  = \"arn:aws:ec2:ap-northeast-1:694047010837:instance\/i-0041e996aac4e5b4b\" -&gt; null\r\n      - associate_public_ip_address          = true -&gt; null\r\n      - availability_zone                    = \"ap-northeast-1c\" -&gt; null\r\n      - cpu_core_count                       = 1 -&gt; null\r\n      - cpu_threads_per_core                 = 1 -&gt; null\r\n      - disable_api_termination              = false -&gt; null\r\n      - ebs_optimized                        = false -&gt; null\r\n      - get_password_data                    = false -&gt; null\r\n      - hibernation                          = false -&gt; null\r\n      - id                                   = \"i-0041e996aac4e5b4b\" -&gt; null\r\n      - instance_initiated_shutdown_behavior = \"stop\" -&gt; null\r\n      - instance_state                       = \"running\" -&gt; null\r\n      - instance_type                        = \"t2.micro\" -&gt; null\r\n      - ipv6_address_count                   = 0 -&gt; null\r\n      - ipv6_addresses                       = [] -&gt; null\r\n      - monitoring                           = false -&gt; null\r\n      - primary_network_interface_id         = \"eni-05060a5c79730093c\" -&gt; null\r\n      - private_dns                          = \"ip-172-31-2-192.ap-northeast-1.compute.internal\" -&gt; null\r\n      - private_ip                           = \"172.31.2.192\" -&gt; null\r\n      - public_dns                           = \"ec2-54-95-7-235.ap-northeast-1.compute.amazonaws.com\" -&gt; null\r\n      - public_ip                            = \"54.95.7.235\" -&gt; null\r\n      - secondary_private_ips                = [] -&gt; null\r\n      - security_groups                      = [\r\n          - \"default\",\r\n        ] -&gt; null\r\n      - source_dest_check                    = true -&gt; null\r\n      - subnet_id                            = \"subnet-78a35122\" -&gt; null\r\n      - tags                                 = {\r\n          - \"Name\" = \"modify-first-terraform-ec2-tags-name\"\r\n        } -&gt; null\r\n      - tags_all                             = {\r\n          - \"Name\" = \"modify-first-terraform-ec2-tags-name\"\r\n        } -&gt; null\r\n      - tenancy                              = \"default\" -&gt; null\r\n      - vpc_security_group_ids               = [\r\n          - \"sg-33dac977\",\r\n        ] -&gt; null\r\n\r\n      - capacity_reservation_specification {\r\n          - capacity_reservation_preference = \"open\" -&gt; null\r\n        }\r\n\r\n      - credit_specification {\r\n          - cpu_credits = \"standard\" -&gt; null\r\n        }\r\n\r\n      - enclave_options {\r\n          - enabled = false -&gt; null\r\n        }\r\n\r\n      - metadata_options {\r\n          - http_endpoint               = \"enabled\" -&gt; null\r\n          - http_put_response_hop_limit = 1 -&gt; null\r\n          - http_tokens                 = \"optional\" -&gt; null\r\n          - instance_metadata_tags      = \"disabled\" -&gt; null\r\n        }\r\n\r\n      - root_block_device {\r\n          - delete_on_termination = true -&gt; null\r\n          - device_name           = \"\/dev\/xvda\" -&gt; null\r\n          - encrypted             = false -&gt; null\r\n          - iops                  = 100 -&gt; null\r\n          - tags                  = {} -&gt; null\r\n          - throughput            = 0 -&gt; null\r\n          - volume_id             = \"vol-0a35c335542aefab0\" -&gt; null\r\n          - volume_size           = 8 -&gt; null\r\n          - volume_type           = \"gp2\" -&gt; null\r\n        }\r\n    }\r\n\r\nPlan: 0 to add, 0 to change, 1 to destroy.\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_instance.my-first-terraform-ec2: Destroying... [id=i-0041e996aac4e5b4b]\r\naws_instance.my-first-terraform-ec2: Still destroying... [id=i-0041e996aac4e5b4b, 10s elapsed]\r\naws_instance.my-first-terraform-ec2: Still destroying... [id=i-0041e996aac4e5b4b, 20s elapsed]\r\naws_instance.my-first-terraform-ec2: Still destroying... [id=i-0041e996aac4e5b4b, 30s elapsed]\r\naws_instance.my-first-terraform-ec2: Destruction complete after 30s\r\n\r\nDestroy complete! Resources: 1 destroyed.\r\n<\/code><\/pre>\n<h2>\u8bf7\u67e5\u770b\u5220\u9664\u7684\u7ed3\u679c<\/h2>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8606913a08637a6baf2b\/43-0.png\" alt=\"\u622a\u5c4f2022-07-06 12.14.12.png\" \/><\/div>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u8fd9\u6b21\uff0c\u6211\u4f7f\u7528Terraform\u5b9e\u65bd\u4e86AWS EC2\u7684\u642d\u5efa\u3001\u7f16\u8f91\u548c\u5220\u9664\u3002<br \/>\n\u5c31\u8fd9\u6837\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u4ecb \u672c\u6b21\uff0c\u6211\u60f3\u5411\u90a3\u4e9b\u8fd8\u6ca1\u6709\u63a5\u89e6\u8fc7\u7684\u4eba\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e0b\u4f5c\u4e3a\u57fa\u7840\u8bbe\u65bd\u5373\u4ee3\u7801\u7684\u4ee3\u8868\u6027\u5de5\u5177Terraform\u7684\u7279\u70b9\u548c\u4f7f\u7528 [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-48623","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>\u5f9e Terraform \u521d\u5b78\u8005\u5230\u5c08\u5bb6\uff08\u521d\u59cb\u914d\u7f6e\uff09\u7684\u5b8c\u5168\u6307\u5357 - 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\/\u5f9e-terraform-\u521d\u5b78\u8005\u5230\u5c08\u5bb6\uff08\u521d\u59cb\u914d\u7f6e\uff09\u7684\u5b8c\u5168\u6307\u5357\u3002\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5f9e Terraform \u521d\u5b78\u8005\u5230\u5c08\u5bb6\uff08\u521d\u59cb\u914d\u7f6e\uff09\u7684\u5b8c\u5168\u6307\u5357\" \/>\n<meta property=\"og:description\" content=\"\u7b80\u4ecb \u672c\u6b21\uff0c\u6211\u60f3\u5411\u90a3\u4e9b\u8fd8\u6ca1\u6709\u63a5\u89e6\u8fc7\u7684\u4eba\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e0b\u4f5c\u4e3a\u57fa\u7840\u8bbe\u65bd\u5373\u4ee3\u7801\u7684\u4ee3\u8868\u6027\u5de5\u5177Terraform\u7684\u7279\u70b9\u548c\u4f7f\u7528 [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u5f9e-terraform-\u521d\u5b78\u8005\u5230\u5c08\u5bb6\uff08\u521d\u59cb\u914d\u7f6e\uff09\u7684\u5b8c\u5168\u6307\u5357\u3002\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2024-02-18T20:11:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-29T10:20:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8606913a08637a6baf2b\/27-0.png\" \/>\n<meta name=\"author\" content=\"\u6e05, \u5b87\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u6e05, \u5b87\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 \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\/%e5%be%9e-terraform-%e5%88%9d%e5%ad%b8%e8%80%85%e5%88%b0%e5%b0%88%e5%ae%b6%ef%bc%88%e5%88%9d%e5%a7%8b%e9%85%8d%e7%bd%ae%ef%bc%89%e7%9a%84%e5%ae%8c%e5%85%a8%e6%8c%87%e5%8d%97%e3%80%82\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%be%9e-terraform-%e5%88%9d%e5%ad%b8%e8%80%85%e5%88%b0%e5%b0%88%e5%ae%b6%ef%bc%88%e5%88%9d%e5%a7%8b%e9%85%8d%e7%bd%ae%ef%bc%89%e7%9a%84%e5%ae%8c%e5%85%a8%e6%8c%87%e5%8d%97%e3%80%82\/\",\"name\":\"\u5f9e Terraform \u521d\u5b78\u8005\u5230\u5c08\u5bb6\uff08\u521d\u59cb\u914d\u7f6e\uff09\u7684\u5b8c\u5168\u6307\u5357 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2024-02-18T20:11:26+00:00\",\"dateModified\":\"2024-04-29T10:20:37+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/1a6ecd3d914d22a5ac32791ffc1fbd8e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%be%9e-terraform-%e5%88%9d%e5%ad%b8%e8%80%85%e5%88%b0%e5%b0%88%e5%ae%b6%ef%bc%88%e5%88%9d%e5%a7%8b%e9%85%8d%e7%bd%ae%ef%bc%89%e7%9a%84%e5%ae%8c%e5%85%a8%e6%8c%87%e5%8d%97%e3%80%82\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%be%9e-terraform-%e5%88%9d%e5%ad%b8%e8%80%85%e5%88%b0%e5%b0%88%e5%ae%b6%ef%bc%88%e5%88%9d%e5%a7%8b%e9%85%8d%e7%bd%ae%ef%bc%89%e7%9a%84%e5%ae%8c%e5%85%a8%e6%8c%87%e5%8d%97%e3%80%82\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%be%9e-terraform-%e5%88%9d%e5%ad%b8%e8%80%85%e5%88%b0%e5%b0%88%e5%ae%b6%ef%bc%88%e5%88%9d%e5%a7%8b%e9%85%8d%e7%bd%ae%ef%bc%89%e7%9a%84%e5%ae%8c%e5%85%a8%e6%8c%87%e5%8d%97%e3%80%82\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5f9e Terraform \u521d\u5b78\u8005\u5230\u5c08\u5bb6\uff08\u521d\u59cb\u914d\u7f6e\uff09\u7684\u5b8c\u5168\u6307\u5357\"}]},{\"@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\/1a6ecd3d914d22a5ac32791ffc1fbd8e\",\"name\":\"\u6e05, \u5b87\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g\",\"caption\":\"\u6e05, \u5b87\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyu\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%be%9e-terraform-%e5%88%9d%e5%ad%b8%e8%80%85%e5%88%b0%e5%b0%88%e5%ae%b6%ef%bc%88%e5%88%9d%e5%a7%8b%e9%85%8d%e7%bd%ae%ef%bc%89%e7%9a%84%e5%ae%8c%e5%85%a8%e6%8c%87%e5%8d%97%e3%80%82\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u5f9e Terraform \u521d\u5b78\u8005\u5230\u5c08\u5bb6\uff08\u521d\u59cb\u914d\u7f6e\uff09\u7684\u5b8c\u5168\u6307\u5357 - 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\/\u5f9e-terraform-\u521d\u5b78\u8005\u5230\u5c08\u5bb6\uff08\u521d\u59cb\u914d\u7f6e\uff09\u7684\u5b8c\u5168\u6307\u5357\u3002\/","og_locale":"zh_CN","og_type":"article","og_title":"\u5f9e Terraform \u521d\u5b78\u8005\u5230\u5c08\u5bb6\uff08\u521d\u59cb\u914d\u7f6e\uff09\u7684\u5b8c\u5168\u6307\u5357","og_description":"\u7b80\u4ecb \u672c\u6b21\uff0c\u6211\u60f3\u5411\u90a3\u4e9b\u8fd8\u6ca1\u6709\u63a5\u89e6\u8fc7\u7684\u4eba\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e0b\u4f5c\u4e3a\u57fa\u7840\u8bbe\u65bd\u5373\u4ee3\u7801\u7684\u4ee3\u8868\u6027\u5de5\u5177Terraform\u7684\u7279\u70b9\u548c\u4f7f\u7528 [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u5f9e-terraform-\u521d\u5b78\u8005\u5230\u5c08\u5bb6\uff08\u521d\u59cb\u914d\u7f6e\uff09\u7684\u5b8c\u5168\u6307\u5357\u3002\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2024-02-18T20:11:26+00:00","article_modified_time":"2024-04-29T10:20:37+00:00","og_image":[{"url":"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8606913a08637a6baf2b\/27-0.png"}],"author":"\u6e05, \u5b87","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u6e05, \u5b87","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"10 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%be%9e-terraform-%e5%88%9d%e5%ad%b8%e8%80%85%e5%88%b0%e5%b0%88%e5%ae%b6%ef%bc%88%e5%88%9d%e5%a7%8b%e9%85%8d%e7%bd%ae%ef%bc%89%e7%9a%84%e5%ae%8c%e5%85%a8%e6%8c%87%e5%8d%97%e3%80%82\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%be%9e-terraform-%e5%88%9d%e5%ad%b8%e8%80%85%e5%88%b0%e5%b0%88%e5%ae%b6%ef%bc%88%e5%88%9d%e5%a7%8b%e9%85%8d%e7%bd%ae%ef%bc%89%e7%9a%84%e5%ae%8c%e5%85%a8%e6%8c%87%e5%8d%97%e3%80%82\/","name":"\u5f9e Terraform \u521d\u5b78\u8005\u5230\u5c08\u5bb6\uff08\u521d\u59cb\u914d\u7f6e\uff09\u7684\u5b8c\u5168\u6307\u5357 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2024-02-18T20:11:26+00:00","dateModified":"2024-04-29T10:20:37+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/1a6ecd3d914d22a5ac32791ffc1fbd8e"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%be%9e-terraform-%e5%88%9d%e5%ad%b8%e8%80%85%e5%88%b0%e5%b0%88%e5%ae%b6%ef%bc%88%e5%88%9d%e5%a7%8b%e9%85%8d%e7%bd%ae%ef%bc%89%e7%9a%84%e5%ae%8c%e5%85%a8%e6%8c%87%e5%8d%97%e3%80%82\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e5%be%9e-terraform-%e5%88%9d%e5%ad%b8%e8%80%85%e5%88%b0%e5%b0%88%e5%ae%b6%ef%bc%88%e5%88%9d%e5%a7%8b%e9%85%8d%e7%bd%ae%ef%bc%89%e7%9a%84%e5%ae%8c%e5%85%a8%e6%8c%87%e5%8d%97%e3%80%82\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%be%9e-terraform-%e5%88%9d%e5%ad%b8%e8%80%85%e5%88%b0%e5%b0%88%e5%ae%b6%ef%bc%88%e5%88%9d%e5%a7%8b%e9%85%8d%e7%bd%ae%ef%bc%89%e7%9a%84%e5%ae%8c%e5%85%a8%e6%8c%87%e5%8d%97%e3%80%82\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u5f9e Terraform \u521d\u5b78\u8005\u5230\u5c08\u5bb6\uff08\u521d\u59cb\u914d\u7f6e\uff09\u7684\u5b8c\u5168\u6307\u5357"}]},{"@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\/1a6ecd3d914d22a5ac32791ffc1fbd8e","name":"\u6e05, \u5b87","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g","caption":"\u6e05, \u5b87"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyu\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%be%9e-terraform-%e5%88%9d%e5%ad%b8%e8%80%85%e5%88%b0%e5%b0%88%e5%ae%b6%ef%bc%88%e5%88%9d%e5%a7%8b%e9%85%8d%e7%bd%ae%ef%bc%89%e7%9a%84%e5%ae%8c%e5%85%a8%e6%8c%87%e5%8d%97%e3%80%82\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/48623","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\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=48623"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/48623\/revisions"}],"predecessor-version":[{"id":86872,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/48623\/revisions\/86872"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=48623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=48623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=48623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}