Skip to content

Commit c2afce2

Browse files
nitrocodeostermanmilldr
authored
docs(best-practices): all resource attributes (#750)
Co-authored-by: Erik Osterman (CEO @ Cloud Posse) <[email protected]> Co-authored-by: Dan Miller <[email protected]>
1 parent 5db22ea commit c2afce2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/best-practices/terraform.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,28 @@ We prefer to keep terraform outputs symmetrical as much as possible with the ups
273273

274274
![Terraform outputs should be symmetrical](/assets/terraform-outputs-should-be-symmetrical.png)
275275

276+
### Export all Attributes of a Resource
277+
278+
While it's important to explicitly output the most relevant attributes from a resource, there are cases where exposing the entire resource object is beneficial. By outputting the full resource, you provide downstream modules and users with greater flexibility and easier interoperability—especially when composing infrastructure across multiple modules.
279+
280+
This approach also future-proofs your module. As providers evolve and introduce new attributes, consumers can immediately access those attributes without requiring the module to be updated with new outputs.
281+
282+
```hcl
283+
output "<resource_type>_<resource_name>" {
284+
value = <resource_type>.<resource_name>
285+
description = "All attributes of [`<resource_type>.<resource_name>`](link-to-aws-provider-resource-attribute-docs)"
286+
}
287+
```
288+
289+
For example, if the module contained the resource address `aws_ec2_instance.default` then the output would be defined like this.
290+
291+
```hcl
292+
output "aws_ec2_instance_default" {
293+
value = aws_ec2_instance.default
294+
description = "All attributes of [`aws_ec2_instance.default`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance#attribute-reference)"
295+
}
296+
```
297+
276298
## Language
277299

278300
### Use indented `HEREDOC` syntax

0 commit comments

Comments
 (0)