xworkspace-console/scripts/render_backend_tf.py
Haitao Pan 9b3687e189 fix(ci): 消除 workflow 所有 heredoc,改为外置脚本调用
- 删除 Configure remote backend 步骤的 shell heredoc(导致 YAML L191 语法错误)
- 新增 scripts/render_backend_tf.py 外置脚本,接受 TF_STATE_ENDPOINT env 渲染 backend.tf
- provision job 新增 Checkout xworkspace-console 步骤,确保 scripts/ 在 runner 可用
- 新增 CLAUDE.md,明确禁止 workflow 内嵌 heredoc(shell/python),要求外置脚本

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-25 11:48:47 +08:00

39 lines
995 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
渲染 Terraform S3 backend 配置文件backend.tf
用法:
TF_STATE_ENDPOINT=https://... python3 render_backend_tf.py [output_path]
默认输出到当前目录的 backend.tfterraform init 的 working-directory 里执行)。
"""
import os
import sys
endpoint = os.environ.get("TF_STATE_ENDPOINT", "")
if not endpoint:
print("ERROR: TF_STATE_ENDPOINT is not set", file=sys.stderr)
sys.exit(1)
output = sys.argv[1] if len(sys.argv) > 1 else "backend.tf"
content = f"""\
terraform {{
backend "s3" {{
endpoints = {{ s3 = "{endpoint}" }}
skip_credentials_validation = true
skip_region_validation = true
skip_requesting_account_id = true
skip_metadata_api_check = true
skip_s3_checksum = true
use_path_style = true
}}
}}
"""
with open(output, "w") as f:
f.write(content)
print(f"backend.tf written to {output}")
print(f" endpoint = {endpoint[:40]}...")