Skip to content

Commit

Permalink
Patcher test (#100)
Browse files Browse the repository at this point in the history
* chore: WIP - Patcher test

* chore: test a sample patch
  • Loading branch information
ZachGoldberg authored Aug 8, 2024
1 parent b383c2b commit 6a34d13
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .patcher/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
versions:
- tag: v0.10.2
patches:
- slug: "sample-breaking-change"
modules_affected:
- patcher-test
15 changes: 15 additions & 0 deletions .patcher/patches/sample-breaking-change/patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "Sample Breaking Change"
description: A sample breaking change that renames a resource
author: Gruntwork

# Optional list of dependencies that the patch requires.
dependencies:
- name: terrapatch
version: "0.1.0"

# List of steps that this patch should execute.
# Each step has a name field (string) and a run field, which can denote either an OS command, or an external script to be run.
# If there are any external scripts, then make sure you include these in the same directory where the patch.yaml file is.
steps:
- name:
run: terrapatch move-resource --path $PATCHER_MODULE_PATH terraform $PATCHER_MODULE_ADDRESS module.null_resource.test2
40 changes: 40 additions & 0 deletions modules/patcher-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Operating System Module

This is a module that can be used to figure out what operating system is being used to run Terraform. This may be used
to modify Terraform's behavior depending on the OS, such as modifying the way you format file paths on Linux vs
Windows (see also the [join-path module](/modules/join-path)).

This module uses Python under the hood so, the Python must be installed on the OS.




## Example code

See the [operating-system example](/examples/operating-system) for working sample code.




## Usage

Simply use the module in your Terraform code, replacing `<VERSION>` with the latest version from the [releases
page](https://github.com/gruntwork-io/terraform-aws-utilities/releases):

```hcl
module "os" {
source = "git::git@github.com:gruntwork-io/terraform-aws-utilities.git//modules/operating-system?ref=<VERSION>"
}
```

* You can now get the name of the operating system from the `name` output, which will be set to either `Linux`,
`Darwin`, or `Windows`

* You can also get the path separator for the current OS—backslash for Windows, forward slash everywhere else—from the
`path_separator` output.

```hcl
operating_system_name = "${module.os.name}"
path_separator = "${module.os.path_separator}"
```

17 changes: 17 additions & 0 deletions modules/patcher-test/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
terraform {
required_version = ">= 1.0.0"
}

data "external" "os" {
program = ["python3", "-c", <<-EOF
import json
import os
import platform
print(json.dumps({
"platform": platform.system(),
"path_separator": os.sep,
}))
EOF
]
}
7 changes: 7 additions & 0 deletions modules/patcher-test/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "name" {
value = data.external.os.result.platform
}

output "path_separator" {
value = data.external.os.result.path_separator
}

0 comments on commit 6a34d13

Please sign in to comment.