在运行Terraform计划之前,如何将.tfvar文件直接下载到AdoAgent Machine中?
我们正在使用Terraform Enterprise Cloud和Azure Devops YML管道进行Azure Infra部署。
需求:我们希望将.tfvar文件与主Terraform文件夹完全分开,并将其保留在不同的存储库中,称为Config Repository。
解决方案1:我们可以在运行以下命令时从配置存储库中转移TFVARS, Terraform Plan -Var -Fil -我们无法实现
Note :由于我们使用的是全局模板,因此这些Terraform命令(例如FMT,验证,计划和应用程序)由模板本身,我们不允许编辑模板。
这是逻辑, 模板仅期望当前目录中的.tfvars文件,然后有一些bash命令将其重命名为.auto.tfvars。 我们知道这些auto.tfvars文件将被Terraform自动识别。
解决方案2:我们期望和努力实施,
默认模板副本需要一些帮助,将所有Terraform文件夹副本副本填充到ADO代理容器。我们希望确保来自配置存储库中的.tfvar文件在代理容器中可用。那么这个解决方案将是好的。
可能是,
我们可以通过编写一些Shell脚本将.TFVARS文件从配置存储库复制到代理容器来实现。但是它必须在Terraform文件夹中。因为仅将Terraform文件夹复制到代理容器中。
或者有什么方法可以将Shell脚本集成到Terraform Configuration 中,可以在运行时间下将TFVARS文件从配置存储库下载到容器中。
任何其他解决方案或方法都将不胜感激。
We are using Terraform Enterprise Cloud and Azure DevOps YML pipelines for Azure infra deployments.
Requirement: We want to separate .tfvar files completely from the main terraform folder and keep them in different Repo called config Repository.
Solution 1: We can refer tfvars from the config repository while running the below command,
terraform plan --var-fil -We cannot implement
Note: Since we are using global templates, these terraform commands like fmt, validate, plan, and apply are managed by the template itself, we are not allowed to edit the template.
Here is the logic,
template expects only .tfvars file in the current directory, then there are some bash commands to rename it to .auto.tfvars.
We know that these auto.tfvars files will be automatically identified by Terraform.
Solution 2: We are expecting and struggling to implement and need some help
By default Template copies all terraform folders to ADO Agent Container. we want to make sure the .tfvar file from the Config repository is available in the agent container. Then this solution will be good.
May be,
We can achieve it by Copying the .tfvars file from the config repository to the agent container by writing some shell script. but it has to be inside the terraform folder. because only terraform folder will be copied to the agent container.
Or is there any way that we can integrate a shell script to terraform configuration which can download tfvars file from config repository to container in run time.
Any other solution or approach will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了确保在运行时可用配置回购文件可用,您可以在Release Pipeline中添加第二个工件。这将允许您使用适当的文件修改VAR参数。
https://learn.microsoft.com/en-us/azure/devops/pipelines/release/release/artifacts?view=Azure-devops
To make sure the config repo files are available during runtime you can add a second artifact to the release pipeline. This will allow you to modify your var argument with the appropriate file.
https://learn.microsoft.com/en-us/azure/devops/pipelines/release/artifacts?view=azure-devops
一种方法是将您的TFVAR文件存储为安全文件,然后在管道中添加一个步骤以下载它,但是,如果您使用Terraform Enterprise,是否有任何特殊原因不使用Terraform Workspace变量?
One approach is to have your tfvars file stored as a secure file, then just add a step in your pipeline to download it, however, if you're using Terraform Enterprise, is there any particular reason to not use Terraform workspace variables?