Terraform : 运行 terraform apply/plan 时指定工作目录

Yay*_*aya 7 amazon-web-services terraform

在运行 terraform apply 或 terraform plan 时,有没有办法(或解决方法)指定工作目录?例如 :

terraform apply working_dir/vpc
terraform apply working_dir/dns
terraform apply working_dir/postgres
terraform apply working_dir/service-a
terraform apply working_dir/service-b
Run Code Online (Sandbox Code Playgroud)

我知道有一个 target 选项,我们可以在其中指定target的资源。但在这里我需要一个文件夹来进行更多的抽象。最终目标是能够设置运行以下命令的基础设施:

make vpc
make dns
make postgres
make service-a
make service-b
Run Code Online (Sandbox Code Playgroud)

log*_*kai 6

您可以在发出apply命令时指定计划或目录。您的示例是有效的应用命令。

用法:terraform apply [options] [dir-or-plan]


Mar*_*cin 5

现在,您还可以使用全局选项-chdir

chdir 选项指示 Terraform在运行给定子命令之前将其工作目录更改为给定目录。这意味着 Terraform 通常在当前工作目录中读取或写入的任何文件都将改为在给定目录中读取或写入。

例如:

terraform -chdir=environments/production apply
Run Code Online (Sandbox Code Playgroud)