Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
busser committed Nov 18, 2022
1 parent 1447cd5 commit b1090dd
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 23 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ jobs:
with:
terraform_version: ${{ matrix.terraform-version }}
terraform_wrapper: false # script interferes with parsing of plan
- name: Install Terragrunt
uses: autero1/action-terragrunt@v1.1.0
with:
terragrunt_version: latest
- run: make test-e2e

end-to-end-tests-check:
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.4.1
v0.5.0
2 changes: 2 additions & 0 deletions docs/content/usage/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Usage of tfautomv:
output format of moves ("blocks" or "commands") (default "blocks")
-show-analysis
show detailed analysis of Terraform plan
-terraform-bin string
terraform binary to use (default "terraform")
-version
print version and exit
```
54 changes: 44 additions & 10 deletions docs/content/usage/ignore.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,61 @@ Add the `-ignore` flag to your `tfautomv` command to ignore differences between
certain resources' attributes. Differences are ignored based on the rules you
provide. Use the `-ignore` flag multiple times to specify multiple rules.

Rules have this structure:

```plaintext
<EFFECT>:<RESOURCE TYPE>:<ATTRIBUTE NAME>
<EFFECT>:<RESOURCE TYPE>:<ATTRIBUTE NAME>[OPTIONAL PARAMETERS]
```

For nested attributes, separate parent attributes from child attributes with a
`.` (the representation used in tfautomv's [detailed analysis]({{< relref "usage/show-analysis.md" >}})):

```bash
<EFFECT>:<RESOURCE TYPE>:parent_obj.child_field
<EFFECT>:<RESOURCE TYPE>:parent_list.0
```

## Ignore an attribute entirely

Use the `everything` effect to ignore any difference between two values of an
attribute:

```bash
tfautomv -ignore="everything:<RESOURCE TYPE>:<ATTRIBUTE NAME>"
```

For example:

```bash
tfautomv -ignore=everything:random_pet:length
tfautomv -ignore="everything:random_pet:length"
```

For nested attributes, separate parent attributes from child attributes with a
`.` (the representation used in tfautomv's detailed analysis):
## Ignore whitespace

Use the `whitespace` effect to ignore differences in whitespace between two
values of an attribute:

```bash
<EFFECT>:<RESOURCE TYPE>:parent_obj.child_field
<EFFECT>:<RESOURCE TYPE>:parent_list.0
tfautomv -ignore="whitespace:<RESOURCE TYPE>:<ATTRIBUTE NAME>"
```

For example:

```bash
tfautomv -ignore="whitespace:azurerm_api_management_policy:xml_content"
```

## Available effects
## Ignore a prefix

The following effects are available:
Use the `prefix` effect to ignore a specific prefix between in one of two values
of an attribute:

- `everything`: ignores all differences between attribute values
- `whitespace`: ignores whitespace when comparing attribute values
```bash
tfautomv -ignore="prefix:<RESOURCE TYPE>:<ATTRIBUTE NAME>:<PREFIX>"
```

For example:

```bash
tfautomv -ignore="prefix:google_storage_bucket_iam_member:bucket:b/"
```
16 changes: 16 additions & 0 deletions docs/content/usage/terraform-bin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
weight: 7
title: "Use a specific Terraform binary"
description: Tfautomv allows using any Terraform binary or wrapper.
---

# Use a specific Terraform binary

Under the hood, `tfautomv` runs `terraform`. You can replace `terraform` with
any other binary with the `-terraform-bin` flag.

For example, you can use Terragrunt as a Terraform wrapper:

```bash
tfautomv -terraform-bin=terragrunt
```
41 changes: 29 additions & 12 deletions internal/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ func TestE2E(t *testing.T) {
skip: true,
skipReason: "tfautomv is currently incompatible with Terraform Cloud workspaces with the \"Remote\" execution mode.\nFor more details, see https://github.com/padok-team/tfautomv/issues/17",
},
{
name: "terragrunt",
workdir: filepath.Join("testdata", "terragrunt"),
args: []string{
"-terraform-bin=terragrunt",
},
wantChanges: 0,
wantOutputInclude: []string{
colorEscapeSequence,
},
},
}

binPath := buildBinary(t)
Expand All @@ -109,6 +120,16 @@ func TestE2E(t *testing.T) {
for _, outputFormat := range []string{"blocks", "commands"} {
t.Run(outputFormat, func(t *testing.T) {

originalWorkdir := filepath.Join(tc.workdir, "original-code")
refactoredWorkdir := filepath.Join(tc.workdir, "refactored-code")

terraformBin := "terraform"
for _, a := range tc.args {
if strings.HasPrefix(a, "-terraform-bin=") {
terraformBin = strings.TrimPrefix(a, "-terraform-bin=")
}
}

/*
Skip tests that serve as documentation of known limitations or
use features incompatible with the Terraform CLI's version.
Expand All @@ -119,7 +140,7 @@ func TestE2E(t *testing.T) {
}

if outputFormat == "blocks" {
tf, err := tfexec.NewTerraform(".", "terraform")
tf, err := tfexec.NewTerraform(originalWorkdir, terraformBin)
if err != nil {
t.Fatal(err)
}
Expand All @@ -137,8 +158,7 @@ func TestE2E(t *testing.T) {
Create a fresh environment for each test.
*/

setupWorkdir(t, tc.workdir)
workdir := filepath.Join(tc.workdir, "refactored-code")
setupWorkdir(t, originalWorkdir, refactoredWorkdir, terraformBin)

args := append(tc.args, fmt.Sprintf("-output=%s", outputFormat))

Expand All @@ -147,7 +167,7 @@ func TestE2E(t *testing.T) {
*/

tfautomvCmd := exec.Command(binPath, args...)
tfautomvCmd.Dir = workdir
tfautomvCmd.Dir = refactoredWorkdir

var tfautomvStdout bytes.Buffer
var tfautomvCompleteOutput bytes.Buffer
Expand Down Expand Up @@ -180,7 +200,7 @@ func TestE2E(t *testing.T) {

if outputFormat == "commands" {
cmd := exec.Command("/bin/sh")
cmd.Dir = workdir
cmd.Dir = refactoredWorkdir

cmd.Stdin = &tfautomvStdout
cmd.Stdout = os.Stderr
Expand All @@ -195,7 +215,7 @@ func TestE2E(t *testing.T) {
Count how many changes remain in Terraform's plan.
*/

tf, err := tfexec.NewTerraform(workdir, "terraform")
tf, err := tfexec.NewTerraform(refactoredWorkdir, terraformBin)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -227,7 +247,7 @@ func numChanges(p *tfjson.Plan) int {
count := 0

for _, rc := range p.ResourceChanges {
if slices.Contains(rc.Change.Actions, "create") || slices.Contains(rc.Change.Actions, "delete") {
if slices.Contains(rc.Change.Actions, tfjson.ActionCreate) || slices.Contains(rc.Change.Actions, tfjson.ActionDelete) {
count++
}
}
Expand Down Expand Up @@ -257,12 +277,9 @@ func buildBinary(t *testing.T) string {
return binPath
}

func setupWorkdir(t *testing.T, workdir string) {
func setupWorkdir(t *testing.T, originalWorkdir, refactoredWorkdir, terraformBin string) {
t.Helper()

originalWorkdir := filepath.Join(workdir, "original-code")
refactoredWorkdir := filepath.Join(workdir, "refactored-code")

filesToRemove := []string{
filepath.Join(originalWorkdir, "terraform.tfstate"),
filepath.Join(originalWorkdir, ".terraform.lock.hcl"),
Expand All @@ -282,7 +299,7 @@ func setupWorkdir(t *testing.T, workdir string) {
ensureDirectoryRemoved(t, d)
}

original, err := tfexec.NewTerraform(originalWorkdir, "terraform")
original, err := tfexec.NewTerraform(originalWorkdir, terraformBin)
if err != nil {
t.Fatal(err)
}
Expand Down
18 changes: 18 additions & 0 deletions internal/e2e/testdata/terragrunt/original-code/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
variable "prefix" {
type = string
}

resource "random_pet" "original_first" {
prefix = var.prefix
length = 1
}

resource "random_pet" "original_second" {
prefix = var.prefix
length = 2
}

resource "random_pet" "original_third" {
prefix = var.prefix
length = 3
}
3 changes: 3 additions & 0 deletions internal/e2e/testdata/terragrunt/original-code/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
inputs = {
prefix = "my-"
}
18 changes: 18 additions & 0 deletions internal/e2e/testdata/terragrunt/refactored-code/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
variable "prefix" {
type = string
}

resource "random_pet" "refactored_first" {
prefix = var.prefix
length = 1
}

resource "random_pet" "refactored_second" {
prefix = var.prefix
length = 2
}

resource "random_pet" "refactored_third" {
prefix = var.prefix
length = 3
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
inputs = {
prefix = "my-"
}

0 comments on commit b1090dd

Please sign in to comment.