github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/website/docs/language/meta-arguments/depends_on.html.md (about) 1 --- 2 layout: "language" 3 page_title: "The depends_on Meta-Argument - Configuration Language" 4 description: "The depends_on meta-argument allows you to handle hidden resource or module dependencies." 5 --- 6 7 # The `depends_on` Meta-Argument 8 9 -> **Version note:** Module support for `depends_on` was added in Terraform 0.13, and 10 previous versions can only use it with resources. 11 12 Use the `depends_on` meta-argument to handle hidden resource or module dependencies that 13 Terraform can't automatically infer. 14 15 Explicitly specifying a dependency is only necessary when a resource or module relies on 16 some other resource's behavior but _doesn't_ access any of that resource's data 17 in its arguments. 18 19 This argument is available in `module` blocks and in all `resource` blocks, 20 regardless of resource type. For example: 21 22 ```hcl 23 resource "aws_iam_role" "example" { 24 name = "example" 25 26 # assume_role_policy is omitted for brevity in this example. See the 27 # documentation for aws_iam_role for a complete example. 28 assume_role_policy = "..." 29 } 30 31 resource "aws_iam_instance_profile" "example" { 32 # Because this expression refers to the role, Terraform can infer 33 # automatically that the role must be created first. 34 role = aws_iam_role.example.name 35 } 36 37 resource "aws_iam_role_policy" "example" { 38 name = "example" 39 role = aws_iam_role.example.name 40 policy = jsonencode({ 41 "Statement" = [{ 42 # This policy allows software running on the EC2 instance to 43 # access the S3 API. 44 "Action" = "s3:*", 45 "Effect" = "Allow", 46 }], 47 }) 48 } 49 50 resource "aws_instance" "example" { 51 ami = "ami-a1b2c3d4" 52 instance_type = "t2.micro" 53 54 # Terraform can infer from this that the instance profile must 55 # be created before the EC2 instance. 56 iam_instance_profile = aws_iam_instance_profile.example 57 58 # However, if software running in this EC2 instance needs access 59 # to the S3 API in order to boot properly, there is also a "hidden" 60 # dependency on the aws_iam_role_policy that Terraform cannot 61 # automatically infer, so it must be declared explicitly: 62 depends_on = [ 63 aws_iam_role_policy.example, 64 ] 65 } 66 ``` 67 68 The `depends_on` meta-argument, if present, must be a list of references 69 to other resources or child modules in the same calling module. 70 Arbitrary expressions are not allowed in the `depends_on` argument value, 71 because its value must be known before Terraform knows resource relationships 72 and thus before it can safely evaluate expressions. 73 74 The `depends_on` argument should be used only as a last resort. When using it, 75 always include a comment explaining why it is being used, to help future 76 maintainers understand the purpose of the additional dependency. 77