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
- If the return value is a list, it must have a plural name
293
294
- Use description for outputs
294
295
296
+
#### Resources order in .tf files
297
+
298
+
Resources in `.tf` files should be described in the following order:
299
+
1. locals
300
+
2. data
301
+
3. modules
302
+
4. resources
303
+
295
304
### Names of terraform files, directories, and modules
296
305
297
306
#### General configuration files
298
307
299
308
Each terraform module and configuration contains a set of general files ending in `.tf`:
300
309
301
-
-`main.tf` - contains terraform settings if it is the top layer; or the main working code if it is a module
310
+
-`main.tf` - contains terraform settings and resources that can't be somehow grouped if it is the top layer; or the main working code if it is a module
302
311
-`variables.tf` - module input values
303
312
-`outputs.tf` - module output values
304
313
@@ -308,27 +317,27 @@ Besides these, there may be:
308
317
-`providers.tf` - contains settings from terraform providers, e.g. `aws`, `kubernetes`, etc
309
318
-`iam.tf` - IAM configurations of policies, roles, etc
310
319
311
-
This is not a full list; each configuration, module, or layer may need additional files and manifests. The objective is to name them as succinctly and closer in meaning to the content as possible. Do not use prefixes.
320
+
This is not a full list; each configuration, module, or layer may need additional files and manifests. The objective is to name them as succinctly and closer in meaning to the content as possible. Do not use prefixes (for files inside modules).
312
321
313
322
> Terraform itself doesn't care how many files you create. It collects all layer and module manifests into one object, builds dependencies, and executes.
314
323
315
324
#### Specific configuration files
316
325
317
-
These configuration files and manifests include the following: `data "template_file"` or `templatefile ()` template resources, a logical resource group placed in a separate `.tf` file, one or more deployments to k8s using `resource "helm_release"`, module initialization, aws resources that do not require a separate module, etc.
326
+
These configuration files and manifests include a logical resource group placed in a separate `.tf` file.
318
327
319
328
> It should be noted that since some kind of a logical group of resources is being, why not move it all into a separate module. But it turned out that it is easier to manage helm releases, templates for them, and additional resources in separate `.tf` files at the root of a layer. And for many such configurations, when moving to modules, the amount of code can double + what we move to modules is usually what we are going to reuse.
320
329
321
-
Each specific `.tf` file must begin with a prefix indicating the service or provider to which the main resource or group being created belongs, e.g. `aws`. Optionally, the type of service is indicated next, e.g. `iam`. Next comes the name of the main service or resource or resource group declared inside, and after that, an explanatory suffix can optionally be added if there are several such files. All the parts of the name are separated by hyphens`
330
+
Each specific `.tf` file must begin with a prefix indicating the service or provider to which the main resource or group being created belongs, e.g. `aws`. Next comes the name of the main service or resource or resource group declared inside, and after that, an explanatory suffix can optionally be added if there are several such files. All the parts of the name are separated by hyphens`
322
331
323
-
So the formula looks like this: `provider|servicename`-[`optional resource/service type`]-`main resourcename|group-name`-[`optional suffix`].tf
332
+
So the formula looks like this: `provider|servicename`-`main resourcename|group-name`-[`optional suffix`].tf
324
333
325
334
Examples:
326
335
327
-
-`aws-vpc.tf` - terraform manifest describing the creation of a single vpc
336
+
-`aws-vpc.tf` - terraform manifest describing the creation of a group resources for vpc (vpc + vpc endpoints)
328
337
-`aws-vpc-stage.tf` - terraform manifest describing the creation of one of several vpc, for staging
329
-
-`eks-namespaces.tf` - group of namespaces created in the EKS cluster
330
338
-`eks-external-dns.tf` - contains the description of external-dns service deployment to the EKS cluster
331
-
-`aws-ec2-pritunl.tf` - contains the initialization of the module that creates an EC2 instance in AWS with pritunl configured
339
+
340
+
If a resource isn't related to any others (for example: `resource "aws_iam_account_password_policy" "default"`), it can be stored in the `main.tf` file.
332
341
333
342
#### Modules
334
343
@@ -338,24 +347,24 @@ Examples:
338
347
339
348
-`eks-rbac-ci` - module for creating rbac for CI inside the EKS cluster
340
349
-`aws-iam-autoscaler` - module for creating IAM policies for autoscaler
341
-
-`aws-ec2-pritunl` - module for creating pritunl ec2 instance
350
+
-`aws-pritunl` - module for creating pritunl ec2 instance
0 commit comments