# Helper Scripts

A number of scripts exist to save time when preforming routine tasks. It's easiest if `xdr-terraform-live/bin` is in your PATH somewhere.

Many of these scripts make an assumption that you are somewhere in a directory structure with `xdr-terraform-modules` and `xdr-terraform-live` repositories both available at the root. In the examples, I'll use `~/xdr-terraform-live`, but you hsould be able to subsitute whichever path you like for `~`, provided both repositories exist as subdirectories.

Many accept `--help` and `--debug` options, though some do no input filtering at all. USE AT YOUR OWN RISK.

## Scripts to help with Applying Modules

### terragrunt-local

Runs the `terragrunt` command, but subsitutes the local copy of `xdr-terraform-modules` for the one that's in github.

Example:
```
cd ~/xdr-terraform-live/test/aws-us-gov/mdr-test-c2/010-vpc-splunk/
terragrunt-local apply
```

### apply_last_updated_modules

Runs a `terragrunt apply` in any module changed in the last commit. Must be run from the xdr-terraform-live root.

Example:
```
cd ~/xdr-terraform-live
apply_last_updated_modules
```

### terragrunt-apply-all

Runs a `terragrunt apply` in every module for an individual customer. Accepts a `--local` flag to use `terragrunt-local` instead of `terragrunt`.

Example:
```
cd ~/xdr-terraform-live/test/aws-us-gov/mdr-test-c2/
terragrunt-apply-all --local
```

### terragrunt-apply-all-everywhere

Runs a terragrunt apply all for every customer. Accepts `--envtest`, `--envcommon`, and `--envprod` if you'd like to limit the environment.

Example:
```
cd ~/xdr-terraform-live
terragrunt-apply-all-everywhere
```

### apply_module_everywhere

Applies a particular module for all customers.

Example:
```
cd ~/xdr-terraform-live
apply_module_everywhere 010-vpc-splunk
```

## Scripts to Help with Tagging

### update_module_refs

Updates the reference for a particular module under all accounts.

Example:
```
cd ~/xdr-terraform-live
update_module_refs --module 010-vpc-splunk --newtag v5.0.10
```

## update_refs

Updates the references for all modules for a given customer

Example:
```
cd ~/xdr-terraform-live/test/aws-us-gov/mdr-test-c2/
update_refs --newtag v5.0.10
```

## update_all_that_uses

Updates the references for all xdr-terraform-live modules that use a particular variables file. Must be run from the xdr-terraform-modules directory.

Example:
```
cd ~/xdr-terraform-modules
update_all_that_uses employee_ips.tf v5.0.11
```
