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
Copy file name to clipboardExpand all lines: docs/2.0/docs/patcher/concepts/patches.md
+40-33Lines changed: 40 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,44 +25,63 @@ steps:
25
25
26
26
[Check out an example of a patch in the CIS Service Catalog.](https://github.com/gruntwork-io/terraform-aws-service-catalog/blob/c3d5ede211fc3230a7d493ceea43622b337ee88a/.patcher/patches/v0.96.4/switch-to-cis-rds-module/patch.yaml)
27
27
28
+
## Module consumers and module authors
29
+
30
+
Patcher is built around the idea of two specific personas:
31
+
32
+
-**Module authors.** Module authors write OpenTofu/Terraform modules, or make updates to those modules.
33
+
-**Module consumers.** Module consumers make use of an OpenTofu/Terraform module that was created by a module author, typically in Terragrunt units (`terragrunt.hcl` files) or directly in OpenTofu/Terraform code that calls a module.
34
+
35
+
## For Module Authors
36
+
37
+
Module authors periodically need to introduce breaking changes in their modules, causing a downstream, potentially painful, experience for module consumers.
38
+
With patches, module authors include a patch YAML file that automatically updates consuming code to incorporate the breaking changes associated with the updated module code. For example, when module consumers "execute" a patch and their code will automatically be updated to add a variable, rename a variable, update a provider reference, or incorporate some other transformation specified by the module author.
39
+
This allows module consumers to automatically update consuming code to adopt breaking changes.
40
+
41
+
In a Patcher ecosystem, the module author spends a small amount of extra time to author a patch, but now all module consumers can automatically update their code to consume the latest breaking change.
42
+
43
+
In theory, you may write whatever command execution steps you want to perform patch steps.
44
+
For example, there are many cases where validating tool versions are required, or using `sed` to find and replace certain values.
45
+
However, we _strongly_ recommend using [`terrapatch`](https://github.com/gruntwork-io/terrapatch), a Gruntwork tool that surgically updates Terraform/OpenTofu HCL files.
46
+
28
47
## For Module Consumers
29
48
30
-
As an OpenTofu/Terraform module consumer, modules are imported to launch infrastructure by writing Terragrunt units (`terragrunt.hcl` files) or OpenTofu/Terraform code that calls a module.
49
+
When module consumers reference an OpenTofu/Terraform module, it is a best practice to reference a specific version of the OpenTofu/Terraform module.
50
+
Over time, module authors release new versions of the module, and the code that consumes those modules slowly gets out of date.
51
+
In some cases, the latest update of the underlying modules requires a breaking change to the consuming code, meaning the version can't just be bumped; the code needs to be edited.
52
+
This is when using a patch with Patcher comes in handy.
31
53
32
-
It is best practice to reference a specific version of an OpenTofu/Terraform module.
33
-
Over time, module authors release new versions of the module, and the code that consumes those modules slowly gets out of date.
34
-
In some cases, the latest update of the underlying modules requires a breaking change to the consuming code, meaning the version can't just be bumped.
35
-
The consuming code needs to be edited to make use of the new version.
36
-
In this instance, using a patch with Patcher comes in handy.
54
+
### Two update strategies
37
55
38
-
Patches can be consumed with either a "push" strategy, when Patcher proactively opens a pull request with the latest update, or a "pull" strategy, when a repo is manually scanned to look at the current state of your infrastructure using the Patcher CLI tool.
56
+
Patches can be consumed with either a "push" strategy, where Patcher proactively opens a pull request with the latest update, or a "pull" strategy, where a repo is manually scanned to look at the current state of your infrastructure using the Patcher CLI tool.
39
57
40
-
Regardless of methodology, the concept remains the same.
41
-
Patcher will suggest changes to your codebase in order to keep your infrastructure up to date, however you see fit.
58
+
Regardless of methodology, the concept remains the same.
59
+
Patcher will suggest changes to your codebase in order to keep your infrastructure up to date, however you see fit.
42
60
43
-
Here is an example of what your PR will look like, after being generated by Patcher:
61
+
### Update Push Strategy
62
+
63
+
In the "push" strategy, Patcher opens pull requests against your codebase on a schedule you set. You can further customize how those pull requests are grouped by environment, module version, or other parameters. Here is an example of such a pull request:
You can implement the push strategy by using the [Patcher GitHub action workflow](https://github.com/gruntwork-io/patcher-action).
48
68
49
-
Let's take a look at the experience of the "push" strategy available through our [GitHub action](https://github.com/gruntwork-io/patcher-action).
50
-
Using the GitHub action, PRs will be opened against your codebase on a cadence specified by you, against environments, versions, etc. specified by you.
51
-
The intention with this GitHub action is to leave the repo owner in full control of your upgrade cadence. Check out our guide on [promotion workflows](/2.0/docs/patcher/guides/promotion-workflows), so that updates can proceed from `dev` to `stage` to `prod` (or any other environment sequence) to mitigate risks around upgrades.
69
+
The intention with this GitHub action is to leave the repo owner in full control of your upgrade cadence. Check out our guide on [promotion workflows](/2.0/docs/patcher/guides/promotion-workflows), so that updates can proceed from `dev` to `stage` to `prod` (or any other environment sequence) to mitigate risks around upgrades.
52
70
53
71
### Update Pull Strategy
54
72
55
-
Let's take a look at the experience of "pulling" available updates by using the Patcher CLI tool.
56
-
The first step is to run `patcher update` within the repo in which updates are desired.
57
-
When `patcher update` is run, the default mode is to click through the updates **interactively**.
73
+
In the "pull" strategy, you the user choose to launch the Patcher CLI to scan the current state of your repo.
74
+
75
+
The first step is to run `patcher update` within the repo in which updates are desired.
76
+
When `patcher update` is run, the default mode is to click through the updates **interactively**.
58
77
In this mode, available updates are found, and the details of those updates are presented to you:
You can choose to run in `--non-interactive` mode, which will modify the codebase and present results about what the program did at the end.
81
+
You can choose to run in `--non-interactive` mode, which will modify the codebase and present results about what the program did at the end.
63
82
64
-
By default a PR will _not_ be opened with the changes.
65
-
However, the changes should be visible within the version control system. At that point, you may make a PR or apply the changes using your IaC system.
83
+
By default a pull request will _not_ be opened with the changes.
84
+
However, the changes should be visible within the version control system. At that point, you may make a pull request or apply the changes using your IaC system.
66
85
67
86
### Examples Running `patcher update`
68
87
@@ -81,17 +100,5 @@ If more fine-grain controls are desired, the following example (which includes a
81
100
$ patcher update --update-strategy next-safe --non-interactive --publish --pr-branch grunty/update-via-patcher --pr-title "[Patcher] Update All Dependencies to Next Safe"
82
101
```
83
102
84
-
More details on the available options included in `patcher update` can be found in the [reference section](/2.0/reference/patcher/index.md#update).
85
-
86
-
## For Module Authors
87
-
88
-
Module authors periodically need to introduce breaking changes in their modules, causing a downstream, potentially painful, experience for module consumers.
89
-
With patches, module authors include a patch YAML file that automatically updates consuming code to incorporate the breaking changes associated with the updated module code.
90
-
Doing so allows module consumers to use patches to enable their modules consumers to automatically update consuming code to adopt breaking changes.
91
-
92
-
In a Patcher ecosystem, the resolution to such a change is written once, in a patch, and distributed to all consumers.
93
-
Although your release will succeed with or without a patch, downstream consumers of your breaking change will praise you thoroughly for your advance work.
103
+
More details on the available options included in `patcher update` can be found in the [reference section](/2.0/reference/patcher/index.md#update).
94
104
95
-
In theory, you may write whatever command execution steps you want to perform patch steps.
96
-
For example, there are many cases where validating tool versions are required, or using `sed` to find and replace certain values.
97
-
However, we _strongly_ recommend using [`terrapatch`](https://github.com/gruntwork-io/terrapatch), a Gruntwork tool that surgically updates Terraform/OpenTofu HCL files.
0 commit comments