Reputation: 1441
This is a generic workflow terraform question (I am a terraform beginner).
I need to create a new aws resource via terraform. The structure I have is
resource "some_aws_resource" "resource_name" {
name = var.resource_name
role_name = var.role_name
another_key = another_value
}
The value another_value
is derived from vars entered by the user through a bash script
find_another_value.sh
for example
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
}
}
}
should return another_value
How do I pass the output another_value
of the null_resource
to the first resource and make sure that the non null resource waits until the null_resource
returns the value?
The find_another_value.sh
script will use the input variables to query aws via the aws cli to find the value it needs to return.
If there is a better/easier way that would also be good to know.
Upvotes: 0
Views: 776
Reputation: 19
For waiting you will use depends_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
}
To extract value from a resource We will write a resource out We will add value Edit the resource then the name and then the line we want its value
output "another_value" {
description = "another_value from null resource find_another_value ."
value = null_resource.find_another_value.provisioner "local-exec"
}
Upvotes: 1