Data Example
Loading...
Data Example
In this example, we will create a naming convention for data sources in a Terraform codebase. We will use the following naming conventions:
Avoid Repeating Data Type
1data "aws_instance" "web_server" {2 # ...3}1data "aws_instance" "aws_web_server" {2 # ...3}1data "aws_instance" "web_server_instance" {2 # ...3}Use this for Generic Data Sources:
1data "aws_db_instance" "this" {2 # ...3}1data "aws_db_instance" "my_db_instance" {2 # ...3}1data "aws_db_instance" "db_instance" {2 # ...3}Use Descriptive Names
1data "aws_instance" "web_server" {2 # ...3}1data "aws_instance" "database_server" {2 # ...3}1data "aws_instance" "instance" {2 # ...3}1data "aws_instance" "server" {2 # ...3}Use underscores for Multi-word Names
1data "aws_instance" "web_server" {2 # ...3}1data "aws_instance" "web-server" {2 # ...3}1data "aws_instance" "webServer" {2 # ...3}Conclusion
In this example, we have created a naming convention for data sources in a Terraform codebase. By following these conventions, you can make your code more readable and consistent. Remember to avoid repeating data types, use this for generic data sources, use descriptive names, use underscores for multi-word names, and follow the order of data arguments reference. These practices will help you maintain a clean and organized codebase.