Ejemplo n.º 1
0
def test_hcl_nested_named_block():
    c = tf.Context()
    c += tf.many_from_hcl("""
terraform {
  backend "foo" {
    foo = "bar"
    bar = ["baz"]

    map = {
      a = "b"
    }
  }
}
""")
    assert {
        'terraform': {
            'backend': {
                'foo': {
                    'foo': 'bar',
                    'bar': ['baz'],
                    'map': {
                        'a': 'b'
                    }
                }
            }
        }
    } == c.data
Ejemplo n.º 2
0
def test_single_parse():
    c1 = tf.Context()
    c1 += tf.many_from_hcl("""
        terraform {
          foo = "bar"
        }
    """)
    c2 = tf.Context()
    c2 += tf.Terraform({'foo': 'bar'})
    assert c1.data == c2.data
Ejemplo n.º 3
0
def test_hcl_as_object():
    c1 = tf.Context()
    c1 += tf.many_from_hcl("""
    terraform {
      foo = "bar"
    }

    resource "type" "name" {
      whatever {
        here = "there"
      }
    }

    """)
    c2 = tf.Context()
    c2 += tf.Terraform({'foo': 'bar'})
    c2 += tf.Resource('type', 'name', {
        'whatever': {
            'here': 'there'
        }
    })
    assert c1.data == c2.data
Ejemplo n.º 4
0
def test_many_from_hcl_order():
    c = tf.Context()
    many = tf.many_from_hcl("""
    variable "" {
      default = "1"
    }

    variable "a" {
      default = "1"
    }

    variable "a/b" {
      default = "1"
    }

    variable "a/b/c" {
      default = "1"
    }

    """)
    assert [tf.Variable(name="", body={'default': '1'}),
            tf.Variable(name="a", body={'default': '1'}),
            tf.Variable(name="a/b", body={'default': '1'}),
            tf.Variable(name="a/b/c", body={'default': '1'})] == many
Ejemplo n.º 5
0
def test_hcl_as_data(hcl, data):
    c1 = tf.Context()
    c1 += tf.many_from_hcl(hcl)
    assert data == c1.data
Ejemplo n.º 6
0
def test_many_from_hcl_no_data():
    with pytest.raises(tf.HCLParseError):
        tf.many_from_hcl(""" """)
Ejemplo n.º 7
0
def test_many_from_hcl_unknown_key():
    with pytest.raises(tf.HCLUnknownBlockError):
        tf.many_from_hcl("""key { }""")