Skip to content

Commit

Permalink
Add --extra-files option to plan_summary.py cmd (#2452)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaPrete authored Jul 30, 2024
1 parent 2854ae6 commit 140c4e6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,18 @@ outputs:

You can now use this output to create the inventory file for your test. As mentioned before, please only use those values relevant to your test scenario.

You can optionally pass to the command additional files that your plan might need to properly execute.

In this example we pass in two extra files from the organization folder.

```bash
$ python tools/plan_summary.py modules/organization \
tests/modules/organization/common.tfvars \
tests/modules/organization/audit_config.tfvars \
--extra-files ../my-file-1.tf \
--extra-files ../my-file-2.yaml
```

### Running end-to-end tests

You can use end-to-end tests to verify your code against GCP API. These tests verify that `terraform apply` succeeds, `terraform plan` is empty afterwards and that `terraform destroy` raises no error.
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ def plan_summary(module_path, basedir, tf_var_files=None, extra_files=None,
- tf_var_files: set of terraform variable files (tfvars) to pass
in to terraform
- extra_files: set of extra files to optionally pass
in to terraform
Returns a PlanSummary object containing 3 attributes:
- values: dictionary where the keys are terraform plan addresses
and values are the JSON representation (converted to python
Expand Down
5 changes: 3 additions & 2 deletions tools/plan_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@

@click.command()
@click.option('--example', default=False, is_flag=True)
@click.option('--extra-files', default=[], multiple=True)
@click.argument('module', type=click.Path(), nargs=1)
@click.argument('tfvars', type=click.Path(exists=True), nargs=-1)
def main(example, module, tfvars):
def main(example, module, tfvars, extra_files):
try:
if example:
tmp_dir = tempfile.TemporaryDirectory()
Expand All @@ -46,7 +47,7 @@ def main(example, module, tfvars):
else:
module = BASEDIR / module

summary = fixtures.plan_summary(module, Path(), tfvars)
summary = fixtures.plan_summary(module, Path(), tfvars, extra_files)
print(yaml.dump({'values': summary.values}))
print(yaml.dump({'counts': summary.counts}))
outputs = {
Expand Down

0 comments on commit 140c4e6

Please sign in to comment.