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
* Adds Renovate configuration (along with documentation)
* Adds `terraform-docs` along with corresponding tools
* Adds example of using TF workspaces
Also let's come up with the new name for this template repo, and I'll
adjust accordingly in the other dependent repos.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added configuration files for automated dependency updates and
documentation generation tools.
* Introduced environment-specific variable files for development and
production.
* Added a new input variable and output for the template root module to
enhance customization and visibility.
* **Improvements**
* Updated documentation for improved clarity, structure, and actionable
guidance.
* Enhanced module documentation with clearer requirements, usage
instructions, and example commands.
* **Updates**
* Upgraded versions of required tools, linters, and providers for better
compatibility and security.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Copy file name to clipboardExpand all lines: README.md
+16-29Lines changed: 16 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,33 +1,18 @@
1
-
# example-tf
1
+
# infra-monorepo-template
2
2
3
3
This repository serves as an example and template for how Masterpoint thinks about organizing a vanilla Terraform or OpenTofu (from now on referred to as "TF") monorepo with root modules, child modules, and accompanying tooling.
4
4
5
5
This includes example configurations and recommendations around the following topics:
6
6
7
-
<!-- TODO: Link to what Multi-instance root modules are once https://github.com/masterpointio/masterpoint.io/pull/49 ships -->
8
-
9
-
1. Example organizational structure for an IaC Monorepo (Multi-instance Root Modules + Child Modules)
7
+
1. Example organizational structure for an IaC Monorepo ([Multi-instance Root Modules](https://masterpoint.io/blog/terraform-opentofu-terminology-breakdown/#multi-instance-root-modules) + Child Modules)
10
8
1. Root module example is provided in the [root-modules/template-root-module](./root-modules/template-root-module/) directory.
11
9
2. Child module example is provided in the [child-modules/random-pet](./child-modules/random-pet/) directory
12
10
2.[Recommendations for module file structure](#structure) with [file-by-file guidance](#file-by-file-guidance)
13
11
3.[Recommendations for version pinning TF + Providers](#versioning-tf-and-providers)
14
-
4.[Managing which TF binary is used per project](#managing-which-tf-binary-is-used-per-project)
12
+
4.[Managing which TF binary is used per project using Aqua](#managing-which-tf-binary-is-used-per-project-using-aqua)
15
13
5.[Guidance on linting + CI for TF](#tf-linting--ci)
1. Example Native TF Tests with accompanying GitHub Action workflow for running tests
20
-
-->
21
-
22
-
## Recommendations (TODO: Discuss)
23
-
24
-
We recommend to include:
25
-
26
-
- Module Description: Provide a concise explanation of what the module does and its intended use cases.
27
-
- Usage Instructions: Include code snippets demonstrating how to call the module from a [root module](https://developer.hashicorp.com/terraform/language/modules#the-root-module).
28
-
- Inputs & Outputs Summary: List the module’s input variables (with defaults and required ones highlighted) and outputs. We recommend using [terraform-docs](https://github.com/terraform-docs/terraform-docs) to keep the summary up-to-date.
29
-
- Prerequisites and Dependencies: Mention any dependencies, required providers, or external resources.
30
-
- Example Configurations: If applicable, include or link to example code snippets or a separate examples/ directory.
14
+
6.[Renovate to Automate Dependency Updates](#renovate-to-automate-dependency-updates)
<!-- TODO: Update to link Child Modules to Terms blog post once live -->
138
-
139
-
Since child-modules are intended to be used many times throughout your or others code, it’s important to make it so that they create as little restrictions on the consuming root module as possible.
122
+
Since [child-modules](https://masterpoint.io/blog/terraform-opentofu-terminology-breakdown/#child-modules) are intended to be used many times throughout your or others code, it’s important to make it so that they create as little restrictions on the consuming root module as possible.
140
123
141
124
This means you should:
142
125
@@ -162,11 +145,9 @@ terraform {
162
145
163
146
In this example, the child module only demands a minimum version (Terraform or OpenTofu 1.3, Random provider 3.0), letting the root module run newer versions as they become available.
164
147
165
-
### Root Modules
166
-
167
-
<!-- TODO: Update to link Root Modules to Terms blog post once live -->
Root modules are intended to be planned and applied and therefore they should be more prescriptive so that they’re called consistently in each case that you instantiate a new root module instance (i.e. create a new state file).
150
+
[Root modules](https://masterpoint.io/blog/terraform-opentofu-terminology-breakdown/#root-modules) are intended to be planned and applied and therefore they should be more prescriptive so that they’re called consistently in each case that you instantiate a new root module instance (i.e. create a new state file).
170
151
171
152
To accomplish that, you should do the following:
172
153
@@ -195,7 +176,7 @@ In this example two things are happening:
195
176
196
177
If you're more willing to use the bleeding edge of providers, you can always use the `~>` operator on the minor version like so `version = "~> 5.81"`. This will enable any new minor version updates and is essentially a shorthand for `>= 5.81.0 && < 6.0`. Be aware that providers do break and this has the possibility to frustrating bugs from providers to affect your project.
197
178
198
-
## Managing which TF binary is used per project
179
+
## Managing which TF binary is used per project using Aqua
199
180
200
181
At Masterpoint, we're big fans of [Aqua](https://aquasecurity.github.io/aqua/) for managing which TF binary is used per project. This allows us to have a single TF binary that is used across our entire project, but still enables us to use root module specific TF versions if needed.
201
182
@@ -229,6 +210,12 @@ As you can see, this is a LOT of checks that trunk is supporting for us and this
229
210
230
211
Check out our [.trunk/trunk.yaml](.trunk/trunk.yaml) file to see how we configure this and [check the trunk Code Quality getting started documentation](https://docs.trunk.io/code-quality) on how you can use this tool for your own project.
231
212
213
+
## Renovate to Automate Dependency Updates
214
+
215
+
We use [Renovate](https://github.com/apps/renovate) to automatically keep our Terraform and OpenTofu dependencies up-to-date through automated pull requests. This includes providers, modules, and even the Terraform/OpenTofu binaries themselves through Aqua.
216
+
217
+
This repository comes with configurations available at [.github/renovate.json5](.github/renovate.json5) that are configured to run on a weekly basis. Visit the [Renovate GitHub App page](https://github.com/apps/renovate) to install the app and configure it to run on your repository. There's also an [example tutorial that Renovate](https://github.com/renovatebot/tutorial) has to guide setting up Renovate.
218
+
232
219
## Frequently Asked Questions
233
220
234
221
### Why do you prefer DRY (Don't Repeat Yourself) Root Modules vs WET (Write Every Time) Root Modules?
Copy file name to clipboardExpand all lines: root-modules/template-root-module/README.md
+34-11Lines changed: 34 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,26 @@
2
2
3
3
This is a template root module that creates a random pet resource. It can be easily copied and updated for other use-cases.
4
4
5
+
## Using `tfvars` with [TF Workspaces](https://masterpoint.io/blog/terraform-opentofu-terminology-breakdown/#tf-cli-workspaces)
6
+
7
+
Terraform/OpenTofu workspaces are used with environment-specific tfvars files for separate TF state files to keep your configuration DRY. This allows you to maintain the same infrastructure code while using different variable values for different environments.
8
+
9
+
```bash
10
+
# Set up a new workspace for `dev` -- only needs to be done once
11
+
tofu workspace new dev
12
+
# Select the workspace, this is how TF knows where the state file is stored
13
+
tofu workspace selectdev
14
+
# Apply the configuration with the corresponding tfvars file
15
+
tofu apply --var-file tfvars/dev.tfvars
16
+
```
17
+
18
+
This approach ensures that:
19
+
20
+
- Your infrastructure code remains consistent across environments
21
+
- Environment-specific configurations are isolated in tfvars files
22
+
- State files are automatically separated by workspace
23
+
- You can easily switch between environments
24
+
5
25
<!-- README TEMPLATE: AFTER READING THE BELOW SECTION, DELETE THE BELOW SECTION AND REPLACE WITH YOUR OWN CONTENT -->
6
26
7
27
## Documentation Recommendations (DO NOT INCLUDE THIS INTO THE REAL README)
@@ -16,33 +36,36 @@ This is a template root module that creates a random pet resource. It can be eas
0 commit comments