terraform validate 仅检查语法而不检查其他内容

发布于 2025-01-09 17:42:43 字数 728 浏览 1 评论 0原文

目前我在 shell 命令下运行

@if [ -x "$$(command -v terraform)" ]; then \
    echo "==> Checking terraform formatting of files"; \
    (terraform validate ./test && echo "Terraform format check passed successfully") \
    || (echo "validation failed" && exit 1); \
else \
    echo "No terraform command found"; \
    exit 1; \
fi

,我不想初始化后端,但似乎确实如此,而且我还看到

?   on test/policy.tf line 320:
?  320: module "service_admin_policy" {
?
? This module is not yet installed. Run "terraform init" to install all
? modules required by this configuration.

terraform version = 1.1.6

使用 terraform 验证时出现错误,我只想检查目录中的 .tf 文件在语法上是否正确,例如缺少大括号和逗号之类的东西。 有关如何忽略这些错误的任何帮助。

currently I am running below shell command

@if [ -x "$(command -v terraform)" ]; then \
    echo "==> Checking terraform formatting of files"; \
    (terraform validate ./test && echo "Terraform format check passed successfully") \
    || (echo "validation failed" && exit 1); \
else \
    echo "No terraform command found"; \
    exit 1; \
fi

here I dont want to initialize the backend but it seems it does that and I also see error as

?   on test/policy.tf line 320:
?  320: module "service_admin_policy" {
?
? This module is not yet installed. Run "terraform init" to install all
? modules required by this configuration.

terraform version = 1.1.6

using terraform validate I just want to check if the .tf files in a directory are just syntactically correct like braces missing and comma kind of stuff.
any help on how I can ignore these errors.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌能量女王 2025-01-16 17:42:43

验证的工作原理是检查代码的健全性,包括加载模块并确保变量命名正确。

如果您只需要本地文件的基本语法,请考虑使用 terraform fmt -write=false。如果格式化程序无法解析该文件,则会抛出错误。

Validate works at the level of checking your code for soundness, including loading modules and ensuring that variables are correctly named.

If you only want basic syntax of a local file, consider using terraform fmt -write=false. If the formatter is unable to parse the file, it will throw an error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文