Skip to content

Commit 32ba910

Browse files
authored
doc: add some notes about coding conventions (#146)
1 parent d5400b0 commit 32ba910

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

.github/CONTRIBUTING.md

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Please note we have a code of conduct, please follow it in all your interactions
1818
- [Base project name](#base-project-name)
1919
- [Unique prefix of resource names](#unique-prefix-of-resource-names)
2020
- [Separators](#separators)
21-
- [Depends_on](#depends_on)
21+
- [Resource and Data Source Conventions](#resource-and-data-source-conventions)
2222
- [Resource names](#resource-names)
2323
- [Variable names](#variable-names)
2424
- [Output names](#output-names)
@@ -167,16 +167,50 @@ The `local.name` value is then used as a prefix for all `name` and `name_prefix`
167167

168168
> Use `name_prefix` where possible
169169
170-
#### Depends_on
170+
#### Resource and Data Source Conventions
171+
- Include `count` an argument inside resource blocks as the first argument at the top and separate by newline after it:
171172

172-
When you need to add `depends_on` to a resource or a module you should put it at the end of the block with empty line in front of it.
173+
```
174+
resource "aws_instance" "app" {
175+
count = "3"
176+
177+
...
178+
}
179+
```
180+
181+
- Include `tags` the argument, if supported by resource as the last real argument, following by `depends_on` and `lifecycle`, if necessary. All of these should be separated by a single empty line:
182+
183+
```
184+
resource "aws_instance" "app" {
185+
count = "1"
186+
187+
...
188+
189+
tags = {
190+
Name = "..."
191+
}
192+
193+
depends_on = []
194+
195+
lifecycle {}
196+
}
197+
```
198+
199+
- When using condition in `count` argument use boolean value if it makes sense, otherwise use `length` or other interpolation:
173200

174201
```
175-
resource "aws_eks_addon" "coredns" {
202+
resource "aws_instance" "app" {
203+
count = var.run_app_instance ? 1 : 0
204+
176205
...
177-
addon_version = var.addon_coredns_version
206+
}
207+
```
208+
209+
```
210+
resource "aws_route_table_association" "intra" {
211+
count = var.create_vpc && length(var.intra_subnets) > 0 ? length(var.intra_subnets) : 0
178212
179-
depends_on = [module.eks]
213+
...
180214
}
181215
```
182216

@@ -202,6 +236,9 @@ resource "aws_eks_addon" "coredns" {
202236
```
203237

204238
- Nouns must be used for names
239+
- Always use singular nouns for names
240+
- Good: `resource "aws_route_table" "public" {}`
241+
- Bad: `resource "aws_route_table" "publics" {}`
205242

206243
#### Variable names
207244

0 commit comments

Comments
 (0)