In a child Terraform module that provisions an AWS instance named main, which is the correct way to define an output for the instance's IP address to the root module?

Prepare for the HashiCorp Terraform Associate Exam. Utilize flashcards and multiple-choice questions with detailed hints and explanations. Boost your confidence and be ready for success!

Multiple Choice

In a child Terraform module that provisions an AWS instance named main, which is the correct way to define an output for the instance's IP address to the root module?

Explanation:
Outputs in a child module are how you pass values up to the root module. To give the root module the EC2 instance’s address, expose the instance’s public IP as an output. The public_ip attribute contains the address reachable over the internet, which is typically what you want to share with or reference from the root module. Using the private_ip would give an internal address, not suitable for external access, and the id is just a resource identifier, not an address. The output name can be any valid string, but naming it something intuitive like ip and setting its value to aws_instance.main.public_ip makes the purpose clear and aligns with how the root module will read it. In the root module, you would access this as the module’s ip output.

Outputs in a child module are how you pass values up to the root module. To give the root module the EC2 instance’s address, expose the instance’s public IP as an output. The public_ip attribute contains the address reachable over the internet, which is typically what you want to share with or reference from the root module. Using the private_ip would give an internal address, not suitable for external access, and the id is just a resource identifier, not an address. The output name can be any valid string, but naming it something intuitive like ip and setting its value to aws_instance.main.public_ip makes the purpose clear and aligns with how the root module will read it. In the root module, you would access this as the module’s ip output.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy