繁体   English   中英

我们可以在 Azure DevOps 发布管道中运行 terraform 导入吗

[英]Can we run terraform import in Azure DevOps release pipeline

我已经手动创建了 Azure virtual.networks 和资源组。 我将使用 Terraform 创建一个 VM,并通过 Azure DevOps 部署它。我的 Terraform state 文件驻留在 Azure 存储帐户中。 目前,它是空白的。 我需要将现有的 virtual.network 和资源组导入到 state 文件中。 我能够使用发布管道执行 Terraform 初始化、计划和应用,但我无法在发布管道中找到导入 terraform 的任务。我可以使用我的 VSCode 导入,但我需要使用 Azure DevOps 执行此导入.

有人可以让我知道这是否可能吗? 提前致谢

Azure Terrafy 是解决这个问题的另一种方法。 您将针对现有基础设施运行它,它会为您生成 Terraform 并将其添加到 state 文件中。

https://github.com/Azure/aztfy

它确实有一些限制,在这里讨论:

https://techcommunity.microsoft.com/t5/itops-talk-blog/azure-terrafy-import-your-existing-azure-infrastructure-into/ba-p/3357653

此 Azure 管道扩展声称支持 Terraform 导入: Terraform 任务

我们可以在 Azure DevOps 发布管道中运行 terraform 导入吗

恐怕目前没有这样的开箱即用任务来运行 terraform 导入在 Azure DevOps 发布管道中。

开发者社区有用户的声音:

支持 Terraform 导入

It would be great if we are creating infrastructure via the Azure Portal to then be able to bring those resources into Terraform state management via a simple Terraform import task rather than attempting to call this in a PowerShell/Bash/Azure CLI script. 目前Terraform任务支持plan、init、apply等,但不支持import

您可以对此反馈进行投票并添加您的评论。

您可以...或者您可以设置本地 terraform 以读取 AZ 中的 state,然后在本地导入,保存到 AZ,这样就完成了。

类似的东西:

terrafrom init -backend-config=storage_account_name=<storageaccountname> -backend-config=container_name=<container_name> -backend-config="key=statefile.terraform-state" -backend-config=resource_group_name=<rg-name> -backend-config=subscription_id=<subid> -backend-config=tenant_id=<tenantid>

这样:

terrafrom init -backend-config=storage_account_name=terraform_state -backend-config=container_name=dev -backend-config="key=dev-app-uk.terraform-state" -backend-config=resource_group_name=terraform-state -backend-config=subscription_id=0000-0000-0000-0000 -backend-config=tenant_id=9999-9999-9999-9999

然后像这样导入你的资源,它会保存到 AZ all imported

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM