Question 1 · choose 1
An application on an instance reads a bucket at startup through the instance's IAM role. The role policy that grants bucket access is a separate resource, and nothing in the instance's arguments refers to it. Sometimes the app starts before the policy exists. What fixes the order?
- AMove the policy block above the instance block in the same file
- BAdd lifecycle { ignore_changes = all } to the instance
- CAdd depends_on = [aws_iam_role_policy.bucket_read] to the instance
- DRun the apply with -parallelism=1 so resources are created one at a time
Show the answer and why
AMove the policy block above the instance block in the same file
Incorrect
Block order does not affect the dependency graph.
BAdd lifecycle { ignore_changes = all } to the instance
Incorrect
ignore_changes stops updates to attributes; it does not order creation.
CAdd depends_on = [aws_iam_role_policy.bucket_read] to the instance
Correct
depends_on handles hidden dependencies that Terraform cannot infer, when a resource relies on another's behavior without referencing its data.
DRun the apply with -parallelism=1 so resources are created one at a time
Incorrect
Lower parallelism does not guarantee the policy comes first.
References create dependencies automatically; depends_on is for the ones Terraform cannot see.
HashiCorp documentation