TA-002-P · Question #321
From the code below, identify the implicit dependency:
The correct answer is C. The EC2 instance labeled web_server. An implicit dependency occurs when one Terraform resource references an attribute of another, such as when an Elastic IP or a security group rule references the ID of an EC2 instance labeled web_server.
Question
From the code below, identify the implicit dependency:
Options
- AThe EIP with an id of ami-2757f631
- BThe AMI used for the EC2 instance
- CThe EC2 instance labeled web_server
- DThe S3 bucket labeled company_data
How the community answered
(25 responses)- A4% (1)
- B4% (1)
- C88% (22)
- D4% (1)
Why each option
An implicit dependency occurs when one Terraform resource references an attribute of another, such as when an Elastic IP or a security group rule references the ID of an EC2 instance labeled `web_server`.
Elastic IP addresses do not use Amazon Machine Image (AMI) IDs; AMI IDs are associated with EC2 instances to define their operating system and initial software.
While an EC2 instance depends on an AMI for its creation, the AMI itself is not typically the *dependent* resource in an implicit dependency chain related to the EC2 instance's existence; rather, the EC2 instance *uses* the AMI.
The EC2 instance labeled `web_server` would be an implicit dependency if another resource, such as an `aws_eip` or `aws_security_group_rule`, contained an expression referencing an attribute of `aws_instance.web_server`, thereby requiring the instance to be created first.
An S3 bucket would only be an implicit dependency for an EC2 instance in very specific and less common scenarios, such as if the instance's user data fetched content from the bucket, and even then, the dependency is usually reversed or more complex.
Concept tested: Terraform implicit dependencies identification
Source: https://developer.hashicorp.com/terraform/language/syntax/dependencies
Topics
Community Discussion
No community discussion yet for this question.