Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

HashiCorp Terraform-Associate-004 Exam - Topic 7 Question 6 Discussion

Actual exam question for HashiCorp's Terraform-Associate-004 exam
Question #: 6
Topic #: 7
[All Terraform-Associate-004 Questions]

Exhibit:

resource "azurerm_linux_web_app" "app" {

name = "example-app"

resource_group_name = azurerm_resource_group.rg.name

location = azurerm_resource_group.rg.location

service_plan_id = azurerm_service_plan.plan.id

identity {

type = "UserAssigned"

identity_ids = [azurerm_user_assigned_identity.app.id]

}

}

resource "azurerm_role_assignment" "kv_access" {

scope = azurerm_key_vault.kv.id

role_definition_name = "Key Vault Secrets User"

principal_id = azurerm_user_assigned_identity.app.principal_id

}

Two resource blocks are shown: azurerm_linux_web_app and azurerm_role_assignment. When provisioned, the web app will use the role assignment during creation, so the role assignment must be created first. How do you ensure the azurerm_role_assignment resource is created first?

Show Suggested Answer Hide Answer
Suggested Answer: A

Rationale for Correct Answer: depends_on explicitly adds a dependency edge in Terraform's graph. By adding depends_on = [azurerm_role_assignment.kv_access] to the web app resource, you force Terraform to create the role assignment first, even if Terraform can't infer the dependency from attribute references.

Analysis of Incorrect Options (Distractors):

B: create_before_destroy is a lifecycle setting relevant to replacement behavior, not initial create ordering between independent resources.

C: File/block order does not control creation order; Terraform uses its dependency graph.

D: count controls quantity, not ordering.

Key Concept: Dependency graph and explicit dependencies via depends_on.


====================

Contribute your Thoughts:

0/2000 characters
Madalyn
3 days ago
B) doesn't really make sense here, right?
upvoted 0 times
...
Leonida
8 days ago
I think C) is a bit risky, order can be tricky.
upvoted 0 times
...
Corrie
13 days ago
A) is the way to go, definitely needs depends_on.
upvoted 0 times
...
Andra
19 days ago
I don't recall using count for this kind of dependency issue. Seems like it wouldn't help with the order of creation.
upvoted 0 times
...
Kayleigh
24 days ago
I feel like the create_before_destroy option is more about resource replacement than creation order. Not sure if it applies here.
upvoted 0 times
...
Soledad
29 days ago
I'm not entirely sure, but I remember something about resource dependencies. Could changing the order of the blocks work?
upvoted 0 times
...
Rene
1 month ago
I think we might need to use the depends_on argument to control the creation order. That sounds familiar from our Terraform practice.
upvoted 0 times
...

Save Cancel