Skip to content

Commit 0f2b341

Browse files
IaC-Library-Edify-1: Concepts/Principles files (#2317)
* Update overview.md * Update control-provider-usage.md * Update be-judicious-with-new-features.md * Update quality-in-depth.md * Update docs/2.0/docs/library/concepts/principles/be-judicious-with-new-features.md * Update docs/2.0/docs/library/concepts/principles/be-judicious-with-new-features.md --------- Co-authored-by: Zach Goldberg <[email protected]>
1 parent 34d8334 commit 0f2b341

File tree

4 files changed

+54
-63
lines changed

4 files changed

+54
-63
lines changed
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
# Be Judicious With New Features
1+
# Be Judicious with New Features
22

3-
New OpenTofu features can streamline module authoring and provide more features, but may also require that consumers adopt newer OpenTofu versions. This requirement can pose challenges for organizations that cannot upgrade OpenTofu versions promptly, but want to keep using the latest version of our modules.
3+
Introducing new OpenTofu features can enhance module development and expand functionality. However, adopting these features may require users to upgrade to newer OpenTofu versions. This requirement can create challenges for organizations that are unable to update OpenTofu promptly but still wish to utilize the latest module versions.
44

5-
Modules in the Library often depend on each other. All dependent modules must be updated to require a newer OpenTofu version if a dependent module update requires a newer OpenTofu version.
5+
Modules within the library often have interdependencies. If a module update introduces a dependency on a newer OpenTofu version, **all related modules must be updated** to reflect this version requirement.
66

7-
## How to Decide to Use Newer Features
7+
## Guidelines for adopting new features
88

9-
Consider the following when deciding whether to adopt a new feature:
9+
Evaluate the following factors when determining whether to adopt a new feature:
1010

11-
### Age of Feature
11+
### Feature stability and maturity
1212

13-
Older features are more likely to be compatible with existing consumer environments. While it is unnecessary to avoid newer features altogether, prioritizing well-established features ensures broader compatibility.
13+
Well-established features typically offer greater compatibility with existing module-consumer environments. While incorporating newer features is not discouraged, prioritizing stable and widely adopted features helps maintain consistency and reliability.
1414

15-
### Impact on Module Consumers
15+
### Impact on module users
1616

17-
Requiring upgrades is sometimes justified. For example, the [moved](https://opentofu.org/docs/v1.6/language/modules/develop/refactoring/#moved-block-syntax) block enables seamless upgrades even when resource addresses change. If upgrading provides greater benefits than manual interventions, adopting newer versions can be a practical choice.
17+
Upgrading OpenTofu versions may sometimes be necessary. For instance, the [`moved`](https://opentofu.org/docs/v1.6/language/modules/develop/refactoring/#moved-block-syntax) block allows seamless upgrades even when resource addresses change. When the benefits of upgrading outweigh the effort of manual adjustments, adopting newer versions is recommended.
Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Control Provider Usage
22

3-
There are two main methods for controlling the provider used in OpenTofu/Terraform operations:
3+
There are two primary methods for managing the provider used in OpenTofu/Terraform operations:
44

5-
1. Setting required provider versions.
6-
2. Committing the `.terraform.lock.hcl` file.
5+
1. Specifying required provider versions.
6+
2. Committing the `.terraform.lock.hcl` file to version control.
7+
8+
## Required provider versions
79

8-
## Required Provider Versions
10+
It is advisable to follow the [OpenTofu recommendations](https://opentofu.org/docs/language/providers/requirements/#best-practices-for-provider-versions) for specifying minimum provider versions for any providers used in modules developed as part of the library, ensuring compatibility between installed provider versions and the features in your modules.
911

10-
Generally speaking, follow [OpenTofu recommendations](https://opentofu.org/docs/language/providers/requirements/#best-practices-for-provider-versions) regarding specifying the minimum provider version for any providers used by modules authored as part of the library.
1112

12-
This recommendation is useful guidance for ensuring that the feature set used as part of modules being authored for the library are available in provider versions end users install.
1313

14-
You can do that by using a `required_provider` configuration block like the following:
14+
Specify these versions using a `required_provider` configuration block, as demonstrated below:
1515

1616
```terraform
1717
terraform {
@@ -23,19 +23,17 @@ terraform {
2323
}
2424
}
2525
```
26+
Following guidance against setting maximum provider versions is critical, particularly for modules dependent on other modules.
2627

27-
Note the guidance against setting maximum provider versions. This is especially important for modules that end up as dependencies of other modules.
28+
Since end users install only one provider version, conflicting provider version constraints across module dependencies can make the modules unusable.
2829

29-
Because only one version of a provider is ultimately installed by end users, conflicting provider versions in module dependencies can result in modules being unusable.
30-
31-
An exception to the general rule of avoiding pinning maximum provider versions in modules is to prevent a module from pulling in breaking changes from a future version of a provider.
30+
The exception to this rule is when setting a maximum provider version is necessary to prevent a module from inadvertently adopting breaking changes in future provider versions.
3231

3332
## Committing `.terraform.lock.hcl` File
3433

35-
When running `tofu init` in a directory with `.tf` files, a [`.terraform.lock.hcl`](https://opentofu.org/docs/language/files/dependency-lock) file will be automatically generated if it doesn't exist.
3634

37-
This file shouldn't be committed in module repositories, but should be committed to repositories where those modules are referenced to provision live infrastructure.
35+
When you run `tofu init` in a directory with `.tf` files, a [`.terraform.lock.hcl`](https://opentofu.org/docs/language/files/dependency-lock) file is automatically created if one does not already exist.
3836

39-
When using Terragrunt, note how [Terragrunt handles lock files](https://terragrunt.gruntwork.io/docs/features/lock-file-handling/).
37+
This file should not be committed in module repositories. However, committing it in repositories used to provision live infrastructure is recommended.
4038

41-
Keep this behavior in mind when deciding how to handle `.terraform.lock.hcl` files in modules.
39+
For Terragrunt users, review [Terragrunt’s approach to lock file management](https://terragrunt.gruntwork.io/docs/features/lock-file-handling/) to determine the best way to handle `.terraform.lock.hcl` files in modules.

docs/2.0/docs/library/concepts/principles/overview.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@ import DocCardList from '@theme/DocCardList';
22

33
# Overview
44

5-
Authoring a large library of modules like this requires that certain principles be decided and documented for iteration.
5+
Developing and maintaining a comprehensive library of modules requires clearly defined and documented principles to support ongoing iteration and improvement.
66

7-
These principles help guide decision making when multiple valid approaches exist for tackling a problem.
7+
These principles serve as a framework for decision-making when multiple valid solutions are available for addressing a problem.
88

9-
## High Level Principles
9+
## High-level principles
1010

11-
These are some documented high level principles that should be followed in order to encourage continuous increase in the quality of modules in the library.
11+
The following high-level principles are intended to continuously improve the quality and reliability of the modules within this library.
1212

13-
### If Isn't Tested It's Broken
13+
### If it isn't tested, it's broken
1414

15-
The [Terratest](https://github.com/gruntwork-io/terratest) testing library was created in order to provide a way to efficiently test IAC modules in an easy way.
16-
All modules in the library should have tests associated with them, and whenever possible, should have tests that test all the most important behaviors.
15+
The [Terratest](https://github.com/gruntwork-io/terratest) testing library was developed to provide an efficient and effective method for testing Infrastructure as Code (IaC) modules.
1716

18-
It can be expensive to maintain this many tests, but it is more expensive not to, when dealing with surface area this large.
17+
All modules in this library **must** have associated tests. Wherever feasible, these tests should cover all critical functionalities and behaviors.
18+
19+
While maintaining a comprehensive suite of tests can be resource-intensive, neglecting testing introduces significantly higher risks and costs due to the library's extensive surface area.
20+
21+
As a best practice, it is **more important that a module has basic testing coverage** than that it is tested exhaustively.
1922

20-
As a matter of general practice, it is more important that a module is tested at all than that it is tested comprehensively
2123

2224
<DocCardList />
Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,42 @@
11
# Quality in Depth
22

3-
Similar to the notion of [Defense in Depth](https://en.wikipedia.org/wiki/Defense_in_depth_(computing)), quality in depth is a concept relating to how multiple layers of quality assurance can be used to ensure that modules continuously improve in quality over time.
3+
Inspired by the concept of [Defense in Depth](https://en.wikipedia.org/wiki/Defense_in_depth_(computing)), quality in depth refers to implementing multiple layers of quality assurance to ensure continuous improvement in the quality of modules.
44

5-
## Quality Checks We Use
5+
## Quality checks we use
66

7-
These are some of the standard quality checks that are frequently used to ensure that modules are of high quality.
7+
These are the standard quality checks we employ to maintain high-quality modules.
88

9-
### Automated Testing
9+
### Automated testing
1010

11-
The most important tool in our arsenal for ensuring high quality modules is automated testing. Nothing will catch more bugs than actually attempting to provision infrastructure using a module, verifying that the infrastructure is provisioned as expected, and then tearing it down.
11+
Automated testing is the most effective method for ensuring the quality of modules. It involves provisioning infrastructure using a module, verifying it works as expected, and tearing it down.
1212

13-
To support this, we use the [Terratest](https://github.com/gruntwork-io/terratest) library, which is an open source Go library maintained by Gruntwork that makes it easier to automate this process.
13+
We rely on [Terratest](https://github.com/gruntwork-io/terratest), an open-source Go library maintained by Gruntwork, to facilitate this process. Terratest enables local testing and CI pipeline tests against live cloud environments to verify that all library modules function as intended.
1414

15-
These tests can be run locally, and are run in CI pipelines against live cloud environments to ensure that every module in the library works as expected.
15+
### Pre-commit hooks
1616

17-
### Pre-commit Hooks
17+
Pre-commit hooks enable module authors to identify and address issues early in the development process. They are also enforced during CI runs to maintain compliance and consistency.
1818

19-
Prior to committing any software, module authors leverage a suite of pre-commit hooks to ensure that quality is introduced as early as possible. These hooks are run again in CI to ensure that authors did in-fact run them locally.
19+
For details on available hooks and repository-specific configurations, refer to the documentation in the [pre-commit repository](https://github.com/gruntwork-io/pre-commit?tab=readme-ov-file#pre-commit-hooks).
2020

21-
For a list of hooks available for authors, and for information on the hooks leveraged for a particular repository in the library, see the documentation in the [pre-commit](https://github.com/gruntwork-io/pre-commit?tab=readme-ov-file#pre-commit-hooks) repository.
21+
### Security scanning
2222

23-
### Security Scanning
23+
While ensuring security often involves good practices and sound judgment, static analysis tools can identify potential module vulnerabilities.
2424

25-
While making modules secure is often a practice of exercising good judgement and following best practices, there are some tools that can help identify security vulnerabilities in modules through static analysis.
25+
- [Terrascan](https://github.com/tenable/terrascan) is used in CI pipelines to detect vulnerabilities through static analysis.
26+
- [Steampipe](https://github.com/turbot/steampipe) performs live test cloud environment scans to detect security risks not captured by static analysis. These live test scans validate CIS compliance of modules like the [cis-service-catalog](https://github.com/gruntwork-io/terraform-aws-cis-service-catalog).
2627

27-
The tool used to achieve this in CI is [Terrascan](https://github.com/tenable/terrascan). This is an open source tool that is run continuously to ensure that our modules do not have any security vulnerabilities that are easily detectable.
28+
### Automated documentation generation
2829

29-
In addition to static analysis, we also use the [Steampipe](https://github.com/turbot/steampipe) tool to scan live test cloud environments for security vulnerabilities that might not be easily detectable through static analysis. This tool is particularly useful in ensuring the CIS compliance of the [cis-service-catalog](https://github.com/gruntwork-io/terraform-aws-cis-service-catalog) provided to automate the provisioning of CIS compliant AWS accounts.
30+
While well-written, human-generated documentation captures intent and technical details, automated documentation generation ensures accuracy and up-to-date information. Gruntwork employs custom tools to supplement manually written documentation with automatically generated details, available in the [Library Reference](/library/reference).
3031

31-
### Automated Documentation Generation
32+
## Quality checks we don't use
3233

33-
Generally, the best documentation is that which is written by a person and accurately conveys not only the technical details of a module, but also the intent behind the module. However, it is also useful to have automated documentation generation to ensure that the documentation is always up to date.
34+
Not every quality check is practical or valuable enough to justify its implementation. Each quality check incurs a cost, and we aim to maintain a high signal-to-noise ratio by using the most impactful methods within available resources.
3435

35-
To achieve that goal, some custom tooling is used to automatically generate documentation for modules in the library in the context of the manually written documentation to express intent. You can see this documentation by navigating to the [Library Reference](/library/reference)
36+
### Infrastructure cost
3637

37-
## Quality Checks We Don't Use
38+
Tools like [Infracost](https://github.com/infracost/infracost) can help assess the cost of live infrastructure. However, it is less relevant to a module library and is not currently part of our quality checks.
3839

39-
It is impossible to use every conceivable quality check, and some quality checks are more valuable than others. Every quality check has a cost associated with it, and it is important to be judicious in the quality checks that are used to ensure a high signal to noise ratio. That being said, there is also limited time and resources to implement new quality checks on the entire library.
40+
### Further exploration
4041

41-
Gruntwork strives to use the most valuable quality checks that result in high quality modules with the resources available to us.
42-
43-
These are some quality checks that we are aware of, but don't use. They may not be in use at the moment because they are not valuable enough to justify the cost of implementing them, or because they are not a good fit for the library. Regardless, they are referenced here so that they can be considered in the future, and so that you can evaluate whether they are a good fit for your own modules.
44-
45-
### Infrastructure Cost
46-
47-
A useful tool for evaluating the cost of infrastructure is [Infracost](https://github.com/infracost/infracost). This is a useful tool, but more practically useful for live infrastructure than a library of modules.
48-
49-
### More to be Discovered
50-
51-
Quality checks that are _not_ used are harder to think of than those that _are_ used. If you have any suggestions for quality checks that we should consider, please let us know by sending a pull request to this document.
42+
Determining unused quality checks is inherently challenging. If you have suggestions for additional quality checks we should consider, please contribute by submitting a pull request to this document.

0 commit comments

Comments
 (0)