Skip to content

Commit

Permalink
Don't fail when resource_changes key not present in output (#27)
Browse files Browse the repository at this point in the history
* Resolves #26 tftest failed when terraform plan is empty

* add missing copyright boilerplate

Co-authored-by: Ludovico Magnocavallo <[email protected]>
  • Loading branch information
brownmike and ludoo authored Apr 15, 2021
1 parent d48599c commit 78981fe
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
19 changes: 19 additions & 0 deletions test/fixtures/plan_no_resource_changes/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

output "just_an_output" {
value = "Hello, plan!"
}
7 changes: 7 additions & 0 deletions test/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,10 @@ def test_modules(plan_out):
def test_child_modules(plan_out):
mod = plan_out.modules['module.parent'].child_modules['module.child']
assert mod.resources['eggs.someeggs']['values']['eggs-value'] == 'eggs'


def test_plan_with_no_resources_succeeds(fixtures_dir):
tf = tftest.TerraformTest('plan_no_resource_changes', fixtures_dir)
result = tf.plan(output=True)

assert result.outputs['just_an_output'] == 'Hello, plan!'
2 changes: 1 addition & 1 deletion tftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def __init__(self, raw):
planned_values.get('root_module', {}))
self.outputs = TerraformValueDict(planned_values.get('outputs', {}))
self.resource_changes = dict((v['address'], v)
for v in self._raw['resource_changes'])
for v in self._raw.get('resource_changes', {}))
# there might be no variables defined
self.variables = TerraformValueDict(raw.get('variables', {}))

Expand Down

0 comments on commit 78981fe

Please sign in to comment.