You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have read and agree to the project's Code of Conduct.
Provider Version
latest
Motivation
The examples do not follow the common terraform naming standards. There is use of an imperative style, as opposed to declarative. The specific naming I found unusual was the use of "create_" as the start of a resource name. I asked chatGPT what it thought of that convention.
Question
Reviewing terraform code, I noticed the resources are named starting with "create_". ex. resource "tanzu-mission-control_git_repository" "create_cluster_git_repository" {
Is this a common practice? I would have thought the name would just be "cluster_git_repository"
Answer
Naming conventions in Terraform are critical for readability, maintainability, and collaboration, but there is no strict requirement on how resource names should be structured. Using create_ as a prefix in resource names is not a common practice and might lead to confusion, as Terraform resources typically represent a declarative state rather than an imperative action.
Common Practices in Terraform Resource Naming:
Descriptive and Contextual Names:
Resource names should describe the entity being managed and its context in the infrastructure.
Example:
resource "tanzu-mission-control_git_repository" "cluster_git_repository" {
# Configuration here
}
Avoiding Action-Oriented Prefixes:
Prefixes like create_ or delete_ imply imperative operations, which can be misleading. Terraform's declarative model means it reconciles the desired state, not directly issuing "create" or "delete" commands.
Using Resource Purpose:
Include the purpose or function in the name for clarity.
Example for multiple repositories:
resource "tanzu-mission-control_git_repository" "prod_git_repository" {
# Configuration here
}
resource "tanzu-mission-control_git_repository" "dev_git_repository" {
# Configuration here
}
Provider-Specific Guidance:
Some providers may suggest naming patterns. For example, AWS-related resources often follow names like vpc_main, s3_bucket_logs, etc.
Potential Issues with create_ Prefix:
Redundancy: The action (create) is implicit in Terraform since all resources are created unless explicitly destroyed.
Misleading Semantics: It suggests an imperative process rather than describing the resource's role.
Consistency: May lead to inconsistent naming if not applied across all resources.
Recommended Naming Pattern:
Instead of create_cluster_git_repository, prefer:
Sources and References:
Terraform Documentation on Resources
Best Practices for Naming in Infrastructure as Code
Let me know if you'd like help updating the resource names in your codebase!
Suggestion
Refactor the terraform to use naming best practices.
The text was updated successfully, but these errors were encountered:
Code of Conduct
Provider Version
latest
Motivation
The examples do not follow the common terraform naming standards. There is use of an imperative style, as opposed to declarative. The specific naming I found unusual was the use of "create_" as the start of a resource name. I asked chatGPT what it thought of that convention.
Question
Reviewing terraform code, I noticed the resources are named starting with "create_". ex. resource "tanzu-mission-control_git_repository" "create_cluster_git_repository" {
Is this a common practice? I would have thought the name would just be "cluster_git_repository"
Answer
Naming conventions in Terraform are critical for readability, maintainability, and collaboration, but there is no strict requirement on how resource names should be structured. Using create_ as a prefix in resource names is not a common practice and might lead to confusion, as Terraform resources typically represent a declarative state rather than an imperative action.
Common Practices in Terraform Resource Naming:
Descriptive and Contextual Names:
Resource names should describe the entity being managed and its context in the infrastructure.
Example:
Avoiding Action-Oriented Prefixes:
Prefixes like create_ or delete_ imply imperative operations, which can be misleading. Terraform's declarative model means it reconciles the desired state, not directly issuing "create" or "delete" commands.
Using Resource Purpose:
Include the purpose or function in the name for clarity.
Example for multiple repositories:
Provider-Specific Guidance:
Some providers may suggest naming patterns. For example, AWS-related resources often follow names like vpc_main, s3_bucket_logs, etc.
Potential Issues with create_ Prefix:
Redundancy: The action (create) is implicit in Terraform since all resources are created unless explicitly destroyed.
Misleading Semantics: It suggests an imperative process rather than describing the resource's role.
Consistency: May lead to inconsistent naming if not applied across all resources.
Recommended Naming Pattern:
Instead of create_cluster_git_repository, prefer:
Sources and References:
Terraform Documentation on Resources
Best Practices for Naming in Infrastructure as Code
Let me know if you'd like help updating the resource names in your codebase!
Suggestion
Refactor the terraform to use naming best practices.
The text was updated successfully, but these errors were encountered: