TA-002-P · Question #165
1. resource "aws_s3_bucket" "example" { 2. bucket = "my-test-s3-terraform-bucket" 3. ...} resource "aws_iam_role" "test_role" { 4. name = "test_role" 5. ...} Due to the way that the application code i
The correct answer is A. Add explicit dependency using depends_on . This will ensure the correct order of. Since aws_s3_bucket.example and aws_iam_role.test_role have no direct reference between them (e.g., the role does not use the bucket's ARN in its configuration), Terraform cannot detect an implicit dependency. Terraform's implicit dependency only applies when one resource referen
Question
- resource "aws_s3_bucket" "example" { 2. bucket = "my-test-s3-terraform-bucket" 3. ...} resource "aws_iam_role" "test_role" { 4. name = "test_role" 5. ...} Due to the way that the application code is written, the s3 bucket must be created before the test role is created, otherwise there will be a problem. How can you ensure that?
Options
- AAdd explicit dependency using depends_on . This will ensure the correct order of
- BThis will already be taken care of by terraform native implicit dependency. Nothing else
- CThis is not possible to control in terraform . Terraform will take care of it in a native way ,
- DCreate 2 separate terraform config scripts , and run them one by one , 1 for s3 bucket ,
How the community answered
(17 responses)- A76% (13)
- B6% (1)
- C12% (2)
- D6% (1)
Explanation
Since aws_s3_bucket.example and aws_iam_role.test_role have no direct reference between them (e.g., the role does not use the bucket's ARN in its configuration), Terraform cannot detect an implicit dependency. Terraform's implicit dependency only applies when one resource references another's attributes. Because no such reference exists here, you must use depends_on = [aws_s3_bucket.example] inside the IAM role resource to explicitly tell Terraform to create the S3 bucket first.
Topics
Community Discussion
No community discussion yet for this question.