{"id":48462,"date":"2023-05-23T12:22:34","date_gmt":"2023-05-31T09:29:43","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8terraform-import%e6%97%b6%e9%81%87%e5%88%b0%e7%9a%84%e9%97%ae%e9%a2%98\/"},"modified":"2024-04-30T05:34:14","modified_gmt":"2024-04-29T21:34:14","slug":"%e4%bd%bf%e7%94%a8terraform-import%e6%97%b6%e9%81%87%e5%88%b0%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8terraform-import%e6%97%b6%e9%81%87%e5%88%b0%e7%9a%84%e9%97%ae%e9%a2%98\/","title":{"rendered":"\u4f7f\u7528terraform import\u65f6\u9047\u5230\u7684\u95ee\u9898"},"content":{"rendered":"<h2>\u603b\u7ed3<\/h2>\n<p>\u53ea\u662f\u60f3\u8fdb\u884cTerraform \u5bfc\u5165\u64cd\u4f5c\uff0c\u4f46\u5374\u9047\u5230\u4e86\u56f0\u96be\uff0c\u6240\u4ee5\u6211\u628a\u8fd9\u5f53\u4f5c\u5907\u5fd8\u5f55\u8bb0\u5f55\u4e0b\u6765\u3002<\/p>\n<h3>\u9519\u8bef\u2460\uff1a\u5728\u914d\u7f6e\u4e2d\u4e0d\u5b58\u5728\u8d44\u6e90\u5730\u5740XX\u3002<\/h3>\n<p>\u8bf4\u6ca1\u6709\u8d44\u6e90\u88ab\u6307\u8d23\u4e3a\u9519\u8bef\u3002<\/p>\n<pre class=\"post-pre\"><code>$ terraform import module.network.aws_security_group.XXX sg-XXX\r\nError: resource address \"module.network.aws_security_group.XXX\" does not exist in the configuration.\r\n\r\nBefore importing this resource, please create its configuration in module.network. For example:\r\n\r\nresource \"aws_security_group\" \"XXX\" {\r\n  # (resource arguments)\r\n}\r\n<\/code><\/pre>\n<h3>\u9519\u8bef\u2461\uff1a\u5730\u5740\u65e0\u6548<\/h3>\n<p>\u88ab\u6279\u8bc4\u8bf4\u5730\u5740\u4e0d\u6b63\u786e<\/p>\n<pre class=\"post-pre\"><code>$ terraform import module.network.module.aws_security_group.XXX XXX\r\nError: Invalid address\r\n\r\n  on &lt;import-address&gt; line 1:\r\n   1: module.network.module.aws_security_group.XXX\r\n\r\nResource specification must include a resource type and name.\r\n<\/code><\/pre>\n<h3>\u9519\u8bef\u2462 \u5bfc\u5165\u547d\u4ee4\u9700\u8981\u4e24\u4e2a\u53c2\u6570\u3002<\/h3>\n<p>\u5982\u679c\u5bfc\u5165\u547d\u4ee4\u7684\u5b9a\u4e49\u65b9\u5f0f\u4e0d\u540c\uff0c\u5c31\u4f1a\u88ab\u8d23\u5907\u3002<\/p>\n<pre class=\"post-pre\"><code>$ terraform import aws --regions=ap-northeast-1 --resources=security-group --filter=aws_security_group=sg-XXX \r\nThe import command expects two arguments.\r\nUsage: terraform import [options] ADDR ID\r\n\r\n  Import existing infrastructure into your Terraform state.\r\n\r\n  This will find and import the specified resource into your Terraform\r\n  state, allowing existing infrastructure to come under Terraform\r\n  management without having to be initially created by Terraform.\r\n\r\n  The ADDR specified is the address to import the resource to. Please\r\n  see the documentation online for resource addresses. The ID is a\r\n  resource-specific ID to identify that resource being imported. Please\r\n  reference the documentation for the resource type you're importing to\r\n  determine the ID syntax to use. It typically matches directly to the ID\r\n  that the provider uses.\r\n\r\n  The current implementation of Terraform import can only import resources\r\n  into the state. It does not generate configuration. A future version of\r\n  Terraform will also generate configuration.\r\n\r\n  Because of this, prior to running terraform import it is necessary to write\r\n  a resource configuration block for the resource manually, to which the\r\n  imported object will be attached.\r\n\r\n  This command will not modify your infrastructure, but it will make\r\n  network requests to inspect parts of your infrastructure relevant to\r\n  the resource being imported.\r\n\r\nOptions:\r\n\r\n  -backup=path            Path to backup the existing state file before\r\n                          modifying. Defaults to the \"-state-out\" path with\r\n                          \".backup\" extension. Set to \"-\" to disable backup.\r\n\r\n  -config=path            Path to a directory of Terraform configuration files\r\n                          to use to configure the provider. Defaults to pwd.\r\n                          If no config files are present, they must be provided\r\n                          via the input prompts or env vars.\r\n\r\n  -allow-missing-config   Allow import when no resource configuration block exists.\r\n\r\n  -input=true             Ask for input for variables if not directly set.\r\n\r\n  -lock=true              Lock the state file when locking is supported.\r\n\r\n  -lock-timeout=0s        Duration to retry a state lock.\r\n\r\n  -no-color               If specified, output won't contain any color.\r\n\r\n  -state=PATH             Path to the source state file. Defaults to the configured\r\n                          backend, or \"terraform.tfstate\"\r\n\r\n  -state-out=PATH         Path to the destination state file to write to. If this\r\n                          isn't specified, the source state file will be used. This\r\n                          can be a new or existing path.\r\n\r\n  -var 'foo=bar'          Set a variable in the Terraform configuration. This\r\n                          flag can be set multiple times. This is only useful\r\n                          with the \"-config\" flag.\r\n\r\n  -var-file=foo           Set variables in the Terraform configuration from\r\n                          a file. If \"terraform.tfvars\" or any \".auto.tfvars\"\r\n                          files are present, they will be automatically loaded.\r\n\r\n  -ignore-remote-version  Continue even if remote and local Terraform versions\r\n                          differ. This may result in an unusable workspace, and\r\n                          should be used with extreme caution.\r\n<\/code><\/pre>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<h3><\/h3>\n<pre class=\"post-pre\"><code>$ terraform import module.\u30c7\u30a3\u30ec\u30af\u30c8\u30ea.\u30d5\u30a1\u30a4\u30eb\u540d.\u30d5\u30a1\u30a4\u30eb\u5185\u3067\u5b9a\u7fa9\u3057\u3066\u3044\u308b\u540d\u524d \u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u30b0\u30eb\u30fc\u30d7ID\r\n\r\nmodule.network.aws_security_group.XXX: Importing from ID \"XXX\"...\r\nmodule.network.aws_security_group.XXX: Import prepared!\r\n  Prepared aws_security_group for import\r\nmodule.network.aws_security_group.XXX: Refreshing state... [id=sg-XXX]\r\n\r\nImport successful!\r\n\r\nThe resources that were imported are shown above. These resources are now in\r\nyour Terraform state and will henceforth be managed by Terraform.\r\n<\/code><\/pre>\n<h2>\u6587\u737b\u53c3\u8003<\/h2>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u603b\u7ed3 \u53ea\u662f\u60f3\u8fdb\u884cTerraform \u5bfc\u5165\u64cd\u4f5c\uff0c\u4f46\u5374\u9047\u5230\u4e86\u56f0\u96be\uff0c\u6240\u4ee5\u6211\u628a\u8fd9\u5f53\u4f5c\u5907\u5fd8\u5f55\u8bb0\u5f55\u4e0b\u6765\u3002 \u9519\u8bef\u2460\uff1a\u5728\u914d\u7f6e\u4e2d [&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-48462","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>\u4f7f\u7528terraform import\u65f6\u9047\u5230\u7684\u95ee\u9898 - 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\/\u4f7f\u7528terraform-import\u65f6\u9047\u5230\u7684\u95ee\u9898\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4f7f\u7528terraform import\u65f6\u9047\u5230\u7684\u95ee\u9898\" \/>\n<meta property=\"og:description\" content=\"\u603b\u7ed3 \u53ea\u662f\u60f3\u8fdb\u884cTerraform \u5bfc\u5165\u64cd\u4f5c\uff0c\u4f46\u5374\u9047\u5230\u4e86\u56f0\u96be\uff0c\u6240\u4ee5\u6211\u628a\u8fd9\u5f53\u4f5c\u5907\u5fd8\u5f55\u8bb0\u5f55\u4e0b\u6765\u3002 \u9519\u8bef\u2460\uff1a\u5728\u914d\u7f6e\u4e2d [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528terraform-import\u65f6\u9047\u5230\u7684\u95ee\u9898\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-05-31T09:29:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-29T21:34:14+00:00\" \/>\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=\"3 \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%bd%bf%e7%94%a8terraform-import%e6%97%b6%e9%81%87%e5%88%b0%e7%9a%84%e9%97%ae%e9%a2%98\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8terraform-import%e6%97%b6%e9%81%87%e5%88%b0%e7%9a%84%e9%97%ae%e9%a2%98\/\",\"name\":\"\u4f7f\u7528terraform import\u65f6\u9047\u5230\u7684\u95ee\u9898 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-05-31T09:29:43+00:00\",\"dateModified\":\"2024-04-29T21:34:14+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/1a6ecd3d914d22a5ac32791ffc1fbd8e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8terraform-import%e6%97%b6%e9%81%87%e5%88%b0%e7%9a%84%e9%97%ae%e9%a2%98\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8terraform-import%e6%97%b6%e9%81%87%e5%88%b0%e7%9a%84%e9%97%ae%e9%a2%98\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8terraform-import%e6%97%b6%e9%81%87%e5%88%b0%e7%9a%84%e9%97%ae%e9%a2%98\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4f7f\u7528terraform import\u65f6\u9047\u5230\u7684\u95ee\u9898\"}]},{\"@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\/%e4%bd%bf%e7%94%a8terraform-import%e6%97%b6%e9%81%87%e5%88%b0%e7%9a%84%e9%97%ae%e9%a2%98\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u4f7f\u7528terraform import\u65f6\u9047\u5230\u7684\u95ee\u9898 - 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\/\u4f7f\u7528terraform-import\u65f6\u9047\u5230\u7684\u95ee\u9898\/","og_locale":"zh_CN","og_type":"article","og_title":"\u4f7f\u7528terraform import\u65f6\u9047\u5230\u7684\u95ee\u9898","og_description":"\u603b\u7ed3 \u53ea\u662f\u60f3\u8fdb\u884cTerraform \u5bfc\u5165\u64cd\u4f5c\uff0c\u4f46\u5374\u9047\u5230\u4e86\u56f0\u96be\uff0c\u6240\u4ee5\u6211\u628a\u8fd9\u5f53\u4f5c\u5907\u5fd8\u5f55\u8bb0\u5f55\u4e0b\u6765\u3002 \u9519\u8bef\u2460\uff1a\u5728\u914d\u7f6e\u4e2d [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528terraform-import\u65f6\u9047\u5230\u7684\u95ee\u9898\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-05-31T09:29:43+00:00","article_modified_time":"2024-04-29T21:34:14+00:00","author":"\u6e05, \u5b87","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u6e05, \u5b87","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8terraform-import%e6%97%b6%e9%81%87%e5%88%b0%e7%9a%84%e9%97%ae%e9%a2%98\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8terraform-import%e6%97%b6%e9%81%87%e5%88%b0%e7%9a%84%e9%97%ae%e9%a2%98\/","name":"\u4f7f\u7528terraform import\u65f6\u9047\u5230\u7684\u95ee\u9898 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-05-31T09:29:43+00:00","dateModified":"2024-04-29T21:34:14+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/1a6ecd3d914d22a5ac32791ffc1fbd8e"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8terraform-import%e6%97%b6%e9%81%87%e5%88%b0%e7%9a%84%e9%97%ae%e9%a2%98\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8terraform-import%e6%97%b6%e9%81%87%e5%88%b0%e7%9a%84%e9%97%ae%e9%a2%98\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8terraform-import%e6%97%b6%e9%81%87%e5%88%b0%e7%9a%84%e9%97%ae%e9%a2%98\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u4f7f\u7528terraform import\u65f6\u9047\u5230\u7684\u95ee\u9898"}]},{"@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\/%e4%bd%bf%e7%94%a8terraform-import%e6%97%b6%e9%81%87%e5%88%b0%e7%9a%84%e9%97%ae%e9%a2%98\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/48462","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=48462"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/48462\/revisions"}],"predecessor-version":[{"id":90004,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/48462\/revisions\/90004"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=48462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=48462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=48462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}