{"id":116515,"date":"2026-10-21T17:24:54","date_gmt":"2026-10-21T09:24:54","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/116515.html"},"modified":"2026-10-21T17:24:54","modified_gmt":"2026-10-21T09:24:54","slug":"%e7%bc%96%e5%86%99%e7%ac%ac%e4%b8%80%e4%b8%aa-terraform-module%ef%bc%9a%e7%bb%93%e6%9e%84%e3%80%81%e8%be%93%e5%85%a5%e8%be%93%e5%87%ba%e4%b8%8e%e5%8f%98%e9%87%8f%e6%a0%a1%e9%aa%8c","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/116515.html","title":{"rendered":"\u7f16\u5199\u7b2c\u4e00\u4e2a Terraform Module\uff1a\u7ed3\u6784\u3001\u8f93\u5165\u8f93\u51fa\u4e0e\u53d8\u91cf\u6821\u9a8c"},"content":{"rendered":"<p>\u4e09\u5957\u73af\u5883\u7684 S3 \u914d\u7f6e\u5404\u6284\u4e86\u4e00\u4efd&#xff0c;\u6539\u4e2a\u53c2\u6570\u8981\u52a8\u4e09\u4e2a\u76ee\u5f55\u3002\u6709\u4e00\u56de\u6f0f\u6539&#xff0c;plan \u91cc dev \u7684 bucket \u524d\u7f00\u8ddf prod \u649e\u4e86\u3002<\/p>\n<p>&#x1f4a1; \u793a\u4f8b\u57fa\u4e8e Terraform 1.x &#043; AWS provider 5.x&#xff0c;\u6a21\u5757\u653e\u5728 .\/modules\/s3_bucket&#xff0c;\u672c\u5730\u8def\u5f84\u5f15\u7528&#xff0c;\u4e0d\u63a8 registry \u4e5f\u80fd\u8dd1\u3002<\/p>\n<h3>1. \u6a21\u5757\u7ed3\u6784\u4e0e\u8c03\u7528\u5173\u7cfb<\/h3>\n<h4>1.1 \u4e09\u6bb5\u6587\u4ef6\u7ed3\u6784<\/h4>\n<p>\u4e00\u4e2a\u76ee\u5f55\u5c31\u662f\u4e00\u4e2a\u6a21\u5757&#xff0c;\u76ee\u5f55\u91cc\u7684 .tf \u6587\u4ef6\u5168\u90e8\u53c2\u4e0e\u6c42\u503c\u3002\u7ea6\u5b9a\u62c6\u6210\u4e09\u4e2a\u6587\u4ef6&#xff0c;\u628a\u8f93\u5165\u3001\u52a0\u5de5\u3001\u8f93\u51fa\u5206\u5f00\u3002<\/p>\n<table>\n<tr>\u6587\u4ef6\u804c\u8d23\u5185\u5bb9<\/tr>\n<tbody>\n<tr>\n<td>variables.tf<\/td>\n<td>\u8f93\u5165<\/td>\n<td>variable \u5757&#xff0c;\u58f0\u660e\u8c03\u7528\u65b9\u80fd\u4f20\u4ec0\u4e48<\/td>\n<\/tr>\n<tr>\n<td>main.tf<\/td>\n<td>\u52a0\u5de5<\/td>\n<td>resource \/ data \/ locals&#xff0c;\u771f\u6b63\u5e72\u6d3b\u7684\u8d44\u6e90<\/td>\n<\/tr>\n<tr>\n<td>outputs.tf<\/td>\n<td>\u8f93\u51fa<\/td>\n<td>output \u5757&#xff0c;\u58f0\u660e\u8c03\u7528\u65b9\u80fd\u8bfb\u5230\u4ec0\u4e48<\/td>\n<\/tr>\n<tr>\n<td>versions.tf<\/td>\n<td>\u4f9d\u8d56\u7ea6\u675f<\/td>\n<td>terraform \u5757 &#043; required_providers<\/td>\n<\/tr>\n<tr>\n<td>README.md<\/td>\n<td>\u6587\u6863<\/td>\n<td>\u53c2\u6570\u8868\u3001\u8c03\u7528\u793a\u4f8b&#xff0c;registry \u4f1a\u6e32\u67d3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6587\u4ef6\u540d\u672c\u8eab\u6ca1\u6709\u8bed\u4e49&#xff0c;Terraform \u53ea\u8ba4\u540e\u7f00\u3002\u62c6\u4e09\u4e2a\u6587\u4ef6\u662f\u4e3a\u4e86\u8ba9\u4eba\u4e00\u773c\u627e\u5230\u5165\u53e3\u548c\u51fa\u53e3\u3002<\/p>\n<p>\u8dd1 terraform plan \u7684\u90a3\u4e2a\u76ee\u5f55\u53eb root module&#xff0c;\u88ab\u5b83\u5f15\u7528\u7684\u76ee\u5f55\u53eb child module\u3002child module \u4e0d\u80fd\u5355\u72ec apply&#xff0c;\u53ea\u80fd\u7531 root \u4f20\u53c2\u8c03\u7528\u3002<\/p>\n<p>terraform-aws-s3-bucket\/<br \/>\n\u251c\u2500\u2500 variables.tf &#8230;&#8230;&#8230; \u8f93\u5165&#xff1a;name \/ versioning \/ force_destroy \/ tags<br \/>\n\u251c\u2500\u2500 main.tf &#8230;&#8230;&#8230;&#8230;.. \u52a0\u5de5&#xff1a;aws_s3_bucket &#043; \u7248\u672c\u63a7\u5236 &#043; \u516c\u5171\u8bbf\u95ee\u963b\u65ad<br \/>\n\u251c\u2500\u2500 outputs.tf &#8230;&#8230;&#8230;.. \u8f93\u51fa&#xff1a;bucket_id \/ bucket_arn \/ bucket_domain_name<br \/>\n\u251c\u2500\u2500 versions.tf &#8230;&#8230;&#8230;. required_providers: aws ~&gt; 5.0<br \/>\n\u2514\u2500\u2500 README.md<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261021092450-6ad884e2d9391.png\" alt=\"\" \/><\/p>\n<h4>1.2 \u8c03\u7528\u65b9\u5f0f\u4e0e\u8d44\u6e90\u5730\u5740<\/h4>\n<p>\u8c03\u7528\u65b9\u5728\u81ea\u5df1\u7684 main.tf \u91cc\u5199 module \u5757&#xff0c;source \u6307\u5411\u6a21\u5757\u76ee\u5f55&#xff0c;\u5176\u4f59\u53c2\u6570\u6309\u53d8\u91cf\u540d\u4f20\u3002<\/p>\n<p>module &#034;s3_bucket&#034; {<br \/>\n  source &#061; &#034;.\/modules\/s3_bucket&#034;<\/p>\n<p>  name          &#061; &#034;logs-archive&#034;<br \/>\n  versioning    &#061; true<br \/>\n  force_destroy &#061; false<\/p>\n<p>  tags &#061; {<br \/>\n    env &#061; &#034;dev&#034;<br \/>\n  }<br \/>\n}<\/p>\n<p>\u6a21\u5757\u5185\u90e8\u7684\u8d44\u6e90\u5730\u5740\u4f1a\u52a0\u4e0a\u6a21\u5757\u524d\u7f00&#xff0c;aws_s3_bucket.this \u53d8\u6210 module.s3_bucket.aws_s3_bucket.this\u3002\u8c03\u7528\u65b9\u8bfb\u8f93\u51fa\u5199 module.s3_bucket.bucket_id&#xff0c;\u78b0\u4e0d\u5230\u5185\u90e8\u8d44\u6e90\u540d\u3002<\/p>\n<p>\u8c03\u7528\u65b9 main.tf \u2500\u2500\u4f20\u53d8\u91cf\u2500\u2500\u25b6 variables.tf \u2500\u2500\u252c\u2500\u6821\u9a8c\u901a\u8fc7\u2500\u25b6 main.tf \u8d44\u6e90 \u2500\u25b6 outputs.tf \u2500\u2500\u8f93\u51fa\u2500\u2500\u25b6 \u8c03\u7528\u65b9<br \/>\n                                          \u2514\u2500\u6821\u9a8c\u5931\u8d25\u2500\u25b6 plan \u62a5\u9519<\/p>\n<p>source \u6709\u56db\u7c7b\u5199\u6cd5&#xff0c;\u80fd\u5199 version \u7684\u53ea\u6709 registry&#xff1a;<\/p>\n<table>\n<tr>source \u5199\u6cd5\u793a\u4f8b\u80fd\u5426\u5199 version<\/tr>\n<tbody>\n<tr>\n<td>\u672c\u5730\u8def\u5f84<\/td>\n<td>.\/modules\/s3_bucket<\/td>\n<td>\u5426<\/td>\n<\/tr>\n<tr>\n<td>Registry<\/td>\n<td>hashicorp\/consul\/aws<\/td>\n<td>\u662f&#xff0c;version &#061; &#034;~&gt; 0.11&#034;<\/td>\n<\/tr>\n<tr>\n<td>Git<\/td>\n<td>git::https:\/\/example.com\/vpc.git?ref&#061;v1.2.0<\/td>\n<td>\u7528 ?ref&#061; \u9501\u7248\u672c<\/td>\n<\/tr>\n<tr>\n<td>HTTP \u5f52\u6863<\/td>\n<td>https:\/\/example.com\/vpc-module.zip<\/td>\n<td>\u5426<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u672c\u5730\u8def\u5f84\u9002\u5408\u5f00\u53d1\u671f&#xff0c;\u7a33\u5b9a\u540e\u63a8 Git \u6253 tag&#xff0c;\u7528 ?ref&#061; \u56fa\u5b9a\u7248\u672c\u53f7\u3002<\/p>\n<h3>2. \u8f93\u5165&#xff1a;variables.tf<\/h3>\n<h4>2.1 \u56db\u4e2a\u5e38\u7528\u5c5e\u6027<\/h4>\n<table>\n<tr>\u5c5e\u6027\u4f5c\u7528\u4e0d\u5199\u4f1a\u600e\u6837<\/tr>\n<tbody>\n<tr>\n<td>type<\/td>\n<td>\u7ea6\u675f\u4f20\u5165\u503c\u7684\u7c7b\u578b<\/td>\n<td>\u89c6\u4e3a any&#xff0c;\u5199\u9519\u7c7b\u578b\u5230 plan \u624d\u70b8<\/td>\n<\/tr>\n<tr>\n<td>default<\/td>\n<td>\u9ed8\u8ba4\u503c&#xff0c;\u5199\u4e86\u5c31\u53d8\u53ef\u9009<\/td>\n<td>\u4e0d\u5199\u5373\u5fc5\u586b&#xff0c;\u8c03\u7528\u65b9\u6f0f\u4f20\u76f4\u63a5\u62a5\u9519<\/td>\n<\/tr>\n<tr>\n<td>description<\/td>\n<td>\u53c2\u6570\u8bf4\u660e<\/td>\n<td>\u6587\u6863\u9760\u4eba\u8089\u7ef4\u62a4<\/td>\n<\/tr>\n<tr>\n<td>sensitive<\/td>\n<td>\u6253\u7801&#xff0c;plan \u91cc\u663e\u793a (sensitive value)<\/td>\n<td>\u660e\u6587\u8fdb plan \u548c\u65e5\u5fd7<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>variable &#034;name&#034; {<br \/>\n  type        &#061; string<br \/>\n  description &#061; &#034;Bucket \u540d\u79f0\u524d\u7f00&#xff0c;\u5168\u5c40\u552f\u4e00&#034;<br \/>\n}<\/p>\n<p>variable &#034;versioning&#034; {<br \/>\n  type        &#061; bool<br \/>\n  description &#061; &#034;\u662f\u5426\u5f00\u542f\u7248\u672c\u63a7\u5236&#034;<br \/>\n  default     &#061; false<br \/>\n}<\/p>\n<p>variable &#034;force_destroy&#034; {<br \/>\n  type        &#061; bool<br \/>\n  description &#061; &#034;\u9500\u6bc1\u65f6\u662f\u5426\u6e05\u7a7a\u5bf9\u8c61&#034;<br \/>\n  default     &#061; false<br \/>\n}<\/p>\n<p>name \u6ca1\u6709 default&#xff0c;\u8c03\u7528\u65b9\u5fc5\u987b\u4f20\u3002\u53e6\u5916\u4e24\u4e2a\u6709\u9ed8\u8ba4\u503c&#xff0c;\u4e0d\u4f20\u5c31\u53d6\u9ed8\u8ba4\u3002<\/p>\n<h4>2.2 \u590d\u6742\u7c7b\u578b\u4e0e\u53ef\u9009\u5b57\u6bb5<\/h4>\n<table>\n<tr>\u7c7b\u578b\u5199\u6cd5\u9002\u5408<\/tr>\n<tbody>\n<tr>\n<td>\u57fa\u7840<\/td>\n<td>string number bool<\/td>\n<td>\u5355\u4e2a\u503c<\/td>\n<\/tr>\n<tr>\n<td>\u96c6\u5408<\/td>\n<td>list(string) set(string) map(string)<\/td>\n<td>\u540c\u7c7b\u578b\u591a\u503c<\/td>\n<\/tr>\n<tr>\n<td>\u7ed3\u6784<\/td>\n<td>object({&#8230;})<\/td>\n<td>\u4e00\u7ec4\u56fa\u5b9a\u5b57\u6bb5<\/td>\n<\/tr>\n<tr>\n<td>\u5143\u7ec4<\/td>\n<td>tuple([string, number])<\/td>\n<td>\u4f4d\u7f6e\u56fa\u5b9a\u3001\u7c7b\u578b\u4e0d\u540c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5bf9\u8c61\u91cc\u90e8\u5206\u5b57\u6bb5\u53ef\u4ee5\u4e0d\u586b&#xff0c;\u7528 optional()&#xff0c;Terraform 1.3 \u8d77\u652f\u6301&#xff1a;<\/p>\n<p>variable &#034;lifecycle_rule&#034; {<br \/>\n  type &#061; object({<br \/>\n    enabled &#061; bool<br \/>\n    days    &#061; optional(number, 30)<br \/>\n    prefix  &#061; optional(string, &#034;&#034;)<br \/>\n  })<br \/>\n  default &#061; {<br \/>\n    enabled &#061; true<br \/>\n  }<br \/>\n}<\/p>\n<p>days \u548c prefix \u6ca1\u4f20\u65f6\u53d6\u62ec\u53f7\u91cc\u7684\u9ed8\u8ba4\u503c\u3002\u8c03\u7528\u65b9\u53ea\u5199\u5fc5\u586b\u9879&#xff0c;\u6a21\u5757\u5185\u90e8\u6309\u5b8c\u6574\u7ed3\u6784\u4f7f\u7528\u3002<\/p>\n<p>\u26a0\ufe0f list \u7528\u4f4d\u7f6e\u7d22\u5f15&#xff0c;\u4e2d\u95f4\u63d2\u4e00\u4e2a\u5143\u7d20\u4f1a\u8ba9\u540e\u9762\u6574\u4f53\u524d\u79fb&#xff1b;set \u6210\u5458\u65e0\u5e8f&#xff0c;\u53d6\u503c\u987a\u5e8f\u4e0d\u4fdd\u8bc1\u3002\u8981\u6309\u540d\u5b57\u5f15\u7528\u5c31\u6362\u6210 map\u3002<\/p>\n<h4>2.3 \u53d8\u91cf\u6765\u6e90\u4e0e\u4f18\u5148\u7ea7<\/h4>\n<p>\u540c\u4e00\u4e2a\u53d8\u91cf\u53ef\u80fd\u4ece\u591a\u5904\u8d4b\u503c&#xff0c;Terraform \u6309\u56fa\u5b9a\u987a\u5e8f\u53d6&#xff0c;\u540e\u8005\u8986\u76d6\u524d\u8005&#xff1a;<\/p>\n<p>\u73af\u5883\u53d8\u91cf TF_VAR_name<br \/>\n  \u25bc \u8986\u76d6<br \/>\nterraform.tfvars<br \/>\n  \u25bc<br \/>\nterraform.tfvars.json<br \/>\n  \u25bc<br \/>\n*.auto.tfvars \/ *.auto.tfvars.json&#xff08;\u6309\u6587\u4ef6\u540d\u6392\u5e8f&#xff09;<br \/>\n  \u25bc<br \/>\n-var \/ -var-file&#xff08;\u547d\u4ee4\u884c&#xff0c;\u5199\u5728\u540e\u9762\u7684\u8d62&#xff09;<\/p>\n<p><span class=\"token builtin class-name\">export<\/span> <span class=\"token assign-left variable\">TF_VAR_name<\/span><span class=\"token operator\">&#061;<\/span>from-env<br \/>\nterraform plan <span class=\"token parameter variable\">-var<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;name&#061;from-cli&#034;<\/span><\/p>\n<p>\u7ed3\u679c\u53d6 from-cli\u3002\u53c2\u6570\u6ca1\u751f\u6548\u65f6\u5148\u67e5\u8fd9\u6761\u94fe&#xff0c;\u516b\u6210\u662f\u67d0\u4e2a auto.tfvars \u628a\u4eba\u5751\u4e86\u3002<\/p>\n<h3>3. \u8f93\u51fa&#xff1a;outputs.tf<\/h3>\n<h4>3.1 value \u4e0e description<\/h4>\n<p>\u8c03\u7528\u65b9\u53ea\u80fd\u8bfb\u5230 output \u58f0\u660e\u8fc7\u7684\u503c&#xff0c;\u6a21\u5757\u5185\u90e8\u8d44\u6e90\u5c5e\u6027\u4e0d\u58f0\u660e\u5c31\u51fa\u4e0d\u53bb\u3002<\/p>\n<p>output &#034;bucket_id&#034; {<br \/>\n  description &#061; &#034;Bucket \u540d\u79f0&#034;<br \/>\n  value       &#061; aws_s3_bucket.this.id<br \/>\n}<\/p>\n<p>output &#034;bucket_arn&#034; {<br \/>\n  description &#061; &#034;Bucket ARN&#xff0c;\u7528\u4e8e\u7b56\u7565\u6388\u6743&#034;<br \/>\n  value       &#061; aws_s3_bucket.this.arn<br \/>\n}<\/p>\n<p>\u5f15\u7528\u5199 module.s3_bucket.bucket_arn\u3002value \u652f\u6301\u8868\u8fbe\u5f0f&#xff0c;\u62fc\u597d\u7684\u5b57\u7b26\u4e32\u4e5f\u80fd\u51fa\u3002<\/p>\n<table>\n<tr>\u5c5e\u6027\u7528\u9014<\/tr>\n<tbody>\n<tr>\n<td>value<\/td>\n<td>\u5fc5\u586b&#xff0c;\u8f93\u51fa\u5185\u5bb9<\/td>\n<\/tr>\n<tr>\n<td>description<\/td>\n<td>\u8bf4\u660e&#xff0c;registry \u6587\u6863\u7528<\/td>\n<\/tr>\n<tr>\n<td>sensitive<\/td>\n<td>\u6253\u7801&#xff0c;\u5411\u4e0a\u4f20\u64ad<\/td>\n<\/tr>\n<tr>\n<td>depends_on<\/td>\n<td>\u5f3a\u5236\u4f9d\u8d56&#xff0c;\u8f93\u51fa\u524d\u7b49\u67d0\u8d44\u6e90\u5c31\u7eea<\/td>\n<\/tr>\n<tr>\n<td>precondition<\/td>\n<td>\u8f93\u51fa\u524d\u6821\u9a8c&#xff0c;\u4e0d\u6ee1\u8db3\u76f4\u63a5\u62a5\u9519<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>3.2 \u654f\u611f\u8f93\u51fa<\/h4>\n<p>\u5bc6\u7801\u3001\u5bc6\u94a5\u8fd9\u7c7b\u503c\u52a0 sensitive &#061; true&#xff0c;plan \u548c terraform output \u90fd\u663e\u793a (sensitive value)\u3002<\/p>\n<p>output &#034;secret_key&#034; {<br \/>\n  description &#061; &#034;\u8bbf\u95ee\u5bc6\u94a5&#034;<br \/>\n  value       &#061; aws_iam_access_key.this.secret<br \/>\n  sensitive   &#061; true<br \/>\n}<\/p>\n<p>\u53d6\u771f\u5b9e\u503c\u7528 terraform output -raw secret_key\u3002sensitive \u4f1a\u5411\u4e0a\u4f20\u64ad&#xff0c;\u5f15\u7528\u654f\u611f\u8f93\u51fa\u7684\u53e6\u4e00\u4e2a output \u4e5f\u8981\u6807\u654f\u611f&#xff0c;\u5426\u5219 plan \u62a5\u9519\u3002<\/p>\n<h3>4. \u53d8\u91cf\u6821\u9a8c<\/h3>\n<h4>4.1 validation \u5757<\/h4>\n<p>variable \u5757\u91cc\u52a0 validation&#xff0c;condition \u8fd4\u56de false \u65f6 plan \u76f4\u63a5\u5931\u8d25&#xff0c;\u9644\u4e0a error_message\u3002<\/p>\n<p>variable &#034;name&#034; {<br \/>\n  type        &#061; string<br \/>\n  description &#061; &#034;Bucket \u540d\u79f0\u524d\u7f00&#034;<\/p>\n<p>  validation {<br \/>\n    condition     &#061; can(regex(&#034;^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$&#034;, var.name))<br \/>\n    error_message &#061; &#034;name \u53ea\u5141\u8bb8\u5c0f\u5199\u5b57\u6bcd\u3001\u6570\u5b57\u3001\u8fde\u5b57\u7b26&#xff0c;\u957f\u5ea6 3-63\u3002&#034;<br \/>\n  }<\/p>\n<p>  validation {<br \/>\n    condition     &#061; !strcontains(var.name, &#034;..&#034;)<br \/>\n    error_message &#061; &#034;name \u4e0d\u80fd\u542b\u8fde\u7eed\u4e24\u4e2a\u70b9\u3002&#034;<br \/>\n  }<br \/>\n}<\/p>\n<p>can() \u628a\u53ef\u80fd\u62a5\u9519\u7684\u8868\u8fbe\u5f0f\u5305\u6210\u5e03\u5c14\u503c&#xff0c;\u6b63\u5219\u4e0d\u5339\u914d\u65f6\u8fd4\u56de false&#xff0c;\u4e0d\u4f1a\u629b\u5f02\u5e38\u4e2d\u65ad\u3002\u4e00\u4e2a\u53d8\u91cf\u53ef\u4ee5\u6302\u591a\u4e2a validation&#xff0c;\u5168\u90e8\u901a\u8fc7\u624d\u7ee7\u7eed\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261021092451-6ad884e3ce659.png\" alt=\"\" \/><\/p>\n<h4>4.2 condition \u7684\u7ea6\u675f<\/h4>\n<table>\n<tr>\u7ea6\u675f\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u5fc5\u987b\u8fd4\u56de bool<\/td>\n<td>\u8fd4\u56de\u5b57\u7b26\u4e32\u6216\u6570\u5b57\u62a5 Invalid expression value<\/td>\n<\/tr>\n<tr>\n<td>\u53ea\u80fd\u7528\u7eaf\u51fd\u6570<\/td>\n<td>uuid() timestamp() bcrypt() \u6bcf\u6b21\u7ed3\u679c\u4e0d\u540c&#xff0c;\u7981\u7528<\/td>\n<\/tr>\n<tr>\n<td>\u5f15\u7528\u8303\u56f4<\/td>\n<td>1.9 \u4e4b\u524d\u53ea\u80fd\u5f15\u7528\u88ab\u6821\u9a8c\u7684\u90a3\u4e2a\u53d8\u91cf&#xff1b;1.9 \u8d77\u53ef\u5f15\u7528\u5176\u4ed6\u8f93\u5165\u53d8\u91cf<\/td>\n<\/tr>\n<tr>\n<td>\u62a5\u9519\u65f6\u673a<\/td>\n<td>plan \u9636\u6bb5&#xff0c;\u65e9\u4e8e\u4efb\u4f55\u4e91 API \u8c03\u7528<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8de8\u53d8\u91cf\u6821\u9a8c\u5728 1.9 \u4e4b\u524d\u7528 precondition \u515c\u5e95&#xff1a;<\/p>\n<p>variable &#034;environment&#034; {<br \/>\n  type &#061; string<br \/>\n}<\/p>\n<p>variable &#034;enable_versioning&#034; {<br \/>\n  type    &#061; bool<br \/>\n  default &#061; false<br \/>\n}<\/p>\n<p>environment &#061; &#034;prod&#034; \u4e14\u6ca1\u5f00\u7248\u672c\u63a7\u5236\u65f6&#xff0c;\u5e0c\u671b\u5728 plan \u9636\u6bb5\u62e6\u4f4f&#xff0c;\u628a\u6821\u9a8c\u6302\u5230\u8d44\u6e90\u4e0a&#xff1a;<\/p>\n<p>resource &#034;aws_s3_bucket&#034; &#034;this&#034; {<br \/>\n  bucket &#061; var.name<\/p>\n<p>  lifecycle {<br \/>\n    precondition {<br \/>\n      condition     &#061; var.environment !&#061; &#034;prod&#034; || var.enable_versioning<br \/>\n      error_message &#061; &#034;\u751f\u4ea7\u73af\u5883\u7684 bucket \u5fc5\u987b\u5f00\u542f\u7248\u672c\u63a7\u5236\u3002&#034;<br \/>\n    }<br \/>\n  }<br \/>\n}<\/p>\n<p>precondition \u5199\u5728 lifecycle \u91cc&#xff0c;condition \u80fd\u8bfb\u4efb\u610f\u53d8\u91cf\u548c\u8d44\u6e90\u5c5e\u6027&#xff0c;\u6bd4 validation \u5bbd\u677e\u3002<\/p>\n<h4>4.3 \u5e38\u7528\u6821\u9a8c\u5199\u6cd5<\/h4>\n<table>\n<tr>\u9700\u6c42condition<\/tr>\n<tbody>\n<tr>\n<td>\u975e\u7a7a\u5b57\u7b26\u4e32<\/td>\n<td>length(var.name) &gt; 0<\/td>\n<\/tr>\n<tr>\n<td>\u679a\u4e3e\u503c<\/td>\n<td>contains([&#034;dev&#034;, &#034;staging&#034;, &#034;prod&#034;], var.environment)<\/td>\n<\/tr>\n<tr>\n<td>\u6570\u5b57\u533a\u95f4<\/td>\n<td>var.port &gt;&#061; 1 &amp;&amp; var.port &lt;&#061; 65535<\/td>\n<\/tr>\n<tr>\n<td>CIDR \u683c\u5f0f<\/td>\n<td>can(cidrhost(var.vpc_cidr, 0))<\/td>\n<\/tr>\n<tr>\n<td>\u524d\u7f00\u5339\u914d<\/td>\n<td>startswith(var.name, &#034;logs-&#034;)<\/td>\n<\/tr>\n<tr>\n<td>\u5217\u8868\u975e\u7a7a<\/td>\n<td>length(var.subnet_ids) &gt; 0<\/td>\n<\/tr>\n<tr>\n<td>\u4e92\u65a5\u5f00\u5173<\/td>\n<td>!(var.public &amp;&amp; var.private)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&#x1f4a1; error_message \u5199\u6e05\u671f\u671b\u503c&#xff0c;\u522b\u53ea\u5199\u300c\u53c2\u6570\u975e\u6cd5\u300d<\/p>\n<p>plan \u5931\u8d25\u65f6\u8c03\u7528\u65b9\u53ea\u80fd\u770b\u5230\u8fd9\u4e00\u884c\u63d0\u793a&#xff0c;\u628a\u5141\u8bb8\u8303\u56f4\u548c\u5b9e\u9645\u503c\u90fd\u5e26\u4e0a&#xff1a; validation { condition &#061; contains([\u201cdev\u201d, \u201cstaging\u201d, \u201cprod\u201d], var.environment) error_message &#061; \u201cenvironment \u53ea\u80fd\u662f dev \/ staging \/ prod&#xff0c;\u5f53\u524d\u503c ${var.environment}\u3002\u201d }<\/p>\n<h3>5. \u62bd\u53d6\u53ef\u590d\u7528\u6a21\u5757<\/h3>\n<h4>5.1 \u62bd\u53d6\u524d\u7684\u72b6\u6001<\/h4>\n<p>\u4e09\u5957\u73af\u5883\u5404\u6709\u4e00\u4efd main.tf&#xff0c;S3 \u76f8\u5173\u6bb5\u843d\u51e0\u4e4e\u4e00\u81f4&#xff0c;\u53ea\u6709\u524d\u7f00\u548c\u7248\u672c\u63a7\u5236\u5f00\u5173\u4e0d\u540c\u3002<\/p>\n<p>envs\/<br \/>\n\u251c\u2500\u2500 dev\/main.tf &#8230;&#8230;. aws_s3_bucket &#043; versioning &#043; \u516c\u5171\u8bbf\u95ee\u963b\u65ad<br \/>\n\u251c\u2500\u2500 staging\/main.tf &#8230; \u540c\u4e00\u6bb5\u8d44\u6e90\u5b9a\u4e49&#xff0c;\u590d\u5236\u4e00\u904d<br \/>\n\u2514\u2500\u2500 prod\/main.tf &#8230;&#8230; \u540c\u4e00\u6bb5\u8d44\u6e90\u5b9a\u4e49&#xff0c;\u518d\u590d\u5236\u4e00\u904d<\/p>\n<p>\u6539\u4e00\u6761\u516c\u5171\u89c4\u5219\u8981\u52a8\u4e09\u5904&#xff0c;\u6f0f\u4e00\u5904 plan \u5c31\u51fa\u5dee\u5f02\u3002\u628a\u8fd9\u4e9b\u6bb5\u843d\u6536\u8fdb\u4e00\u4e2a\u76ee\u5f55&#xff0c;\u73af\u5883\u76ee\u5f55\u53ea\u7559 module \u5757\u3002<\/p>\n<h4>5.2 \u76ee\u5f55\u89c4\u5212<\/h4>\n<p>.<br \/>\n\u251c\u2500\u2500 modules\/<br \/>\n\u2502   \u2514\u2500\u2500 s3_bucket\/<br \/>\n\u2502       \u251c\u2500\u2500 variables.tf<br \/>\n\u2502       \u251c\u2500\u2500 main.tf<br \/>\n\u2502       \u251c\u2500\u2500 outputs.tf<br \/>\n\u2502       \u2514\u2500\u2500 versions.tf<br \/>\n\u2514\u2500\u2500 envs\/<br \/>\n    \u251c\u2500\u2500 dev\/main.tf<br \/>\n    \u251c\u2500\u2500 staging\/main.tf<br \/>\n    \u2514\u2500\u2500 prod\/main.tf<\/p>\n<p>modules\/ \u653e\u53ef\u590d\u7528\u5355\u5143&#xff0c;envs\/ \u653e\u5404\u73af\u5883\u5165\u53e3\u3002\u6a21\u5757\u76ee\u5f55\u53ea\u7559\u901a\u7528\u903b\u8f91&#xff0c;\u73af\u5883\u5dee\u5f02\u901a\u8fc7\u53d8\u91cf\u4f20\u8fdb\u53bb\u3002<\/p>\n<p>\u6a21\u5757\u7c92\u5ea6\u6309\u300c\u80fd\u4e0d\u80fd\u72ec\u7acb\u63cf\u8ff0\u4e00\u4ef6\u4e8b\u300d\u5207\u3002S3 \u6a21\u5757\u53ea\u7ba1 bucket \u672c\u8eab&#xff0c;\u9700\u8981 VPC \u5c31\u8ba9\u8c03\u7528\u65b9\u628a vpc_id \u4f20\u8fdb\u6765&#xff0c;\u522b\u5728\u6a21\u5757\u91cc\u987a\u624b\u5efa VPC\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261021092452-6ad884e4ae4b5.jpg\" alt=\"\u5916\u94fe\u56fe\u7247\u8f6c\u5b58\u5931\u8d25,\u6e90\u7ad9\u53ef\u80fd\u6709\u9632\u76d7\u94fe\u673a\u5236,\u5efa\u8bae\u5c06\u56fe\u7247\u4fdd\u5b58\u4e0b\u6765\u76f4\u63a5\u4e0a\u4f20\" \/><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261021092452-6ad884e4f1ceb.png\" alt=\"\" \/><\/p>\n<h4>5.3 \u8fc1\u79fb\u6b65\u9aa4<\/h4>\n<li>\u5efa modules\/s3_bucket\/&#xff0c;\u628a\u4e09\u4e2a\u6587\u4ef6\u642c\u8fdb\u53bb&#xff0c;\u786c\u7f16\u7801\u6539\u6210 variable \u58f0\u660e<\/li>\n<li>\u73af\u5883\u76ee\u5f55\u6539\u5199\u6210 module \u5757&#xff0c;\u53c2\u6570\u8d70\u53d8\u91cf<\/li>\n<li>\u642c\u72b6\u6001\u5730\u5740&#xff0c;\u907f\u514d\u9500\u6bc1\u91cd\u5efa<\/li>\n<li>terraform plan \u786e\u8ba4\u8f93\u51fa No changes<\/li>\n<p>\u72b6\u6001\u8fc1\u79fb\u662f\u552f\u4e00\u5bb9\u6613\u51fa\u4e8b\u7684\u4e00\u6b65\u3002\u8d44\u6e90\u5730\u5740\u591a\u4e86\u6a21\u5757\u524d\u7f00&#xff0c;\u4e0d\u642c\u5c31\u662f\u300c\u65e7\u7684\u9500\u6bc1 &#043; \u65b0\u7684\u521b\u5efa\u300d&#xff1a;<\/p>\n<p>terraform state <span class=\"token function\">mv<\/span> <span class=\"token string\">&#039;aws_s3_bucket.this&#039;<\/span> <span class=\"token string\">&#039;module.s3_bucket.aws_s3_bucket.this&#039;<\/span><br \/>\nterraform state <span class=\"token function\">mv<\/span> <span class=\"token string\">&#039;aws_s3_bucket_versioning.this&#039;<\/span> <span class=\"token string\">&#039;module.s3_bucket.aws_s3_bucket_versioning.this&#039;<\/span><br \/>\nterraform plan<\/p>\n<p>No changes. Your infrastructure matches the configuration.<\/p>\n<p>plan \u91cc\u51fa\u73b0 destroy&#xff0c;\u8bf4\u660e\u6709\u8d44\u6e90\u5730\u5740\u6f0f\u642c&#xff0c;\u53cd\u5411\u6267\u884c\u4e00\u6b21 state mv \u5c31\u80fd\u9000\u56de\u53bb\u3002<\/p>\n<p>\u26a0\ufe0f state mv \u53ea\u6539\u72b6\u6001\u6587\u4ef6\u91cc\u7684\u5730\u5740&#xff0c;\u4e0d\u52a8\u771f\u5b9e\u8d44\u6e90\u3002\u6267\u884c\u524d\u5148 terraform state list \u5bf9\u4e00\u904d\u6e05\u5355&#xff0c;\u632a\u9519\u4e86\u5728\u771f\u5b9e\u73af\u5883\u91cc\u770b\u4e0d\u51fa\u6765\u3002<\/p>\n<h4>5.4 \u6a21\u5757\u5185\u7684 provider \u58f0\u660e<\/h4>\n<p>\u6a21\u5757\u91cc\u5199 provider &#034;aws&#034; {} \u5728 0.13 \u4e4b\u540e\u88ab\u5f03\u7528&#xff0c;provider \u914d\u7f6e\u7531\u6839\u6a21\u5757\u51b3\u5b9a&#xff0c;\u6a21\u5757\u53ea\u58f0\u660e\u4f9d\u8d56\u7248\u672c\u3002<\/p>\n<p>terraform {<br \/>\n  required_version &#061; &#034;&gt;&#061; 1.5.0&#034;<\/p>\n<p>  required_providers {<br \/>\n    aws &#061; {<br \/>\n      source  &#061; &#034;hashicorp\/aws&#034;<br \/>\n      version &#061; &#034;~&gt; 5.0&#034;<br \/>\n    }<br \/>\n  }<br \/>\n}<\/p>\n<p>~&gt; 5.0 \u5141\u8bb8 5.x \u5c0f\u7248\u672c\u5347\u7ea7&#xff0c;\u6321\u4f4f 6.0 \u7684\u4e0d\u517c\u5bb9\u53d8\u66f4\u3002<\/p>\n<h3>6. \u5e38\u89c1\u62a5\u9519\u4e0e\u6392\u67e5<\/h3>\n<table>\n<tr>\u62a5\u9519 \/ \u73b0\u8c61\u539f\u56e0\u5904\u7406<\/tr>\n<tbody>\n<tr>\n<td>Unsupported argument<\/td>\n<td>\u6a21\u5757\u6ca1\u58f0\u660e\u8be5\u53d8\u91cf&#xff0c;\u8c03\u7528\u65b9\u5374\u4f20\u4e86<\/td>\n<td>\u5728 variables.tf \u8865 variable&#xff0c;\u6216\u5220\u6389\u4f20\u53c2<\/td>\n<\/tr>\n<tr>\n<td>Missing required argument<\/td>\n<td>\u53d8\u91cf\u6ca1\u6709 default&#xff0c;\u8c03\u7528\u65b9\u6f0f\u4f20<\/td>\n<td>\u4f20\u503c&#xff0c;\u6216\u7ed9\u53d8\u91cf\u52a0 default<\/td>\n<\/tr>\n<tr>\n<td>Invalid value for variable<\/td>\n<td>validation \u7684 condition \u8fd4\u56de false<\/td>\n<td>\u770b error_message \u91cc\u7684\u5141\u8bb8\u8303\u56f4<\/td>\n<\/tr>\n<tr>\n<td>Invalid expression value<\/td>\n<td>condition \u6ca1\u8fd4\u56de bool<\/td>\n<td>\u5305\u4e00\u5c42 can()&#xff0c;\u6216\u8865\u4e0a\u6bd4\u8f83\u8fd0\u7b97<\/td>\n<\/tr>\n<tr>\n<td>Reference to undeclared output<\/td>\n<td>\u8bfb\u4e86\u6a21\u5757\u6ca1\u58f0\u660e\u7684\u8f93\u51fa<\/td>\n<td>\u5728 outputs.tf \u8865 output<\/td>\n<\/tr>\n<tr>\n<td>Module version requirements have not been met<\/td>\n<td>\u672c\u5730\u8def\u5f84\u4e0a\u5199\u4e86 version<\/td>\n<td>\u53bb\u6389 version&#xff0c;\u6539\u7528 ?ref&#061; \u9501 tag<\/td>\n<\/tr>\n<tr>\n<td>\u62bd\u6a21\u5757\u540e plan \u8981\u9500\u6bc1\u91cd\u5efa<\/td>\n<td>\u8d44\u6e90\u5730\u5740\u6ca1\u642c<\/td>\n<td>terraform state mv \u5230\u65b0\u5730\u5740<\/td>\n<\/tr>\n<tr>\n<td>\u8f93\u51fa\u663e\u793a (sensitive value)<\/td>\n<td>\u8be5\u8f93\u51fa\u6807\u4e86 sensitive<\/td>\n<td>terraform output -raw xxx \u53d6\u539f\u503c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u52a8\u624b\u524d\u8fc7\u4e00\u904d\u6e05\u5355&#xff1a;<\/p>\n<ul>\n<li class=\"task-list-item\"> \u5fc5\u586b\u53d8\u91cf\u90fd\u5199\u4e86 description&#xff0c;\u8c03\u7528\u65b9\u770b\u5f97\u61c2<\/li>\n<li class=\"task-list-item\"> \u540d\u5b57\u7c7b\u53d8\u91cf\u914d\u4e86 validation&#xff0c;\u975e\u6cd5\u503c\u6321\u5728 plan \u4e4b\u524d<\/li>\n<li class=\"task-list-item\"> condition \u91cc\u6ca1\u6709 uuid() \/ timestamp() \u8fd9\u7c7b\u975e\u7eaf\u51fd\u6570<\/li>\n<li class=\"task-list-item\"> \u8f93\u51fa\u8986\u76d6\u4e86\u8c03\u7528\u65b9\u8981\u7528\u7684\u5b57\u6bb5&#xff0c;\u654f\u611f\u503c\u6807\u4e86 sensitive<\/li>\n<li class=\"task-list-item\"> \u62bd\u5b8c\u6a21\u5757\u6267\u884c\u4e86 state mv&#xff0c;plan \u4e3a No changes<\/li>\n<li class=\"task-list-item\"> \u6a21\u5757\u5185\u6ca1\u6709\u6b8b\u7559 provider \u5757<\/li>\n<\/ul>\n<h3>7. \u53c2\u8003<\/h3>\n<ul>\n<li>Terraform \u6587\u6863 \u00b7 \u6a21\u5757\u7ed3\u6784&#xff1a;https:\/\/developer.hashicorp.com\/terraform\/language\/modules\/develop\/structure<\/li>\n<li>Terraform \u6587\u6863 \u00b7 \u8f93\u5165\u53d8\u91cf&#xff1a;https:\/\/developer.hashicorp.com\/terraform\/language\/values\/variables<\/li>\n<li>Terraform \u6587\u6863 \u00b7 \u8f93\u51fa\u503c&#xff1a;https:\/\/developer.hashicorp.com\/terraform\/language\/values\/outputs<\/li>\n<li>Terraform \u6587\u6863 \u00b7 \u81ea\u5b9a\u4e49\u6821\u9a8c&#xff1a;https:\/\/developer.hashicorp.com\/terraform\/language\/expressions\/custom-validations<\/li>\n<li>Terraform \u6587\u6863 \u00b7 \u6a21\u5757\u6e90&#xff1a;https:\/\/developer.hashicorp.com\/terraform\/language\/modules\/sources<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u4e09\u5957\u73af\u5883\u7684 S3 \u914d\u7f6e\u5404\u6284\u4e86\u4e00\u4efd&#xff0c;\u6539\u4e2a\u53c2\u6570\u8981\u52a8\u4e09\u4e2a\u76ee\u5f55\u3002\u6709\u4e00\u56de\u6f0f\u6539&#xff0c;plan \u91cc dev \u7684 bucket \u524d\u7f00\u8ddf prod \u649e\u4e86\u3002<br \/>\n&#x1f4a1; \u793a\u4f8b\u57fa\u4e8e Terraform 1.x  AWS provider 5.x&#xff0c;\u6a21\u5757\u653e\u5728 .\/modules\/s3_bucket&#xff0c;\u672c\u5730\u8def\u5f84\u5f15\u7528&#xff0c;\u4e0d\u63a8 registry \u4e5f\u80fd\u8dd1\u3002<br \/>\n1. \u6a21\u5757\u7ed3\u6784\u4e0e\u8c03\u7528\u5173\u7cfb<br \/>\n1.1 \u4e09\u6bb5\u6587\u4ef6\u7ed3\u6784<br \/>\n\u4e00\u4e2a\u76ee\u5f55\u5c31\u662f\u4e00\u4e2a\u6a21\u5757&amp;#xf<\/p>\n","protected":false},"author":2,"featured_media":116511,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[11820,10873,763,97],"topic":[],"class_list":["post-116515","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-atomgit","tag-terraform","tag-763","tag-97"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u7f16\u5199\u7b2c\u4e00\u4e2a Terraform Module\uff1a\u7ed3\u6784\u3001\u8f93\u5165\u8f93\u51fa\u4e0e\u53d8\u91cf\u6821\u9a8c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/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.wsisp.com\/helps\/116515.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u7f16\u5199\u7b2c\u4e00\u4e2a Terraform Module\uff1a\u7ed3\u6784\u3001\u8f93\u5165\u8f93\u51fa\u4e0e\u53d8\u91cf\u6821\u9a8c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e09\u5957\u73af\u5883\u7684 S3 \u914d\u7f6e\u5404\u6284\u4e86\u4e00\u4efd&#xff0c;\u6539\u4e2a\u53c2\u6570\u8981\u52a8\u4e09\u4e2a\u76ee\u5f55\u3002\u6709\u4e00\u56de\u6f0f\u6539&#xff0c;plan \u91cc dev \u7684 bucket \u524d\u7f00\u8ddf prod \u649e\u4e86\u3002 &#x1f4a1; \u793a\u4f8b\u57fa\u4e8e Terraform 1.x AWS provider 5.x&#xff0c;\u6a21\u5757\u653e\u5728 .\/modules\/s3_bucket&#xff0c;\u672c\u5730\u8def\u5f84\u5f15\u7528&#xff0c;\u4e0d\u63a8 registry \u4e5f\u80fd\u8dd1\u3002 1. \u6a21\u5757\u7ed3\u6784\u4e0e\u8c03\u7528\u5173\u7cfb 1.1 \u4e09\u6bb5\u6587\u4ef6\u7ed3\u6784 \u4e00\u4e2a\u76ee\u5f55\u5c31\u662f\u4e00\u4e2a\u6a21\u5757&amp;#xf\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/116515.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-21T09:24:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261021092450-6ad884e2d9391.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/116515.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/116515.html\",\"name\":\"\u7f16\u5199\u7b2c\u4e00\u4e2a Terraform Module\uff1a\u7ed3\u6784\u3001\u8f93\u5165\u8f93\u51fa\u4e0e\u53d8\u91cf\u6821\u9a8c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-21T09:24:54+00:00\",\"dateModified\":\"2026-10-21T09:24:54+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/116515.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/116515.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/116515.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u7f16\u5199\u7b2c\u4e00\u4e2a Terraform Module\uff1a\u7ed3\u6784\u3001\u8f93\u5165\u8f93\u51fa\u4e0e\u53d8\u91cf\u6821\u9a8c\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u7f16\u5199\u7b2c\u4e00\u4e2a Terraform Module\uff1a\u7ed3\u6784\u3001\u8f93\u5165\u8f93\u51fa\u4e0e\u53d8\u91cf\u6821\u9a8c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","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.wsisp.com\/helps\/116515.html","og_locale":"zh_CN","og_type":"article","og_title":"\u7f16\u5199\u7b2c\u4e00\u4e2a Terraform Module\uff1a\u7ed3\u6784\u3001\u8f93\u5165\u8f93\u51fa\u4e0e\u53d8\u91cf\u6821\u9a8c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e09\u5957\u73af\u5883\u7684 S3 \u914d\u7f6e\u5404\u6284\u4e86\u4e00\u4efd&#xff0c;\u6539\u4e2a\u53c2\u6570\u8981\u52a8\u4e09\u4e2a\u76ee\u5f55\u3002\u6709\u4e00\u56de\u6f0f\u6539&#xff0c;plan \u91cc dev \u7684 bucket \u524d\u7f00\u8ddf prod \u649e\u4e86\u3002 &#x1f4a1; \u793a\u4f8b\u57fa\u4e8e Terraform 1.x AWS provider 5.x&#xff0c;\u6a21\u5757\u653e\u5728 .\/modules\/s3_bucket&#xff0c;\u672c\u5730\u8def\u5f84\u5f15\u7528&#xff0c;\u4e0d\u63a8 registry \u4e5f\u80fd\u8dd1\u3002 1. \u6a21\u5757\u7ed3\u6784\u4e0e\u8c03\u7528\u5173\u7cfb 1.1 \u4e09\u6bb5\u6587\u4ef6\u7ed3\u6784 \u4e00\u4e2a\u76ee\u5f55\u5c31\u662f\u4e00\u4e2a\u6a21\u5757&amp;#xf","og_url":"https:\/\/www.wsisp.com\/helps\/116515.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-21T09:24:54+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261021092450-6ad884e2d9391.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/116515.html","url":"https:\/\/www.wsisp.com\/helps\/116515.html","name":"\u7f16\u5199\u7b2c\u4e00\u4e2a Terraform Module\uff1a\u7ed3\u6784\u3001\u8f93\u5165\u8f93\u51fa\u4e0e\u53d8\u91cf\u6821\u9a8c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-21T09:24:54+00:00","dateModified":"2026-10-21T09:24:54+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/116515.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/116515.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/116515.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u7f16\u5199\u7b2c\u4e00\u4e2a Terraform Module\uff1a\u7ed3\u6784\u3001\u8f93\u5165\u8f93\u51fa\u4e0e\u53d8\u91cf\u6821\u9a8c"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/116515","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=116515"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/116515\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/116511"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=116515"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=116515"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=116515"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=116515"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}