这是一个通用的工作流地形问题(我是地形初学者(。
我需要通过地形创建一个新的aws资源。我的结构是
resource "some_aws_resource" "resource_name" {
name = var.resource_name
role_name = var.role_name
another_key = another_value
}
值another_value
源自用户通过bash脚本输入的变量find_another_value.sh
,例如
resource "null_resource" "find_another_value" {
provisioner "local-exec" {
command = "shell_scripts/find_another_value.sh"
interpreter = ["/bin/bash"]
working_dir = path.module
environment = {
DAR = var.aws_dar
RAD = var.aws_rad
}
}
}
应返回another_value
如何将null_resource
的输出another_value
传递给第一个资源,并确保非空资源等待null_resource
返回值?
find_another_value.sh
脚本将使用输入变量通过aws-cli查询aws,以找到需要返回的值。
如果有更好/更简单的方法,那也很好知道。
对于等待,您将使用dependens_on=[]
resource "some_aws_resource" "resource_name" {
depends_on =[null_resource.find_another_value]
name = var.resource_name
role_name = var.role_name
another_key = another_value.value
}
从资源中提取价值我们将编写一个资源我们将增加价值编辑资源,然后是名称,然后是我们想要的行的值
output "another_value" {
description = "another_value from null resource find_another_value ."
value = null_resource.find_another_value.provisioner "local-exec"
}