Data Naming Conventions
Loading...
Naming Conventions
When naming data in your codebase, it is important to follow a consistent naming convention. This will help you and your team understand the purpose of each data source and make it easier to navigate the codebase.
Avoid Repeating Data Type
When naming data sources, avoid repeating the data type in the name. For example, instead of naming a data source aws_instance, you can simply name it web_server. This makes the code more readable and avoids redundancy.
- ✅
data "aws_instance" "web_server" - ❌
data "aws_instance" "aws_web_server" - ❌
data "aws_instance" "web_server_instance"
Use this for Generic Data Sources:
When naming generic data sources, use this as a if the data source creates a single resource of this type and it is not necessary to give it a specific name.
- ✅
data "aws_db_instance" "this" - ❌
data "aws_db_instance" "my_db_instance" - ❌
data "aws_db_instance" "db_instance"
Use Descriptive Names
Use descriptive names for data sources to make it clear what the data source is used for. For example, instead of naming a data source instance, you can name it web_server_instance.
- ✅
data "aws_instance" "web_server" - ✅
data "aws_instance" "database_server" - ❌
data "aws_instance" "instance" - ❌
data "aws_instance" "server"
Use Singular Nouns
When naming data sources, use singular nouns to make the code more readable. For example, instead of naming a data source web_servers, you can name it web_server.
- ✅
data "aws_instance" "web_server" - ❌
data "aws_instances" "web_servers" - ❌
data "aws_instance" "dbs_servers"
Use Consistent Naming
When naming data sources, use consistent naming conventions across your codebase. This will make it easier to understand the purpose of each data source and avoid confusion.
Use Lowercase Letters
When naming data sources, use lowercase letters to make the code more readable. This will help you and your team quickly identify data sources in the codebase.
- ✅
data "aws_instance" "web_server" - ❌
data "aws_instance" "Web_Server" - ❌
data "aws_instance" "WEB_SERVER"
Use underscores for Multi-word Names
Use underscores to separate words in data source names. This makes the code more readable and consistent.
- ✅
data "aws_instance" "web_server" - ❌
data "aws_instance" "web-server" - ❌
data "aws_instance" "webServer"