Scenario:
In resource02 I need to get the “for_each” from the result of resource01 to fill in the fields (name and job_name).
But in resource02 I will also need a “for_each” or something similar to fill the “schedule” field with the value that is in the tfvars variable (aws_job_cron).
However, it is only possible to perform 1 for_each per block, this is where I am, that is, in 1 precise resource:
Get the result of a previous block that was created with for_each
So am I correct in thinking that you are wanting to end up with three instances of the aws_glue_job resource and nine instances of the aws_glue_trigger resource?
In resource02, in the field (job_name = each.value.name) I will use the result of resource01.
and in the field (var.aws_schedule) within the same resource02 I will also need a for_each for the aws_job_cron variable.
Since I can’t perform 2 for_each on the same block, this is where I’m struggling.
SCENARIO:
1 - resource01 - Creation of 3 aws_glue_job. I’m creating using for_each .
2 - resource02 - Creation of 3 aws_glue_trigger.
I’m reading via for_each the previous block aws_glue_job.glue-job to fetch the creation result. Because I will need to fill in the value in the field (job_name = each.value.name).
In addition to this for_each from the previous block, I also need to perform a new for_each for the field (schedule = var.aws_schedule).
Because each aws_glue_job will have an aws_glue_trigger attached and with a different value for_each.
The schedule attribute in the aws_glue_trigger resource accepts a string, so I’m not really sure what you are wanting. Which of the three values from var.aws_job_cron should it be using?
Step 1:
This aws_glue_trigger block will create a schedule in each previously created Glue Job.
But for this to happen I have to get the result of the aws_glue_job block and fill it in the field:
actions {
job_name = each.value.name
Step 2:
Each schedule of each Job will have a specific time, example schedule with the name Job01 will have the time *"0 14.22 * * ? ", name Job02 will have the time *"0 18.2 * * ? " and the name Job03 will have the *"0 6 * * ? ".
Final: The problem would be in the "aws_glue_trigger" block because;
In the “job_name” parameter: I bring the result of a for_each from another block, at this point it’s ok.
In the “schedule” parameter: Currently it is as a string, but I would need to read a list and start creating it according to the name or by the order of creation, I would use another for_each for the “schedule” line, but it is not possible