def test_variables(self): """Test parsing a file with only variables.""" r = Parser.load( os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', 'variable-only.tf')) self.assertEqual(2, len(r)) self.assertIn(Variable("one"), r) self.assertIn(Variable("two"), r)
def test_resources(self): """Test parsing a file with only resources.""" r = Parser.load( os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', 'resource-only.tf')) self.assertEqual(2, len(r)) self.assertIn(Resource("default", "aws_sns_topic"), r) self.assertIn(Resource("default", "aws_instance"), r)
def test_outputs(self): """Test parsing a file with only outputs.""" r = Parser.load( os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', 'output-only.tf')) self.assertEqual(2, len(r)) self.assertIn(Output("dango"), r) self.assertIn(Output("brango"), r)
def test_mixed(self): """Test parsing a mixed file.""" r = Parser.load( os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', 'mixed.tf')) self.assertEqual(3, len(r)) self.assertIn(Resource("default", "aws_instance"), r) self.assertIn(Output("rear"), r) self.assertIn(Variable("thing"), r)
def get_module_entities(path): """Return all entities for a given module existing at a given path.""" if not os.path.isdir(path): raise Exception("Unable to load path {}, not a directory".format(path)) entities = set() for tffile in [f for f in os.listdir(path) if f.endswith('.tf')]: entities.update(Parser.load(os.path.join(path, tffile))) return entities